# Why does an instance in a speculative parallel branch commit an irreversible external effect before the winning branch is known, and how do we bound it? **Date of Record:** 2026 November 25 **Scope:** Applies to multi-agent orchestrators that speculatively fork a plan into parallel execution branches and roll back losing branches after arbitration. Does not apply to strictly sequential single-agent loops or to branches whose tool calls are all provably pure/idempotent and side-effect-free. ## Core Distinction Rollback is a *state* operation, not a *world* operation. Optimistic execution assumes that a losing branch can be "undone" by discarding its context, its scratchpad, and its local memory writes. That assumption holds for internal agent state. It fails the moment a branch emits a tool call with **external, non-idempotent, irreversible side effects** — a payment, a `POST` to a webhook, an email, a file deletion, a database `INSERT` without a dedupe key, a container spawn. The orchestrator can unwind the branch's *beliefs* but cannot unwind the *world*. The failure is therefore not a bug in the rollback logic; it is a categorical mismatch between a reversible abstraction (branch state) and an irreversible substrate (external effect). Speculative execution is only sound when the speculative region is confined to effect-free operations, and the boundary between "effect-free" and "effectful" is decided per tool call, not per branch. ## What Was Observed A planner agent decomposed a task ("reconcile invoice, notify customer, archive record") into a DAG and speculatively launched three parallel branches with different reconciliation strategies. Each branch was given the same tool surface, including `send_email`, `charge_card`, and `archive_record`. Branch B reached a confident intermediate state after two tool calls and, following its own local reasoning, invoked `charge_card` optimistically — reasoning that the orchestrator would "roll back" if arbitration favored branch A. Branch A won arbitration 400 ms later. The orchestrator discarded branches B and C, cleared their scratchpads, and resumed from A's checkpoint. The card was charged. No branch had recorded it as committed because the commit was never written to shared state — the branch was *supposed* to be rolled back. The reconciliation ledger now disagreed with the payment processor by one charge, and the discrepancy surfaced only when the customer disputed the duplicate. The trace showed the exact mechanism: the branch's tool-call result was written to its *private* scratchpad (a `ToolResult` object with `status="ok"`), not to the shared effect log. Arbitration read only the shared log, saw no committed effects from B, and marked B cleanly discardable. The effect log was authoritative for rollback decisions but was not the sink for the side effect. Two records of truth, one of which the rollback path never consulted. ## Condition of Validity Optimistic parallel execution with rollback is valid **iff** every tool call reachable from a speculative branch is one of: (a) pure — no external effect; (b) idempotent under a branch-scoped idempotency key derived from `(task_id, branch_id, step_index)`; or (c) deferred — the call is staged into an outbox and only flushed after arbitration commits the branch. The invariant is: > For every speculative branch `b` and every tool call `t` emitted by `b`, `t` must not produce an external effect that is observable before `b` is committed by the arbiter, unless `t` is idempotent under `b`'s branch-scoped key. The moment this invariant is violated, rollback becomes a lie: it removes the branch from the orchestrator's model of the world while leaving the world changed. Note the subtlety — the invariant is about *observability before commit*, not about the tool's abstract purity. A `charge_card` call with a deterministic idempotency key is safe even though it is effectful, because a duplicate call from a re-run collapses. A `send_email` call is never safe under rollback because email has no dedupe semantics the orchestrator controls. ## Decision Boundary The orchestrator must classify each tool at registration time into `PURE`, `IDEMPOTENT_KEYED`, or `EFFECTFUL_DEFERRED`, and the branch scheduler must refuse to place an `EFFECTFUL_DEFERRED` tool inside a speculative region unless it is routed through the outbox. The decision boundary is *not* "does the branch look confident" — that is the failure mode observed above. Confidence is an LLM-internal signal and is not a substitute for a capability declaration. The boundary is: an effectful tool call may only be emitted by a branch that has been committed by the arbiter, or by a branch whose call carries a key that makes a duplicate harmless. If a branch's reasoning *wants* to call an effectful tool before arbitration, the correct response is to suspend the branch at that call, surface the intended effect to the arbiter as a *proposal*, and let arbitration decide whether to commit. This converts a speculative side effect into a speculative *intent*, which is safely discardable. A second boundary: the effect log must be the single sink for both rollback bookkeeping and external effects. If the branch writes tool results only to its private scratchpad, arbitration cannot see them and will declare the branch clean. The effect log entry must be written *before* the external call is dispatched (write-ahead), so that a crash mid-call still leaves a record the arbiter can reconcile. ## Operational Effect Without the invariant, the system exhibits *silent divergence*: the orchestrator's state and the external world disagree, and the disagreement is invisible to every subsequent verification step because verification replays the orchestrator's log, not the world. The failure is not detected by consensus checks, not by replay, and not by the branch's own self-report (`status="ok"`). It is detected only by an external reconciliation — a disputed charge, a duplicate email, an orphaned record — which arrives after the fact and is attributed to the wrong component. With the invariant enforced, speculative branches can still run in parallel and still be rolled back, but the rollback is honest: the only things discarded are beliefs and proposals, never effects. The cost is latency on effectful steps (they serialize behind arbitration), which is the correct trade — an irreversible effect is worth a round-trip to the arbiter. The guardrail is a write-ahead effect log plus a tool capability registry plus a branch scheduler that refuses to speculate across `EFFECTFUL_DEFERRED` tools. The following enforces the invariant at the point where a branch attempts to emit a tool call. ```python from dataclasses import dataclass from enum import Enum from typing import Optional class EffectClass(Enum): PURE = "pure" IDEMPOTENT_KEYED = "idempotent_keyed" EFFECTFUL_DEFERRED = "effectful_deferred" class SpeculativeEffectViolation(RuntimeError): """Raised when a speculative branch emits an effect that rollback cannot undo.""" @dataclass(frozen=True) class ToolCall: tool: str effect_class: EffectClass branch_id: str task_id: str step_index: int idempotency_key: Optional[str] = None @dataclass class Branch: branch_id: str committed: bool = False class EffectLog: """Write-ahead log; the single sink consulted by both rollback and arbitration.""" def __init__(self) -> None: self._entries: list[ToolCall] = [] def record(self, call: ToolCall) -> None: self._entries.append(call) def has_effect(self, branch_id: str) -> bool: return any( e.branch_id == branch_id and e.effect_class is EffectClass.EFFECTFUL_DEFERRED for e in self._entries ) def dispatch(branch: Branch, call: ToolCall, log: EffectLog) -> None: if branch.committed: log.record(call) return if call.effect_class is EffectClass.PURE: return if call.effect_class is EffectClass.IDEMPOTENT_KEYED: expected = f"{call.task_id}:{call.branch_id}:{call.step_index}" if call.idempotency_key != expected: raise SpeculativeEffectViolation( f"branch {call.branch_id} emitted keyed effect {call.tool} " f"with key {call.idempotency_key!r}, expected {expected!r}; " f"a re-run or duplicate branch would not collapse." ) log.record(call) return # EFFECTFUL_DEFERRED inside an uncommitted branch: must be staged, not dispatched. raise SpeculativeEffectViolation( f"branch {call.branch_id} attempted irreversible tool {call.tool!r} " f"(step {call.step_index}) before arbitration commit; " f"rollback would discard branch state but leave the external effect." ) ```