Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(temporal): forward conversation scope into per-type node activities
trohitgcea6e3d60808
diff --git a/docs-internal/errors.md b/docs-internal/errors.mdindex 04b1e953..30987334 100644--- a/docs-internal/errors.md+++ b/docs-internal/errors.md@@ -445,3 +445,13 @@ Seen on Ubuntu 26.04 (system Python 3.14).**Root cause**: The idle footprint is roughly 200 MB for the uvicorn backend plus 150 MB for the Temporal dev server it spawns, on top of the OS baseline (about 220 MB on a stock Ubuntu cloud image). The supervisor restarts the killed backend, so the box thrashes until it is rebooted.**Fix**: Use at least 1 GB of RAM. Measured on a t2.micro (951 MB): backend 197 MB RSS, Temporal 156 MB, about 300 MB still available after two minutes, zero OOM kills.++---++## 17. Claude Code Agent ignores its wired Context node: `context=no` in the log, a fresh session per chat message, zero rows in `agent_conversations`++**Symptom**: A deployed workflow has a Context node wired to `input-context` on a `claude_code_agent` (or `rlm_agent`). Every chat message starts a brand-new claude session, the Context panel never shows a conversation, and the node log prints `[Claude Code] Collected: ... context=no` even though the edge exists. `agent_conversations` stays empty across generations.++**Root cause**: `MachinaWorkflow` stamps `generation`, `graphVersion`, `context_execution_id` and `context_session_id` on each node's activity context, but the per-type activity wrapper in `services/plugin/base.py::as_activity` rebuilds the node context by calling `workflow_service.execute_node` with a fixed argument list and forwards only an allowlist of extra keys. The conversation-scope keys were not on it. The Context descriptor builder (`nodes/context/_descriptor.py`) returns `None` when `generation` is 0, and the edge walker treats `None` as "this edge contributes nothing", so the Context edge was silently dropped before the bridge ever ran. Native agents were unaffected because they run as an `AgentWorkflow` child that reads `generation` from its own payload; the nodes that always take the activity path were the ones affected. The in-process adapter `WorkflowService._execute_node_adapter` dropped the same keys.++**Fix**: both handoffs now forward `generation`, `graphVersion`, `root_execution_id`, `context_execution_id`, `context_session_id` and `data_scope_id` as extras. Locked by `tests/temporal/test_context_scope_forwarding.py`. With the descriptor intact the pool key is `(workflow_id, agent_node_id, generation)`, so chat messages within a deployment reuse one warm claude process and each turn is recorded in the Context store.diff --git a/server/services/plugin/base.py b/server/services/plugin/base.pyindex 782373b7..190f989a 100644--- a/server/services/plugin/base.py+++ b/server/services/plugin/base.py@@ -1052,6 +1052,16 @@ class BaseNode:# legacy handler so split-schema ToolInput validation# applies on the Temporal path too."tool_args",+ # Conversation scope. MachinaWorkflow stamps these on a+ # deployed run; the Context descriptor builder returns+ # None without ``generation``, which silently drops the+ # ``input-context`` edge for every node that runs as a+ # per-type activity (claude_code_agent, rlm_agent).+ "generation",+ "graphVersion",+ "context_execution_id",+ "context_session_id",+ "data_scope_id",):if key in context:extras[key] = context[key]diff --git a/server/services/workflow.py b/server/services/workflow.pyindex f5079825..da1b4cdf 100644--- a/server/services/workflow.py+++ b/server/services/workflow.py@@ -234,6 +234,20 @@ class WorkflowService:context: Dict[str, Any],) -> Dict[str, Any]:"""Adapter for WorkflowExecutor to call NodeExecutor."""+ # Conversation scope keys travel as extras so the Context descriptor+ # builder sees ``generation`` on the in-process path as well.+ extras = {+ key: context[key]+ for key in (+ "generation",+ "graphVersion",+ "root_execution_id",+ "context_execution_id",+ "context_session_id",+ "data_scope_id",+ )+ if key in context+ }return await self.execute_node(node_id=node_id,node_type=node_type,@@ -244,6 +258,7 @@ class WorkflowService:execution_id=context.get("execution_id"),workflow_id=context.get("workflow_id"),workflow_slug=context.get("workflow_slug"),+ extras=extras or None,user_id=(context.get("user_id")or _parallel_user_id.get()@@ -279,8 +294,8 @@ class WorkflowService:skip_clear_outputs: Skip clearing outputs (for deployment runs)workflow_id: Workflow ID for per-workflow status scoping (n8n pattern)use_temporal: Force Temporal execution (None = use settings default)- graph_version: Normalized graph version for Context V2 cutover- generation: Durable deployment generation for Context V2 cutover+ graph_version: Normalized graph version for the Context topology+ generation: Durable deployment generation for the Context storeuser_id: Authenticated server-owned user identity"""start_time = time.time()diff --git a/server/tests/temporal/test_agent_workflow_v2.py b/server/tests/temporal/test_agent_workflow_dispatch.pysimilarity index 100%rename from server/tests/temporal/test_agent_workflow_v2.pyrename to server/tests/temporal/test_agent_workflow_dispatch.pydiff --git a/server/tests/temporal/test_context_scope_forwarding.py b/server/tests/temporal/test_context_scope_forwarding.pynew file mode 100644index 00000000..db160569--- /dev/null+++ b/server/tests/temporal/test_context_scope_forwarding.py@@ -0,0 +1,67 @@+"""The conversation-scope keys MachinaWorkflow stamps on a deployed run must+reach ``NodeContext.raw`` on both node-execution paths.++Without ``generation`` the Context descriptor builder returns ``None`` and+the edge walker drops the ``input-context`` edge, so every node that runs+as a per-type activity (claude_code_agent, rlm_agent) silently ran without+its Context node: no stored conversation, a fresh provider session per+message."""++from __future__ import annotations++import inspect++import pytest++SCOPE_KEYS = (+ "generation",+ "graphVersion",+ "context_execution_id",+ "context_session_id",+ "data_scope_id",+)+++def test_as_activity_forwards_conversation_scope_into_context():+ from services.plugin.base import BaseNode++ source = inspect.getsource(BaseNode.as_activity.__func__)+ for key in SCOPE_KEYS:+ assert f'"{key}"' in source, (+ f"as_activity must forward {key!r} through extras; without it the "+ "Context descriptor builder sees generation 0 and drops the edge"+ )+++async def test_execute_node_adapter_forwards_conversation_scope():+ from services.workflow import WorkflowService++ captured: dict = {}++ async def fake_execute_node(self, **kwargs): # noqa: ANN001+ captured.update(kwargs)+ return {"success": True}++ svc = object.__new__(WorkflowService)+ svc.execute_node = fake_execute_node.__get__(svc, WorkflowService)++ context = {+ "nodes": [],+ "edges": [],+ "session_id": "s",+ "execution_id": "e",+ "workflow_id": "wf",+ "generation": 3,+ "graphVersion": 2,+ "context_execution_id": "wf-run-1",+ "context_session_id": "chat-1",+ "user_id": "owner",+ }+ await WorkflowService._execute_node_adapter(svc, "n1", "claude_code_agent", {}, context)++ extras = captured.get("extras") or {}+ assert extras["generation"] == 3+ assert extras["graphVersion"] == 2+ assert extras["context_execution_id"] == "wf-run-1"+ assert extras["context_session_id"] == "chat-1"