Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/libkernelbot/launchers/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
from typing import Awaitable, Callable, Optional

import requests
from github import Github, UnknownObjectException, WorkflowRun
from github import Github, UnknownObjectException
from github.Workflow import Workflow
from github.WorkflowRun import WorkflowRun

from libkernelbot.consts import (
AMD_REQUIREMENTS,
Expand Down Expand Up @@ -172,6 +174,9 @@ class GitHubArtifact:
public_download_url: str


_WORKFLOW_FILE_CACHE: dict[str, Workflow] = {}


class GitHubRun:
def __init__(self, repo: str, token: str, branch: str, workflow_file: str):
gh = Github(token)
Expand Down Expand Up @@ -209,6 +214,15 @@ def elapsed_time(self):
return None
return datetime.datetime.now(datetime.timezone.utc) - self.start_time

async def get_workflow(self) -> Workflow:
if self.workflow_file in _WORKFLOW_FILE_CACHE:
logger.info(f"Returning cached workflow {self.workflow_file}")
return _WORKFLOW_FILE_CACHE[self.workflow_file]
logger.info(f"Fetching workflow {self.workflow_file} from GitHub")
workflow = self.repo.get_workflow(self.workflow_file)
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get_workflow method is declared as async but doesn't perform any await operations. Line 222 calls self.repo.get_workflow synchronously, which is a blocking network I/O operation that was previously wrapped with asyncio.to_thread at line 246. Removing the asyncio.to_thread wrapper without making the method properly async means this now blocks the event loop. Either add back the asyncio.to_thread wrapper, or change this to a synchronous method if blocking is acceptable.

Suggested change
workflow = self.repo.get_workflow(self.workflow_file)
workflow = await asyncio.to_thread(self.repo.get_workflow, self.workflow_file)

Copilot uses AI. Check for mistakes.
_WORKFLOW_FILE_CACHE[self.workflow_file] = workflow
return workflow

async def trigger(self, inputs: dict) -> bool:
"""
Trigger this run with the provided inputs.
Expand All @@ -229,7 +243,7 @@ async def trigger(self, inputs: dict) -> bool:

trigger_time = datetime.datetime.now(datetime.timezone.utc)
try:
workflow = await asyncio.to_thread(self.repo.get_workflow, self.workflow_file)
workflow = await self.get_workflow()
except UnknownObjectException as e:
logger.error(f"Could not find workflow {self.workflow_file}", exc_info=e)
raise ValueError(f"Could not find workflow {self.workflow_file}") from e
Expand Down
Loading