Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(workflow): stop re-broadcasting every node as `completed` after a run
trohitg5ede76325dbf
diff --git a/server/services/workflow.py b/server/services/workflow.pyindex 09519487..1f044dc8 100644--- a/server/services/workflow.py+++ b/server/services/workflow.py@@ -451,18 +451,13 @@ class WorkflowService:user_id=user_id,)- # Notify status callback for completed nodes if provided- if status_callback and result.get("success"):- for node_id in result.get("nodes_executed", []):- try:- await status_callback(- node_id,- "completed",- result.get("outputs", {}).get(node_id, {}),- )- except Exception:- pass-+ # No status is sent here: every node already reported its own final+ # `success` or `error`, with its result, while the run executed (the+ # per-type activity, the legacy activity through handle_execute_node,+ # and the agent workflow each broadcast it). Sending another status+ # per node after the run would overwrite those with a word the editor+ # does not know and a different payload. `status_callback` stays in+ # the signature for the paths that need it.return {"success": result.get("success", False),"execution_id": result.get("execution_id"),@@ -604,9 +599,10 @@ class WorkflowService:if result.get("success"):envelopes[node_id] = result- # Notify completed+ # Notify the final status, in the editor's vocabulary: `success`+ # or `error`, the same words handle_execute_node sends.if status_callback:- status = "completed" if result.get("success") else "error"+ status = "success" if result.get("success") else "error"try:await status_callback(node_id, status, result)except Exception:diff --git a/server/tests/services/test_workflow_run_result.py b/server/tests/services/test_workflow_run_result.pyindex fa53627f..0f9bab65 100644--- a/server/tests/services/test_workflow_run_result.py+++ b/server/tests/services/test_workflow_run_result.py@@ -67,6 +67,48 @@ async def test_the_sequential_path_counts_a_clean_run():assert (result["completed_nodes"], result["total_nodes"]) == (3, 3)+async def test_the_sequential_path_reports_node_status_in_the_editors_words():+ """The editor's node statuses are idle / executing / success / error /+ waiting. The sequential path used to finish a node with `completed`,+ which the canvas does not know, so a node that succeeded lost its+ success state instead of showing it."""+ service = _sequential_service({"b": {"success": False, "error": "b broke"}})+ sent: list[tuple[str, str]] = []++ async def status_callback(node_id, status, _data=None):+ sent.append((node_id, status))++ await service._execute_sequential(*_chain(), "session", status_callback, time.time())++ assert ("a", "success") in sent+ assert ("b", "error") in sent+ assert all(status != "completed" for _node, status in sent)+++async def test_the_temporal_path_sends_no_status_after_the_run():+ """Each node reports its own final status while the Temporal run+ executes. The service used to send every executed node again as+ `completed` with its raw output afterwards, overwriting the `success`+ and the result the node had just reported."""+ service = WorkflowService.__new__(WorkflowService)+ service._temporal_executor = SimpleNamespace(execute_workflow=AsyncMock(return_value={+ "success": True,+ "nodes_executed": ["start-1", "a", "b"],+ "outputs": {"a": {"text": "hi"}},+ "total_nodes": 3,+ "completed_nodes": 3,+ }))+ service._resolve_workflow_slug = AsyncMock(return_value="Flow_1")+ status_callback = AsyncMock()++ result = await service._execute_temporal(*_chain(), "session", status_callback, time.time(), workflow_id="wf")++ assert result["success"] is True+ status_callback.assert_not_awaited()++@pytest.mark.asyncioasync def test_the_parallel_path_passes_a_failed_node_on():failure = {"node_id": "a", "error": "a broke", "timestamp": 1.0}