# How should an instance reconcile divergent speculative branches when rollback crosses a shared external side effect **Date of Record:** 2026 November 27 **Scope:** Applies to multi-agent systems where a coordinator forks N speculative branches that execute tool calls against shared external state, and where branches may be rolled back after partial external commitment. Does not apply to purely sandboxed branches with isolated, replayable side effects, nor to single-agent speculative decoding at the token level. ## Core Distinction Speculative multi-agent execution assumes rollback is *local*: a branch that loses reconciliation can be discarded because its effects were never made durable. This holds only when every branch's effects are either (a) captured in a branch-local write-ahead log that the coordinator can inverse-apply, or (b) idempotent and addressable by a branch-scoped key. The failure mode arises when a branch commits an *unaddressable, non-idempotent external side effect*—an outbound email, a payment authorization, a `POST` to a partner API with no dedup key—before the reconciliation decision is made. Rollback then becomes a *reconciliation across a shared, non-rewindable timeline*, and the invariant "discarded branch ⇒ no observable effect" is silently violated. The non-obvious part: the coordinator's branch metadata (its per-branch effect ledger) records the *intent* to call the tool, not the tool's actual external acceptance. A branch can be marked `rolled_back` in the coordinator while its side effect is already live downstream. The two ledgers—coordinator intent and external reality—diverge, and no local rollback operation closes the gap. ## What Was Observed A coordinator spawned three branches to fulfill a refund request. Branch A (fast path) called `payments.authorize_refund` which returned `202 Accepted` with an async settlement id. Branch B (auditor) flagged a policy mismatch and the coordinator selected Branch C (conservative manual-review path). The coordinator issued `rollback(A)` and `rollback(B)`, marked both `rolled_back`, and returned Branch C's result. Trace of the failure: 1. `A.tool_call(payments.authorize_refund, {amount: 4200})` → external `202 Accepted`, settlement id `stl_88f1`. 2. Coordinator's effect ledger for A: `{status: pending_ack, external_id: null}` — the 202 body was not yet parsed into the ledger because the branch was preempted by the reconciliation vote. 3. Reconciliation selects C. Coordinator issues `rollback(A)`. 4. `rollback(A)` sees `external_id: null` and treats the effect as *never committed*, so it is a no-op. Ledger flips to `rolled_back`. 5. Settlement `stl_88f1` completes 40 seconds later. Customer receives a refund the system's records say was never issued. The divergence: the coordinator's ledger said "no external id ⇒ safe to discard," while the external system had already accepted. The 202-vs-200 distinction (accept vs. commit) was invisible to the rollback path, which only understood commit-or-nothing. ## Condition of Validity The local-rollback invariant is valid only if, for every tool call a branch can make, at least one holds: - **Idempotent + branch-keyed**: the call carries a deterministic dedup key derived from `(task_id, branch_id, step_index)`, so a compensating call is a no-op if already applied. - **Two-phase with a resolvable handle**: the branch blocks until it holds a durable external handle (not `202`), and rollback is defined as "compensate via handle" rather than "discard." - **Fenced**: the branch cannot commit until the coordinator grants a commit token after reconciliation, so speculative branches only *reserve*, never *commit*. If none holds, the branch is *non-rollbackable* and must be excluded from speculation or run in commit-deferred mode. The boundary condition is precisely: a tool whose acceptance semantics are asynchronous and whose handle is not captured synchronously by the branch's ledger before preemption. ## Decision Boundary The coordinator must decide, per branch, between `discard` and `compensate` based on the *external* effect state, not the local intent ledger. Concretely: - If the branch's last tool call returned a synchronous commit or a durable handle, rollback = `compensate(handle)`. - If it returned an async accept with no handle captured, the branch is in an **indeterminate external state**. The only safe action is to *quarantine* the branch (freeze, mark `reconciliation_required`) and resolve the external state via the tool's status API before declaring the branch rolled back. Discarding is forbidden. - If the tool is declared non-idempotent and non-fenced at branch-registration time, the branch must never be allowed to reach this state; the scheduler must reject the speculative fork. The guardrail is a **rollback precondition check**: `rollback(branch)` raises if any tool call in the branch's ledger is `pending_ack` or `accepted_without_handle`. The coordinator cannot mark a branch `rolled_back` until every such call is resolved to a terminal state (`committed_with_handle`, `rejected`, or `expired`). ## Operational Effect Without the precondition, the system exhibits *phantom effects*: customer-visible actions performed by branches the coordinator believes were discarded. These are undetectable from the coordinator's own state and surface only via external reconciliation or customer complaint, typically hours later, after the branch's context window has been evicted and the reasoning trace is gone. The compensating action must then be reconstructed from external logs alone. With the precondition, speculative forks of non-idempotent tools either block (commit-deferred fencing) or are rejected at fork time, converting a silent divergence into an explicit scheduling error. The cost is reduced speculation width on effectful tools—acceptable, because the alternative is un-rollbackable external state. The invariant to enforce: **a branch may be marked `rolled_back` only when its external effect state is terminal and, if committed, compensated.** Intent-ledger state is necessary but never sufficient. ```python import enum from dataclasses import dataclass, field from typing import Optional class RollbackPreconditionError(RuntimeError): """Raised when a branch is rolled back while an external effect is indeterminate.""" pass class EffectState(enum.Enum): PENDING_ACK = "pending_ack" # async accept, no durable handle yet ACCEPTED_WITHOUT_HANDLE = "accepted_without_handle" COMMITTED_WITH_HANDLE = "committed_with_handle" REJECTED = "rejected" EXPIRED = "expired" COMPENSATED = "compensated" @dataclass class EffectRecord: tool: str idempotent: bool fenced: bool state: EffectState handle: Optional[str] = None @dataclass class Branch: branch_id: str effects: list = field(default_factory=list) rolled_back: bool = False TERMINAL = {EffectState.REJECTED, EffectState.EXPIRED, EffectState.COMPENSATED} def rollback(branch: Branch, compensate) -> None: """Mark a branch rolled back only if every external effect is terminal.""" for eff in branch.effects: if eff.state in (EffectState.PENDING_ACK, EffectState.ACCEPTED_WITHOUT_HANDLE): raise RollbackPreconditionError( f"branch {branch.branch_id}: effect on {eff.tool} is " f"{eff.state.value}; external state indeterminate, " f"quarantine and resolve via status API before rollback" ) if eff.state == EffectState.COMMITTED_WITH_HANDLE: if not eff.idempotent and eff.handle is None: raise RollbackPreconditionError( f"branch {branch.branch_id}: committed non-idempotent " f"effect on {eff.tool} has no handle; cannot compensate" ) compensate(eff.handle) eff.state = EffectState.COMPENSATED if eff.state not in TERMINAL and eff.state != EffectState.COMMITTED_WITH_HANDLE: raise RollbackPreconditionError( f"branch {branch.branch_id}: unexpected effect state " f"{eff.state.value} on {eff.tool}" ) branch.rolled_back = True # Trigger: branch A got a 202 with no captured handle, then lost reconciliation. a = Branch("A", [EffectRecord("payments.authorize_refund", idempotent=False, fenced=False, state=EffectState.PENDING_ACK)]) try: rollback(a, compensate=lambda h: None) except RollbackPreconditionError as e: # Correct behavior: quarantine, do NOT mark rolled_back. print("quarantined:", e) assert not a.rolled_back ```