Skip to content

Commit ac532ca

Browse files
Pwutskcze
andauthored
fix(backend): Graph execution update on terminate (#9952)
Resolves #9947 ### Changes 🏗️ Backend: - Send a graph execution update after terminating a run - Don't wipe the graph execution stats when not passed in to `update_graph_execution_stats` Frontend: - Don't hide the output of stopped runs ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - Go to `/library/agents/[id]` - Run an agent that takes a while (long enough to click stop and see the effect) - Hit stop after it has executed a few nodes - [x] -> run status should change to "Stopped" - [x] -> run stats (steps, duration, cost) should stay the same or increase only one last time - [x] -> output so far should be visible - [x] -> shown information should stay the same after refreshing the page --- Co-authored-by: Krzysztof Czerwinski <[email protected]>
1 parent aa2c2c1 commit ac532ca

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

autogpt_platform/backend/backend/data/execution.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
)
2525
from prisma.types import (
2626
AgentGraphExecutionCreateInput,
27+
AgentGraphExecutionUpdateManyMutationInput,
2728
AgentGraphExecutionWhereInput,
2829
AgentNodeExecutionCreateInput,
2930
AgentNodeExecutionInputOutputCreateInput,
@@ -572,9 +573,15 @@ async def update_graph_execution_stats(
572573
status: ExecutionStatus,
573574
stats: GraphExecutionStats | None = None,
574575
) -> GraphExecution | None:
575-
data = stats.model_dump() if stats else {}
576-
if isinstance(data.get("error"), Exception):
577-
data["error"] = str(data["error"])
576+
update_data: AgentGraphExecutionUpdateManyMutationInput = {
577+
"executionStatus": status
578+
}
579+
580+
if stats:
581+
stats_dict = stats.model_dump()
582+
if isinstance(stats_dict.get("error"), Exception):
583+
stats_dict["error"] = str(stats_dict["error"])
584+
update_data["stats"] = Json(stats_dict)
578585

579586
updated_count = await AgentGraphExecution.prisma().update_many(
580587
where={
@@ -584,10 +591,7 @@ async def update_graph_execution_stats(
584591
{"executionStatus": ExecutionStatus.QUEUED},
585592
],
586593
},
587-
data={
588-
"executionStatus": status,
589-
"stats": Json(data),
590-
},
594+
data=update_data,
591595
)
592596
if updated_count == 0:
593597
return None

autogpt_platform/backend/backend/server/routers/v1.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,11 +660,15 @@ async def _cancel_execution(graph_exec_id: str):
660660
exchange=execution_utils.GRAPH_EXECUTION_CANCEL_EXCHANGE,
661661
)
662662

663-
# Update the status of the graph & node executions
664-
await execution_db.update_graph_execution_stats(
663+
# Update the status of the graph execution
664+
graph_execution = await execution_db.update_graph_execution_stats(
665665
graph_exec_id,
666666
execution_db.ExecutionStatus.TERMINATED,
667667
)
668+
if graph_execution:
669+
await execution_event_bus().publish(graph_execution)
670+
671+
# Update the status of the node executions
668672
node_execs = [
669673
node_exec.model_copy(update={"status": execution_db.ExecutionStatus.TERMINATED})
670674
for node_exec in await execution_db.get_node_executions(
@@ -676,7 +680,6 @@ async def _cancel_execution(graph_exec_id: str):
676680
],
677681
)
678682
]
679-
680683
await execution_db.update_node_execution_status_batch(
681684
[node_exec.node_exec_id for node_exec in node_execs],
682685
execution_db.ExecutionStatus.TERMINATED,

autogpt_platform/frontend/src/components/agents/agent-run-details-view.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ export default function AgentRunDetailsView({
133133
| null
134134
| undefined = useMemo(() => {
135135
if (!("outputs" in run)) return undefined;
136-
if (!["running", "success", "failed"].includes(runStatus)) return null;
136+
if (!["running", "success", "failed", "stopped"].includes(runStatus))
137+
return null;
137138

138139
// Add type info from agent input schema
139140
return Object.fromEntries(

0 commit comments

Comments
 (0)