Skip to content

Self-improving AI Employees for everyone

fix(temporal): the AgentWorkflow carry drops the payload's seed keys (1b.19)

trohitg675375dc1edb
diff --git a/docs-internal/TEMPORAL_ARCHITECTURE.md b/docs-internal/TEMPORAL_ARCHITECTURE.md
index 05c9d386..7fa2be3f 100644
--- a/docs-internal/TEMPORAL_ARCHITECTURE.md
+++ b/docs-internal/TEMPORAL_ARCHITECTURE.md
@@ -715,7 +715,9 @@ delegation handles or Task Manager tasks. Version 1 parks at that boundary
while stopped and waits for all control handlers to finish before
continue-as-new. The next input carries pause/revision/hold state, application
execution identity, transcript, accumulated thinking, iteration, usage,
-context usage, prepared payload, and the resolved tool bindings. A rollover
+context usage, prepared payload (without its seed `conversation`,
+`memory_content` and `parameter_snapshot`, which a resumed run does not read
+from it), and the resolved tool bindings. A rollover
changes Temporal's Run ID while preserving the application's execution scope.
The converter measures the **complete encoded continuation input**, including
diff --git a/docs-internal/agent_context_flow.md b/docs-internal/agent_context_flow.md
index ac6fd46a..0d21b872 100644
--- a/docs-internal/agent_context_flow.md
+++ b/docs-internal/agent_context_flow.md
@@ -114,7 +114,12 @@ the transcript. `AgentWorkflow` restores these values and skips
definitions, plugin Activity policies, and explicit in-run binding changes.
Configuration edited during a pause or restart cannot reconstruct a different
continuation. Iteration, usage, context usage, thinking, application execution
-identity, and control revision/hold state are carried too.
+identity, and control revision/hold state are carried too. The carried payload
+leaves out its seed keys (`conversation`, `memory_content`, `parameter_snapshot`;
+`_carried_payload`): the carried transcript always wins over the stored
+conversation, and the context already carries the snapshot a rebind kept
+current, so a 1 MB seed conversation no longer counts twice against the byte
+guard.
Rollover happens at a completed-turn boundary without live child handles or
Task Manager tasks. A stopped agent waits there for Resume and for control
diff --git a/server/services/temporal/agent_workflow.py b/server/services/temporal/agent_workflow.py
index 0ec2bf21..c82df598 100644
--- a/server/services/temporal/agent_workflow.py
+++ b/server/services/temporal/agent_workflow.py
@@ -382,6 +382,20 @@ def _employee_runtime_metadata() -> dict:
_CAN_TRANSCRIPT_MAX_BYTES = 1_000_000
_CAN_INPUT_MAX_BYTES = 1_900_000
+# The seed keys of the prepared payload that a durable rollover does not carry
+# (1b.19). The resumed run reads `conversation` and `memory_content` only when
+# it has no carried transcript (it always has one here), and the run's own
+# `parameter_snapshot` already rides in the context, where a tool rebind keeps
+# it current; carried again it would overwrite that copy. A Context agent's
+# seed conversation alone can be 1 MB, which the byte guard counted twice. A
+# denylist on purpose: the resumed run reads every other key.
+_CARRY_DROPPED_KEYS = frozenset({"conversation", "memory_content", "parameter_snapshot"})
+
+
+def _carried_payload(payload: Dict[str, Any]) -> Dict[str, Any]:
+ """The prepared payload a durable rollover carries: all of it but the seed keys."""
+ return {key: value for key, value in payload.items() if key not in _CARRY_DROPPED_KEYS}
+
def _inherited_scope(context: Dict[str, Any], *, delegation: bool = False) -> Dict[str, Any]:
"""Return the scope keys a delegated child must inherit from its parent."""
@@ -3181,7 +3195,7 @@ class AgentWorkflow:
"transcript": messages,
"usage": usage_total,
"context_usage": context_usage_total,
- "prepared_payload": payload,
+ "prepared_payload": _carried_payload(payload),
"tools": tools,
"thinking": thinking_accumulated,
"browser_artifacts": browser_artifacts,
diff --git a/server/tests/temporal/test_agent_workflow.py b/server/tests/temporal/test_agent_workflow.py
index 9a71556f..fb947cf1 100644
--- a/server/tests/temporal/test_agent_workflow.py
+++ b/server/tests/temporal/test_agent_workflow.py
@@ -1278,6 +1278,37 @@ class TestAgentContinueAsNew:
):
assert required in carried, f"{required} must cross the rollover"
+ def test_a_durable_rollover_carries_the_payload_without_its_seed_keys(self):
+ # 1b.19: the seed conversation (up to 1 MB) was counted again beside the
+ # live transcript, and the stale snapshot overwrote the refreshed one.
+ import inspect
+ from datetime import timedelta
+
+ from services.temporal.agent_workflow import (
+ _CARRY_DROPPED_KEYS,
+ AgentWorkflow,
+ _carried_payload,
+ llm_attempt_timeout,
+ )
+
+ payload = {
+ "node_id": "agent", "system_message": "s", "user_prompt": "go",
+ "conversation": [{"role": "user", "content": "earlier"}], "memory_content": "# earlier",
+ "parameter_snapshot": {"agent": {"label": "a"}}, "tools": [{"name": "t", "tool_node_id": "t"}],
+ "conversation_key": {"agent_node_id": "agent"}, "llm_attempt_timeout_seconds": 1800.0,
+ "context_pressure_version": 1, "tool_result_max_chars": 100_000, "transcript_budget_bytes": 393_216,
+ "chat_stream": {"run_id": "r"},
+ }
+ carried = _carried_payload(payload)
+ assert _CARRY_DROPPED_KEYS == {"conversation", "memory_content", "parameter_snapshot"}
+ assert list(carried) == [key for key in payload if key not in _CARRY_DROPPED_KEYS] # order kept
+ assert all(carried[key] is payload[key] for key in carried) # tools and the rest kept as they are
+ assert "conversation" in payload # the live payload is untouched
+ assert _carried_payload(carried) == carried # a second rollover
+ assert llm_attempt_timeout(carried) == timedelta(minutes=30) # 1b.25's key survives
+ # And the durable carry uses it.
+ assert '"prepared_payload": _carried_payload(payload)' in inspect.getsource(AgentWorkflow._run_impl)
+
def test_rollover_is_not_gated_on_a_context_node(self):
"""Every agent must roll over under history pressure.