do not clean up workflow in a task v2 block (#1771)

This commit is contained in:
Shuchang Zheng
2025-02-17 02:40:47 +08:00
committed by GitHub
parent 7e74ecc1c7
commit c846d3871b
3 changed files with 18 additions and 12 deletions

View File

@@ -352,6 +352,7 @@ class ForgeAgent:
detailed_output, detailed_output,
) = await self.initialize_execution_state(task, step, workflow_run, browser_session_id) ) = await self.initialize_execution_state(task, step, workflow_run, browser_session_id)
# mark step as completed and mark task as completed
if ( if (
not task.navigation_goal not task.navigation_goal
and not task.data_extraction_goal and not task.data_extraction_goal
@@ -359,7 +360,10 @@ class ForgeAgent:
and not task.terminate_criterion and not task.terminate_criterion
): ):
# most likely a GOTO_URL task block # most likely a GOTO_URL task block
# mark step as completed and mark task as completed page = await browser_state.must_get_working_page()
current_url = page.url
if current_url.rstrip("/") != task.url.rstrip("/"):
await page.goto(task.url)
step = await self.update_step( step = await self.update_step(
step, status=StepStatus.completed, is_last=True, output=AgentStepOutput(action_results=[]) step, status=StepStatus.completed, is_last=True, output=AgentStepOutput(action_results=[])
) )

View File

@@ -262,7 +262,7 @@ async def run_observer_task(
organization_id=organization_id, organization_id=organization_id,
) )
finally: finally:
if workflow and workflow_run: if workflow and workflow_run and workflow_run.parent_workflow_run_id is None:
await app.WORKFLOW_SERVICE.clean_up_workflow( await app.WORKFLOW_SERVICE.clean_up_workflow(
workflow=workflow, workflow=workflow,
workflow_run=workflow_run, workflow_run=workflow_run,
@@ -699,14 +699,6 @@ async def handle_block_result(
) )
await app.WORKFLOW_SERVICE.mark_workflow_run_as_canceled(workflow_run_id=workflow_run.workflow_run_id) await app.WORKFLOW_SERVICE.mark_workflow_run_as_canceled(workflow_run_id=workflow_run.workflow_run_id)
# TODO: we can also support webhook by adding api_key to the function signature
await app.WORKFLOW_SERVICE.clean_up_workflow(
workflow=workflow,
workflow_run=workflow_run,
need_call_webhook=False,
close_browser_on_completion=browser_session_id is None,
browser_session_id=browser_session_id,
)
elif block_result.status == BlockStatus.failed: elif block_result.status == BlockStatus.failed:
LOG.error( LOG.error(
f"Block with type {block.block_type} failed for workflow run {workflow_run_id}", f"Block with type {block.block_type} failed for workflow run {workflow_run_id}",

View File

@@ -130,11 +130,19 @@ class BrowserManager:
url: str | None = None, url: str | None = None,
browser_session_id: str | None = None, browser_session_id: str | None = None,
) -> BrowserState: ) -> BrowserState:
browser_state = self.get_for_workflow_run(workflow_run_id=workflow_run.workflow_run_id) parent_workflow_run_id = workflow_run.parent_workflow_run_id
workflow_run_id = workflow_run.workflow_run_id
browser_state = self.get_for_workflow_run(workflow_run_id=workflow_run_id)
if parent_workflow_run_id:
browser_state = self.get_for_workflow_run(workflow_run_id=parent_workflow_run_id)
if browser_state:
self.pages[workflow_run_id] = browser_state
if browser_state is not None: if browser_state is not None:
return browser_state return browser_state
if browser_session_id: if browser_session_id:
# TODO: what if there's a parent workflow run?
LOG.info( LOG.info(
"Getting browser state for workflow run from persistent sessions manager", "Getting browser state for workflow run from persistent sessions manager",
browser_session_id=browser_session_id, browser_session_id=browser_session_id,
@@ -171,7 +179,9 @@ class BrowserManager:
organization_id=workflow_run.organization_id, organization_id=workflow_run.organization_id,
) )
self.pages[workflow_run.workflow_run_id] = browser_state self.pages[workflow_run_id] = browser_state
if parent_workflow_run_id:
self.pages[parent_workflow_run_id] = browser_state
# The URL here is only used when creating a new page, and not when using an existing page. # The URL here is only used when creating a new page, and not when using an existing page.
# This will make sure browser_state.page is not None. # This will make sure browser_state.page is not None.