fix workflow run browser context missing problem (#1902)

This commit is contained in:
Shuchang Zheng
2025-03-07 15:06:24 -08:00
committed by GitHub
parent 2d2ad2f3d9
commit bc8e458ed1
2 changed files with 9 additions and 4 deletions

View File

@@ -138,7 +138,9 @@ class ForgeAgent:
task_url = task_block.url
if task_url is None:
browser_state = app.BROWSER_MANAGER.get_for_workflow_run(workflow_run_id=workflow_run.workflow_run_id)
browser_state = app.BROWSER_MANAGER.get_for_workflow_run(
workflow_run_id=workflow_run.workflow_run_id, parent_workflow_run_id=workflow_run.parent_workflow_run_id
)
if browser_state is None:
raise MissingBrowserState(workflow_run_id=workflow_run.workflow_run_id)

View File

@@ -136,7 +136,10 @@ class BrowserManager:
workflow_run_id=workflow_run_id, parent_workflow_run_id=parent_workflow_run_id
)
if browser_state:
# always keep the browser state for the workflow run and the parent workflow run synced
self.pages[workflow_run_id] = browser_state
if parent_workflow_run_id:
self.pages[parent_workflow_run_id] = browser_state
return browser_state
if browser_session_id:
@@ -194,12 +197,12 @@ class BrowserManager:
def get_for_workflow_run(
self, workflow_run_id: str, parent_workflow_run_id: str | None = None
) -> BrowserState | None:
if workflow_run_id in self.pages:
return self.pages[workflow_run_id]
if parent_workflow_run_id and parent_workflow_run_id in self.pages:
return self.pages[parent_workflow_run_id]
if workflow_run_id in self.pages:
return self.pages[workflow_run_id]
return None
def set_video_artifact_for_task(self, task: Task, artifacts: list[VideoArtifact]) -> None: