AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(backend): Graph execution update on terminate (#9952)
Reinier van der Leerac532ca4b934
diff --git a/autogpt_platform/backend/backend/data/execution.py b/autogpt_platform/backend/backend/data/execution.pyindex 55b184a147..a89cb8d77c 100644--- a/autogpt_platform/backend/backend/data/execution.py+++ b/autogpt_platform/backend/backend/data/execution.py@@ -24,6 +24,7 @@ from prisma.models import ()from prisma.types import (AgentGraphExecutionCreateInput,+ AgentGraphExecutionUpdateManyMutationInput,AgentGraphExecutionWhereInput,AgentNodeExecutionCreateInput,AgentNodeExecutionInputOutputCreateInput,@@ -572,9 +573,15 @@ async def update_graph_execution_stats(status: ExecutionStatus,stats: GraphExecutionStats | None = None,) -> GraphExecution | None:- data = stats.model_dump() if stats else {}- if isinstance(data.get("error"), Exception):- data["error"] = str(data["error"])+ update_data: AgentGraphExecutionUpdateManyMutationInput = {+ "executionStatus": status+ }++ if stats:+ stats_dict = stats.model_dump()+ if isinstance(stats_dict.get("error"), Exception):+ stats_dict["error"] = str(stats_dict["error"])+ update_data["stats"] = Json(stats_dict)updated_count = await AgentGraphExecution.prisma().update_many(where={@@ -584,10 +591,7 @@ async def update_graph_execution_stats({"executionStatus": ExecutionStatus.QUEUED},],},- data={- "executionStatus": status,- "stats": Json(data),- },+ data=update_data,)if updated_count == 0:return Nonediff --git a/autogpt_platform/backend/backend/server/routers/v1.py b/autogpt_platform/backend/backend/server/routers/v1.pyindex efd43a5c2d..25ddb13145 100644--- a/autogpt_platform/backend/backend/server/routers/v1.py+++ b/autogpt_platform/backend/backend/server/routers/v1.py@@ -660,11 +660,15 @@ async def _cancel_execution(graph_exec_id: str):exchange=execution_utils.GRAPH_EXECUTION_CANCEL_EXCHANGE,)- # Update the status of the graph & node executions- await execution_db.update_graph_execution_stats(+ # Update the status of the graph execution+ graph_execution = await execution_db.update_graph_execution_stats(graph_exec_id,execution_db.ExecutionStatus.TERMINATED,)+ if graph_execution:+ await execution_event_bus().publish(graph_execution)++ # Update the status of the node executionsnode_execs = [node_exec.model_copy(update={"status": execution_db.ExecutionStatus.TERMINATED})for node_exec in await execution_db.get_node_executions(@@ -676,7 +680,6 @@ async def _cancel_execution(graph_exec_id: str):],)]-await execution_db.update_node_execution_status_batch([node_exec.node_exec_id for node_exec in node_execs],execution_db.ExecutionStatus.TERMINATED,diff --git a/autogpt_platform/frontend/src/components/agents/agent-run-details-view.tsx b/autogpt_platform/frontend/src/components/agents/agent-run-details-view.tsxindex 49755104e9..8d691b2d46 100644--- a/autogpt_platform/frontend/src/components/agents/agent-run-details-view.tsx+++ b/autogpt_platform/frontend/src/components/agents/agent-run-details-view.tsx@@ -133,7 +133,8 @@ export default function AgentRunDetailsView({| null| undefined = useMemo(() => {if (!("outputs" in run)) return undefined;- if (!["running", "success", "failed"].includes(runStatus)) return null;+ if (!["running", "success", "failed", "stopped"].includes(runStatus))+ return null;// Add type info from agent input schemareturn Object.fromEntries(