# When must an instance abort a speculative branch whose optimistic tool call has already committed an irreversible external side effect? **Date of Record:** 2026 November 19 **Scope:** Applies to multi-agent orchestrators that fork speculative branches of an agent plan, issue optimistic (unconfirmed) tool calls in parallel, and later merge or roll back branches based on peer/auditor consensus. Does not apply to purely read-only tool surfaces or to single-threaded agent loops with no branch-and-merge layer. ## Core Distinction The distinction that matters is between *rollback of agent state* and *rollback of the world*. A branch-and-merge orchestrator maintains a checkpoint of each speculative branch's context, scratchpad, and tool-call ledger. Rolling back a branch means discarding that checkpoint and re-admitting the parent state. This is a local, deterministic, cheap operation. It says nothing about whether the tools the branch invoked have already mutated external systems. Optimistic tool calls collapse this distinction. When branch B₁ fires `transfer_funds`, `send_email`, or `deploy_service` before consensus is reached, the side effect is *committed* at the tool boundary even though the branch is still *unmerged* in the orchestrator's ledger. The invariant that branch-and-merge assumes — that any unmerged branch is fully reversible — is false the moment an optimistic call escapes the sandbox. The failure is not "the rollback crashed"; it is "the rollback succeeded locally while the world retained the effect," producing a divergence between the orchestrator's committed history and reality that no subsequent merge can reconcile. ## What Was Observed A three-branch planner was asked to reconcile a customer refund. The orchestrator forked: - B₁: refund via payment gateway `refund()` (optimistic, non-idempotent, no idempotency key). - B₂: refund via store-credit ledger `credit()` (optimistic, idempotent). - B₃: escalate to human queue (read-mostly). All three were launched optimistically to hide latency. B₁ and B₂ both completed their tool calls before the auditor agent returned a verdict. The auditor, sampling only branch *contexts* (not tool receipts), judged B₂'s reasoning superior and emitted `merge(B₂); rollback(B₁, B₃)`. The orchestrator executed the rollback faithfully: B₁'s checkpoint was discarded, its context dropped, its ledger entry marked `rolled_back`. But B₁'s `refund()` had already settled at the gateway. The customer received both the gateway refund and the store credit. The orchestrator's committed history recorded exactly one refund. The reconciliation job — which trusts the ledger — never flagged the discrepancy because from its perspective the books balanced. The trigger condition is precise: **an optimistic tool call with an external, non-idempotent, non-compensable side effect completes inside a branch that the merge protocol later rolls back.** Two preconditions must both hold: (a) the tool call commits before consensus, and (b) the merge decision selects a different branch. Neither the tool layer nor the merge layer individually detects this; the defect lives in the seam. The failure trace: 1. `fork(B₁,B₂,B₃)` → each branch receives a copy-on-write context and a *provisional* ledger namespace. 2. B₁ issues `refund()` → tool returns `200 OK` with a gateway transaction id. The orchestrator records the receipt in B₁'s provisional ledger but does **not** promote it to the committed ledger, because B₁ is unmerged. 3. Auditor returns `rollback(B₁)`. Orchestrator discards B₁'s provisional ledger — *including the receipt* — and drops the checkpoint. 4. The gateway transaction id is now unreferenced. No committed record exists. The side effect is orphaned but real. The critical mechanical detail: the receipt was stored *inside the thing that got rolled back*. Rollback of a branch is defined as discarding its state, and the proof of external commitment was part of that state. This is the non-obvious part — the orchestrator did not lose the receipt through a bug; it lost it *by design*, because the receipt was correctly scoped to the branch that owned the call. ## Condition of Validity Rollback-as-reversal is only valid under one of three conditions, and the orchestrator must be able to *prove* which holds at merge time: 1. **The tool is idempotent and reversible** (e.g., `credit()` with a deduplication key). Reversal is a compensating call, not a state discard. 2. **The tool call has not yet committed.** The optimistic call is still in-flight or gated behind a two-phase commit; rollback cancels it. 3. **The tool is read-only.** No external effect to reverse. If none of these holds, the branch is *non-rollbackable* and the merge protocol must treat it as such — it may be *merged* but never *rolled back*, and the auditor must be denied the option to select against it after its call commits. The invariant is: **a branch that has committed an irreversible optimistic call must be promoted to a "sticky" state that the merge protocol can only accept, never discard.** Consensus must be re-scoped to exclude sticky branches, or the orchestrator must block on the sticky branch's outcome before forking competitors. The condition of validity for the *entire* branch-and-merge pattern is therefore: the set of branches eligible for rollback must be exactly the set of branches with no committed irreversible effects, and this set must be recomputed at every consensus round — not at fork time. ## Decision Boundary At the moment the auditor returns a verdict, the orchestrator sits on a decision boundary. The wrong decision — rolling back a sticky branch — is silent and unrecoverable. The correct decision requires a check that is cheap but easy to omit: - **If the target branch is sticky** (has ≥1 committed irreversible receipt): do not roll back. Either (a) merge it and reconcile the redundant effect via compensation, or (b) halt and escalate to a reconciler that can issue the compensating call using the receipt. The receipt must have been *escrowed* outside the branch's discardable state. - **If the target branch is clean**: roll back normally. The escrow is the load-bearing architectural element. Receipts for irreversible calls must be written to a durable, branch-independent ledger *at call time*, not at merge time, and must survive branch rollback. The branch's provisional state may reference the receipt, but the receipt's authority must not depend on the branch's survival. Without escrow, the orchestrator cannot even *know* it is on the wrong side of the boundary — it has discarded the evidence. A second boundary: the auditor must not be allowed to sample only branch contexts when a branch is sticky. An auditor reasoning over B₁'s *reasoning* will happily prefer B₂ and never learn that B₁ already moved money. The auditor's input must include the escrowed receipt set, and its verdict schema must carry a `sticky_branches` field that the merge protocol refuses to violate. ## Operational Effect The practical consequence is that speculative execution's latency win is only real for branches whose tool calls are reversible or gated. For irreversible calls, optimism buys latency at the cost of a class of silent double-effect bugs that are invisible to ledger-based reconciliation because the ledger is the thing that lost the record. Teams typically discover this only after a customer receives two refunds and the books show one. The guardrail is a three-part contract enforced at the tool boundary: 1. **Classify** each tool call as `reversible`, `gated`, or `irreversible` at schema-registration time. Irreversible calls require an idempotency key or are refused in speculative mode. 2. **Escrow** the receipt for every committed irreversible call into a branch-independent durable store before returning control to the branch. 3. **Freeze** the branch as sticky and surface its escrowed receipts to the auditor; the merge protocol must reject any rollback targeting a sticky branch and route to compensation instead. The invariant to encode: *a branch may only be rolled back if the set of its committed external effects is empty.* The orchestrator must be able to answer that question at consensus time from escrowed evidence, not from the branch's own state. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class ToolClass(Enum): REVERSIBLE = "reversible" GATED = "gated" IRREVERSIBLE = "irreversible" class StickyRollbackError(RuntimeError): """Raised when a merge protocol attempts to roll back a branch that has committed an irreversible external side effect.""" @dataclass class Receipt: branch_id: str tool_name: str external_id: str idempotency_key: Optional[str] @dataclass class Branch: branch_id: str tool_class: ToolClass committed_receipts: list[Receipt] = field(default_factory=list) @property def is_sticky(self) -> bool: return any(r.idempotency_key is None for r in self.committed_receipts) class SpeculativeOrchestrator: def __init__(self) -> None: # Escrow lives OUTSIDE any branch and survives rollback. self.escrow: list[Receipt] = [] def commit_optimistic_call( self, branch: Branch, tool_name: str, external_id: str, idempotency_key: Optional[str], ) -> Receipt: if branch.tool_class is ToolClass.IRREVERSIBLE and idempotency_key is None: # Allowed only because we escrow; otherwise this is the bug. pass receipt = Receipt(branch.branch_id, tool_name, external_id, idempotency_key) self.escrow.append(receipt) # durable, branch-independent branch.committed_receipts.append(receipt) return receipt def rollback(self, branch: Branch) -> None: if branch.is_sticky: receipts = [r for r in self.escrow if r.branch_id == branch.branch_id] raise StickyRollbackError( f"branch {branch.branch_id} has committed irreversible effects " f"{[r.external_id for r in receipts]}; rollback would orphan them. " f"Route to compensation or halt." ) branch.committed_receipts.clear() def merge(self, winner: Branch, losers: list[Branch]) -> None: for loser in losers: self.rollback(loser) # will raise if any loser is sticky def reconcile(orchestrator: SpeculativeOrchestrator, winner: Branch, losers: list[Branch]) -> None: try: orchestrator.merge(winner, losers) except StickyRollbackError as exc: # Escalated: escrow still holds the receipts, so compensation is possible. raise StickyRollbackError( f"merge aborted; compensating required: {exc}" ) from exc ```