add failure_reason to the TaskRunRepsonse for task v2 (#2052)

This commit is contained in:
Shuchang Zheng 2025-03-31 12:15:26 -07:00 committed by GitHub
parent a75d5c947d
commit 993e3b637d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 33 deletions

View file

@ -133,7 +133,6 @@ class SkyvernAgent:
status=TaskV2Status.queued,
organization_id=organization.organization_id,
)
assert task_v2.workflow_run_id
await app.DATABASE.update_workflow_run(
workflow_run_id=task_v2.workflow_run_id,
@ -295,7 +294,6 @@ class SkyvernAgent:
proxy_location=proxy_location,
)
if wait_for_completion:
created_task = await app.agent.create_task(task_request, organization.organization_id)
url_hash = generate_url_hash(task_request.url)
await app.DATABASE.create_task_run(
@ -314,10 +312,6 @@ class SkyvernAgent:
# TODO: better error handling and logging
run_obj = await self.get_run(run_id=created_task.task_id)
return cast(TaskRunResponse, run_obj)
else:
create_task_resp = await self.create_task_v1(task_request)
run_obj = await self.get_run(run_id=create_task_resp.task_id)
return cast(TaskRunResponse, run_obj)
elif engine == RunEngine.skyvern_v2:
# initialize task v2
organization = await self._get_organization()
@ -336,14 +330,9 @@ class SkyvernAgent:
create_task_run=True,
)
if wait_for_completion:
await self._run_task_v2(organization, task_v2)
run_obj = await self.get_run(run_id=task_v2.observer_cruise_id)
return cast(TaskRunResponse, run_obj)
else:
asyncio.create_task(self._run_task_v2(organization, task_v2))
run_obj = await self.get_run(run_id=task_v2.observer_cruise_id)
return cast(TaskRunResponse, run_obj)
else:
raise ValueError("Local mode is not supported for this method")

View file

@ -37,13 +37,15 @@ async def get_run_response(run_id: str, organization_id: str | None = None) -> R
task_v2 = await app.DATABASE.get_task_v2(run.run_id, organization_id=organization_id)
if not task_v2:
return None
workflow_run = None
if task_v2.workflow_run_id:
workflow_run = await app.DATABASE.get_workflow_run(task_v2.workflow_run_id, organization_id=organization_id)
return TaskRunResponse(
run_id=run.run_id,
run_type=run.task_run_type,
status=task_v2.status,
output=task_v2.output,
# TODO: add failure reason
# failure_reason=task_v2.failure_reason,
failure_reason=workflow_run.failure_reason if workflow_run else None,
created_at=task_v2.created_at,
modified_at=task_v2.modified_at,
run_request=TaskRunRequest(