# What structural signals indicate a speculative parallel branch has silently committed a non-idempotent side effect before conflict resolution **Date of Record:** 2026 November 24 **Scope:** Applies to orchestrators that fan out optimistic parallel branches from a shared checkpoint, allow branches to execute tool calls speculatively, and resolve conflicts deterministically by replaying or discarding losers. Does not apply to strictly serialized agents or to branches whose tool surface is provably read-only. ## Core Distinction The distinction that matters is between **speculative state** (branch-local scratch that the resolver can rewind) and **committed external state** (side effects that crossed the sandbox boundary — sent emails, written rows, charged cards, posted messages). Optimistic orchestration assumes every branch's work is rewound on loss. That assumption holds for branch-local memory, KV cache, and scratch files. It fails the moment a branch performs a *non-idempotent* tool call, because the resolver's "discard the loser" operation rewinds the branch's context but cannot un-send the email. The failure is silent: the deterministic conflict resolver reports a clean resolution, the winning branch's state is correct, and the loser's side effect lives on in the outside world. The structural signal that this has happened is a **divergence between the resolver's committed-state ledger and the external system's observable state** — a divergence that no branch-local consistency check will ever surface. ## What Was Observed A three-branch fan-out was issued from a checkpoint at step 12 to draft and send a customer notification. Each branch was given the same task with slightly different prompts (tone variants) and permitted to call `send_email`. The resolver's contract: branches return a `(proposal, confidence)` tuple; the highest-confidence proposal wins; losers are discarded via context rewind. Deterministic tiebreak on confidence equality by branch index. Trace: 1. Branch A (index 0) called `send_email(customer=4471, body=tone_formal)` at step 14. Tool returned `{"status":"queued","message_id":"m_8f2"}`. 2. Branch B (index 1) called `send_email(customer=4471, body=tone_warm)` at step 14. Tool returned `{"status":"queued","message_id":"m_8f3"}`. 3. Branch C (index 2) failed schema validation on its proposal and returned confidence 0.0. 4. Resolver compared A and B: both confidence 0.91. Tiebreak by index → A wins. 5. Resolver rewound B's context to checkpoint 12, marked B `discarded`, and committed A's state. Resolution log: `{"winner":0,"losers":[1,2],"status":"clean"}`. Customer 4471 received two emails. The resolver's ledger recorded one send. The structural signal was visible only at the transport layer: the mail gateway logged `m_8f2` and `m_8f3` against the same recipient within 340ms, with the same idempotency key scope (customer-scoped, not branch-scoped). The orchestrator's own telemetry showed zero anomalies because the loser's rewind was, from its perspective, complete. The non-obvious part: the branch's tool-call record *was* rewound. The message_id `m_8f3` was removed from B's context, so a post-hoc inspection of B's transcript showed no send. The evidence of the side effect survived only outside the agent system entirely. ## Condition of Validity The invariant that optimistic parallel orchestration depends on is: > **For every tool call issued by a speculative branch, the external effect must be either (a) idempotent under the branch's idempotency key, or (b) deferred until after conflict resolution commits the branch.** This invariant is valid only when the orchestrator can *classify* each tool in a branch's granted capability set as `speculatable` or `commit-required` before the branch runs. The classification must be derived from the tool's declared schema — specifically, whether the tool accepts a caller-supplied idempotency key whose scope is the *branch*, not the *task*. A tool whose idempotency key is task-scoped (as `send_email` was here — customer-scoped) is not speculatable, because two branches sharing a task share an idempotency key and the second call is deduplicated, not distinguished. That is the boundary: **task-scoped idempotency keys make a tool look safe for speculative execution while silently collapsing distinct branch intents into one external effect — or, when the tool's dedup window is shorter than the branch fan-out latency, into two.** The condition breaks when: (1) the tool schema declares an idempotency key but its scope is coarser than the branch; (2) the tool's dedup window is shorter than the maximum inter-branch skew (here 340ms — fine — but a fan-out with a slow branch can exceed a 60s dedup window); (3) the branch's capability grant was widened at runtime by a tool-discovery step (MCP `tools/list` returning a new tool mid-branch) without re-classification. ## Decision Boundary The resolver must not treat "rewind succeeded" as equivalent to "side effect reverted." The decision boundary is a **pre-fan-out capability classification gate** plus a **post-resolution reconciliation check**: - **Pre-fan-out:** partition each branch's granted tools into `speculatable` (idempotent under branch-scoped key, or read-only) and `commit-required`. Any branch whose plan includes a `commit-required` tool must be run in *pessimistic* mode — serialized behind the resolver, or executed only after the winning proposal is known. Optimism is permitted only over the `speculatable` subset. - **Post-resolution:** the resolver must reconcile its committed-state ledger against the external systems' observable state for every `commit-required` tool invoked by any branch, including losers. A `discarded` branch that invoked a `commit-required` tool is a **contamination event**, not a clean discard. The boundary is sharp: if you cannot classify a tool, you cannot speculate over it. Treating unclassified tools as speculatable is the exact error that produced the double-send. ## Operational Effect When the gate is absent, the observable effect is **orphaned side effects**: external state mutations whose originating branch is marked `discarded` and whose record is absent from the orchestrator's ledger. These are detectable only by cross-referencing external system logs against the resolver's resolution log, keyed on the tool's idempotency key and a time window bounded by the fan-out skew. The reconciliation must be run *per resolution*, not per task, because a single task may contain multiple fan-outs and the contamination is per-branch. The secondary effect is worse: because the loser's transcript is rewound, any downstream agent that later reads the loser's memory sees no evidence of the send, and may re-issue it. The contamination propagates as a *memory-consistent* re-execution — the system believes it is acting on a clean state. This is the failure mode that turns a single double-send into a loop. The guardrail is architectural, not prompt-level: the resolver's commit operation must be the *only* path by which a `commit-required` tool is invoked, and the branch's tool-call surface must be physically incapable of reaching such a tool. Capability grants, not instructions, enforce this. ```python class SpeculativeCommitViolation(RuntimeError): """Raised when a discarded branch is found to have committed an external side effect.""" pass COMMIT_REQUIRED = {"send_email", "charge_card", "post_message", "write_row"} SPECULATABLE = {"read_record", "search", "draft_text"} def classify_branch_tools(granted_tools: set[str]) -> dict[str, str]: classification = {} for tool in granted_tools: if tool in SPECULATABLE: classification[tool] = "speculatable" elif tool in COMMIT_REQUIRED: classification[tool] = "commit-required" else: # Unknown tools are never speculatable. This is the gate. classification[tool] = "commit-required" return classification def assert_speculation_safe(branch_id: str, granted_tools: set[str]) -> None: cls = classify_branch_tools(granted_tools) unsafe = [t for t, c in cls.items() if c == "commit-required"] if unsafe: raise SpeculativeCommitViolation( f"branch {branch_id} granted commit-required tools {unsafe}; " f"must run pessimistic, not speculative" ) def reconcile_resolution(resolution: dict, external_log: list[dict]) -> None: """Called after conflict resolution. Detects orphaned side effects.""" committed_ids = { call["message_id"] for branch in resolution["branches"] if branch["status"] == "committed" for call in branch.get("tool_calls", []) if call["tool"] in COMMIT_REQUIRED } for entry in external_log: if entry["tool"] not in COMMIT_REQUIRED: continue if entry["message_id"] not in committed_ids: raise SpeculativeCommitViolation( f"orphaned side effect: {entry['tool']} -> {entry['message_id']} " f"from branch {entry['branch_id']} marked discarded; " f"external state diverged from resolver ledger" ) ```