execute_task_webhook uses the latest non canceled step (#4007)

This commit is contained in:
Shuchang Zheng
2025-11-16 15:01:40 -08:00
committed by GitHub
parent 3879807fc6
commit 25e375f78f
4 changed files with 7 additions and 9 deletions

View File

@@ -3138,12 +3138,11 @@ class ForgeAgent:
await app.ARTIFACT_MANAGER.wait_for_upload_aiotasks([task.task_id])
if need_call_webhook:
await self.execute_task_webhook(task=task, last_step=last_step, api_key=api_key)
await self.execute_task_webhook(task=task, api_key=api_key)
async def execute_task_webhook(
self,
task: Task,
last_step: Step | None,
api_key: str | None,
) -> None:
if not api_key:
@@ -3159,6 +3158,7 @@ class ForgeAgent:
task_id=task.task_id,
)
return
last_step = await app.DATABASE.get_latest_step(task.task_id, organization_id=task.organization_id)
task_response = await self.build_task_response(task=task, last_step=last_step)
# try to build the new TaskRunResponse for backward compatibility

View File

@@ -532,6 +532,7 @@ class AgentDB:
select(StepModel)
.filter_by(task_id=task_id)
.filter_by(organization_id=organization_id)
.filter(StepModel.status != StepStatus.canceled)
.order_by(StepModel.order.desc())
.order_by(StepModel.retry_index.desc())
)

View File

@@ -1644,10 +1644,8 @@ async def cancel_task(
detail=f"Task not found {task_id}",
)
task = await app.agent.update_task(task_obj, status=TaskStatus.canceled)
# get latest step
latest_step = await app.DATABASE.get_latest_step(task_id, organization_id=current_org.organization_id)
# retry the webhook
await app.agent.execute_task_webhook(task=task, last_step=latest_step, api_key=x_api_key)
await app.agent.execute_task_webhook(task=task, api_key=x_api_key)
async def _cancel_workflow_run(workflow_run_id: str, organization_id: str, x_api_key: str | None = None) -> None:
@@ -1778,7 +1776,7 @@ async def retry_webhook(
return await app.agent.build_task_response(task=task_obj)
# retry the webhook
await app.agent.execute_task_webhook(task=task_obj, last_step=latest_step, api_key=x_api_key)
await app.agent.execute_task_webhook(task=task_obj, api_key=x_api_key)
return await app.agent.build_task_response(task=task_obj, last_step=latest_step)