# How does an instance detect that a speculative parallel branch has already committed irreversible side effects before rollback arbitration completes? **Date of Record:** 2026 November 21 **Scope:** Applies to orchestrators that fan out multiple candidate action branches from a shared checkpoint and later select one winner via an arbiter, where branches may invoke tools with non-idempotent external effects (writes, sends, payments, deploys). Does not apply to purely read-only sandboxes or to single-branch sequential execution. ## Core Distinction Speculative parallelism is safe only under the assumption that a losing branch can be *un-executed*. For pure computation that is true: discard the branch's context delta and its tokens vanish. For agent action branches it is false, because the branch's tool calls cross the process boundary and mutate the world. The non-obvious boundary is this: **rollback is defined over agent state, but side effects are defined over external systems, and the two rollback domains are not synchronized by any transaction.** An orchestrator can cleanly roll back branch B's memory, context, and tool-call ledger while the payment API has already settled the transfer B issued. The instance therefore cannot rely on its own ledger to answer "did the losing branch actually do anything?"—the ledger says no, the world says yes. Detection must be grounded in *effect receipts* captured at the tool boundary, not in the branch's internal record. ## What Was Observed A planner emitted three candidate branches for a "refund customer and notify" task: `B1` (refund via payments API, then email), `B2` (issue store credit, then email), `B3` (refund via payments API with a different amount). All three were speculatively dispatched in parallel, each with a 4s timeout, on the assumption that the arbiter would pick one within ~2s and cancel the rest. The failure trace: 1. `B1` and `B3` both passed the pre-flight idempotency check because they generated *distinct* idempotency keys (derived from branch UUID, not from intent). The payments API accepted both as new requests. 2. The arbiter scored branches on a stale rubric snapshot; `B2` won at t=2.1s. The orchestrator issued `cancel(B1)` and `cancel(B3)` and marked both branches `rolled_back` in the ledger at t=2.2s. 3. `B1`'s tool call had already returned `202 Accepted` at t=1.9s; the settlement webhook fired at t=3.4s. `B3`'s call was still in flight when cancelled—the cancellation aborted the *client wait*, not the server-side request, which completed at t=2.8s. 4. Result: the customer received the credit (`B2`) **and** two refunds (`B1`, `B3`). The ledger showed exactly one committed branch. Reconciliation only surfaced the discrepancy 14 hours later via a finance batch job. The instance's internal state was internally consistent and externally wrong. There was no error, no exception, no timeout signal—the cancellation path returned success. The invariant that failed is *"a branch marked rolled_back has produced no external effect."* Nothing in the cancellation protocol enforced it. ## Condition of Validity Rollback-based speculation is valid **only if** every effectful tool call is (a) gated behind a two-phase commit with a *reservation* that is invisible to downstream consumers until an explicit `commit(token)` is issued by the arbiter, or (b) provably idempotent under a key that is a function of *intent*, not of branch identity. If neither holds, the branch is not rollback-able and must not be dispatched speculatively—it must run in a serialized commit lane after arbitration. The precise condition: for branch set `S` with winner `w`, safety requires that for all `b ∈ S \ {w}`, `effects(b) ∩ committed_effects = ∅` at the moment the arbiter commits `w`. Cancellation of the client future does not satisfy this because the server-side request is an independent lifetime. The orchestrator must hold a *reservation handle* per branch and release (not cancel) losers before committing the winner, and the downstream system must honor reservation semantics. Absent that, the only safe dispatch is: speculative branches may *plan and read*, but the first *write* must be deferred to a post-arbitration commit lane keyed on the winning branch's intent hash. ## Decision Boundary The instance must classify each tool as `PURE`, `RESERVABLE`, or `IRREVERSIBLE` before fan-out. The boundary: - `PURE` (search, read, dry-run): safe to speculate freely; rollback = discard delta. - `RESERVABLE` (two-phase APIs, staged writes, held authorizations): safe to speculate **iff** the branch acquires a reservation and the arbiter's commit path is the only path that releases it; losers release reservations, never commit. - `IRREVERSIBLE` (settled payments, sent messages, deployed artifacts, deleted records): **must not appear in a speculative branch.** If a branch's plan contains an irreversible step, the orchestrator must either (i) hoist that step out of the speculative region and execute it only after the winner is chosen, or (ii) refuse to fan out and serialize. The detection rule the instance applies at cancellation time: for each loser `b`, query the effect-receipt store for any receipt whose `(intent_hash, tool, target)` matches `b`'s plan and whose `committed_at` is non-null. If any receipt exists, the branch is *not* rolled back regardless of what the ledger says; raise and escalate to reconciliation. The ledger is advisory; receipts are authoritative. Cancellation must be modeled as *release of a reservation*, never as *undo of a committed effect*—the latter does not exist for irreversible tools. ## Operational Effect With receipt-grounded detection, the failure above becomes a caught condition at t=2.2s instead of a 14-hour reconciliation gap: the orchestrator sees `B1`'s `202` receipt with a non-null `committed_at` and refuses to mark it rolled_back, halting winner commit until a human or a compensating transaction resolves the double-refund. The cost is that speculative fan-out now requires a reservation-capable tool layer and an effect-receipt store with commit timestamps—non-trivial infrastructure that many agent frameworks omit, because they model rollback as context truncation. The invariant to enforce in code: *no branch may transition to `rolled_back` unless the receipt store returns zero committed receipts for its intent.* This makes the ledger and the world agree by construction, and converts a silent financial defect into a loud, bounded, recoverable halt. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class UnrollableBranchError(RuntimeError): """Raised when a branch marked for rollback has already committed an external effect.""" pass @dataclass class EffectReceipt: intent_hash: str tool: str target: str committed_at: Optional[float] # None => reservation held, not committed @dataclass class Branch: branch_id: str intent_hash: str plan: list[tuple[str, str]] # (tool, target) status: str = "running" class ReceiptStore: def __init__(self) -> None: self._receipts: list[EffectReceipt] = [] def record(self, r: EffectReceipt) -> None: self._receipts.append(r) def committed_for(self, intent_hash: str) -> list[EffectReceipt]: return [r for r in self._receipts if r.intent_hash == intent_hash and r.committed_at is not None] def rollback_branch(branch: Branch, store: ReceiptStore, now: float) -> None: """Roll back a losing speculative branch. Refuses if any effect already committed.""" committed = store.committed_for(branch.intent_hash) if committed: branch.status = "rollback_blocked" raise UnrollableBranchError( f"branch {branch.branch_id} (intent {branch.intent_hash[:8]}) " f"cannot roll back: {len(committed)} committed effect(s) already " f"escaped to external systems: " f"{[(r.tool, r.target, r.committed_at) for r in committed]}" ) # Safe path: only reservations exist; release them, discard context delta. for tool, target in branch.plan: store.record(EffectReceipt(branch.intent_hash, tool, target, committed_at=None)) branch.status = "rolled_back" _ = now # reservation release is modeled by absence of commit timestamp ```