Skip to content

Self-improving AI Employees for everyone

fix(temporal): show why a failed canvas Run failed

trohitg51774a7735e8
diff --git a/docs-internal/TEMPORAL_ARCHITECTURE.md b/docs-internal/TEMPORAL_ARCHITECTURE.md
index f1f13cba..cb494d65 100644
--- a/docs-internal/TEMPORAL_ARCHITECTURE.md
+++ b/docs-internal/TEMPORAL_ARCHITECTURE.md
@@ -210,6 +210,10 @@ while True:
break
done_id, result = await self._wait_any_complete(running)
+ if not result.get("success"):
+ # The first failure stops the run (see "4. The run result").
+ errors.append({"node_id": done_id, "error": result.get("error", "Unknown error")})
+ break
completed.add(done_id)
outputs[done_id] = result
```
@@ -246,6 +250,16 @@ The 2-minute `heartbeat_timeout` would kill browser or claude_code_agent activit
In the legacy path the server broadcasts status updates, tool-glow events, and progress messages continuously during execution, so the WS-read-loop heartbeats keep the activity alive for as long as anything is happening. Start/end heartbeats alone are not enough — any operation longer than 2 minutes would trigger `TIMEOUT_TYPE_HEARTBEAT` and Temporal would retry (or fail) the activity.
+### 4. The run result
+
+`MachinaWorkflow.run` returns `{success, outputs, execution_trace, errors}`. `success` is true only when no node failed and every node in the executable graph completed. The first node that fails stops the run. `errors` then holds that failure as `{node_id, error}`, plus whichever of `hint`, `requires_user_action` and `retryable` the node supplied, and it is `None` when nothing failed. Only an empty graph returns a top-level `error` ("No nodes provided") instead.
+
+`TemporalExecutor.execute_workflow` turns that into the Run response:
+- `errors` is the workflow's list unchanged, or `[{"error": ...}]` for an empty graph or a failed Temporal call;
+- `error` is the first entry's message, or `None`.
+
+`WorkflowService._execute_temporal` forwards both. The editor's Run dialog shows only `error` ("Workflow failed: …"), so before both kept it, every failed Run said "Unknown error" ([Known Errors #31](./errors.md)). Locked by `server/tests/temporal/test_run_errors.py`.
+
## Connection Pooling
Activities use a shared aiohttp.ClientSession for connection pooling:
diff --git a/docs-internal/errors.md b/docs-internal/errors.md
index aab60d2a..f55933e8 100644
--- a/docs-internal/errors.md
+++ b/docs-internal/errors.md
@@ -639,3 +639,15 @@ To reproduce the old failure on 3.12.8, run `kill_orphaned_opencompany_processes
- `month_day` `L`: the "last day of the month" a Home hire can ask for. Temporal's cron values are integers and month or weekday names only.
See the [cronScheduler card](./node-logic-flows/workflow_triggers/cronScheduler.md).
+
+## 31. A failed canvas Run says `Workflow failed: Unknown error`
+
+**Symptom**: Run a whole workflow with Temporal on (the default). When a node fails, the result dialog says `Workflow failed: Unknown error` and the response's `errors` list is empty, whatever the node's actual error was.
+
+**Root cause**: `MachinaWorkflow.run` stops at the first failed node and returns that failure in `errors`, a list of `{node_id, error, ...}`. Only an empty graph returns a top-level `error`. `TemporalExecutor.execute_workflow` read only the top-level `error`, so it reported no errors, and `WorkflowService._execute_temporal` passed no `error` on at all. The dialog shows only `error`.
+
+**Fix**: the executor keeps the workflow's `errors` and sets `error` to the first message; an empty graph or a failed Temporal call becomes `[{"error": ...}]`. `_execute_temporal` forwards `error`. Locked by `server/tests/temporal/test_run_errors.py`. The result contract is in [Temporal Architecture → The run result](./TEMPORAL_ARCHITECTURE.md#4-the-run-result).
+
+**Still open**:
+- A successful Run's dialog says `0/0 nodes completed` on every path, because no path sets `total_nodes` or `completed_nodes`.
+- Without Temporal, a failed Run still says `Unknown error`. The sequential path reports failures only in `node_results`, and the Redis-only parallel path only in `errors`.
diff --git a/server/services/temporal/executor.py b/server/services/temporal/executor.py
index 047badf2..a342d4ed 100644
--- a/server/services/temporal/executor.py
+++ b/server/services/temporal/executor.py
@@ -178,12 +178,16 @@ class TemporalExecutor:
execution_time=execution_time,
)
+ # MachinaWorkflow reports node failures as ``errors``; only an
+ # empty graph comes back with a top-level ``error``.
+ errors = result.get("errors") or ([{"error": result["error"]}] if result.get("error") else [])
return {
"success": result.get("success", False),
"execution_id": execution_id,
"nodes_executed": result.get("execution_trace", []),
"outputs": result.get("outputs", {}),
- "errors": [result.get("error")] if result.get("error") else [],
+ "errors": errors,
+ "error": errors[0].get("error") if errors else None,
"execution_time": execution_time,
"temporal_execution": True,
"timestamp": datetime.now().isoformat(),
@@ -207,7 +211,8 @@ class TemporalExecutor:
"execution_id": execution_id,
"nodes_executed": [],
"outputs": {},
- "errors": [error_details],
+ "errors": [{"error": error_details}],
+ "error": error_details,
"execution_time": execution_time,
"temporal_execution": True,
"timestamp": datetime.now().isoformat(),
diff --git a/server/services/workflow.py b/server/services/workflow.py
index f7f63a2a..a7792ecb 100644
--- a/server/services/workflow.py
+++ b/server/services/workflow.py
@@ -452,6 +452,7 @@ class WorkflowService:
"nodes_executed": result.get("nodes_executed", []),
"outputs": result.get("outputs", {}),
"errors": result.get("errors", []),
+ "error": result.get("error"),
"execution_time": result.get("execution_time", time.time() - start_time),
"temporal_execution": True,
"timestamp": datetime.now().isoformat(),
diff --git a/server/tests/temporal/test_run_errors.py b/server/tests/temporal/test_run_errors.py
new file mode 100644
index 00000000..fcbdb1ad
--- /dev/null
+++ b/server/tests/temporal/test_run_errors.py
@@ -0,0 +1,81 @@
+"""A failed canvas Run on the Temporal path reports why it failed.
+
+MachinaWorkflow returns per-node failures as ``errors`` (a list of
+``{node_id, error, ...}``), and only an empty graph returns a top-level
+``error``. The Run response the editor shows reads ``error`` for its message
+and ``errors`` for detail, so both must survive TemporalExecutor and
+WorkflowService._execute_temporal.
+"""
+
+from __future__ import annotations
+
+import time
+from types import SimpleNamespace
+from unittest.mock import AsyncMock, MagicMock
+
+import pytest
+
+import nodes # noqa: F401 -- populate the node registry
+
+
+async def _run(client_result=None, client_error=None):
+ from services.temporal.executor import TemporalExecutor
+
+ client = MagicMock()
+ client.execute_workflow = AsyncMock(return_value=client_result, side_effect=client_error)
+ return await TemporalExecutor(client).execute_workflow(workflow_id="wf-1", nodes=[], edges=[])
+
+
+async def test_a_node_failure_reaches_the_run_result():
+ failure = {"node_id": "wf-1:aiAgent:1", "error": "No API key for openai", "hint": "Add one in Credentials"}
+
+ result = await _run({"success": False, "outputs": {}, "execution_trace": [], "errors": [failure]})
+
+ assert result["success"] is False
+ assert result["errors"] == [failure]
+ assert result["error"] == "No API key for openai"
+
+
+async def test_a_workflow_level_error_is_reported_like_a_node_failure():
+ result = await _run({"success": False, "error": "No nodes provided", "outputs": {}, "execution_trace": []})
+
+ assert result["errors"] == [{"error": "No nodes provided"}]
+ assert result["error"] == "No nodes provided"
+
+
+async def test_a_client_failure_is_reported_like_a_node_failure():
+ result = await _run(client_error=RuntimeError("worker unavailable"))
+
+ assert result["success"] is False
+ assert result["errors"] == [{"error": "RuntimeError: worker unavailable"}]
+ assert result["error"] == "RuntimeError: worker unavailable"
+
+
+async def test_a_successful_run_reports_no_error():
+ result = await _run({"success": True, "outputs": {}, "execution_trace": ["n1"], "errors": None})
+
+ assert result["errors"] == []
+ assert result["error"] is None
+
+
+async def test_the_workflow_service_passes_the_message_on():
+ from services.workflow import WorkflowService
+
+ service = WorkflowService.__new__(WorkflowService)
+ service._resolve_workflow_slug = AsyncMock(return_value="workflow")
+ failure = {"node_id": "n1", "error": "boom"}
+ service._temporal_executor = SimpleNamespace(
+ execute_workflow=AsyncMock(
+ return_value={"success": False, "nodes_executed": [], "outputs": {}, "errors": [failure], "error": "boom"}
+ )
+ )
+
+ result = await service._execute_temporal([], [], "session", None, time.time(), "wf-1")
+
+ assert result["errors"] == [failure]
+ assert result["error"] == "boom"