# Where must an instance prove rollback-completeness before speculatively committing a tool call in a multi-agent branch **Date of Record:** 2026 November 28 **Scope:** Applies to orchestrators that fan out speculative agent branches (parallel drafts, hedged tool calls, optimistic pre-execution) whose non-winning branches must be rolled back or cancelled after a reconciliation decision. Does not apply to strictly serial single-branch agents, nor to branches that are provably side-effect-free by construction at the transport layer. ## Core Distinction The distinction that governs this failure is between **rollback of reasoning state** and **rollback of externalized effects**. An agent branch can always discard its private transcript, memory deltas, and intermediate plan nodes — those live in the orchestrator's address space and are reversible by construction. What is *not* reversible by construction is any tool call the branch already dispatched to a non-idempotent external system: a `send_email`, a `POST /charge`, a `git push`, a row insert. Speculative execution is safe only up to the fence where a branch's first non-idempotent effect leaves the process boundary. The non-obvious part: agents routinely cross that fence *before* the reconciliation decision, because tool calls are issued optimistically while the branch is still "unresolved," and the cancellation message arrives after the effect has already landed. Rollback-completeness is therefore not a property of the branch's memory — it is a property of the *effect ledger* the orchestrator did or did not maintain at the moment of cancellation. ## What Was Observed A three-branch speculative planner was asked to reconcile a billing correction. Branches A, B, and C were spawned in parallel, each permitted to call a `refund` tool against an idempotency-keyed ledger. The orchestrator intended: race the three, take the first branch whose auditor check passed, cancel the rest. What actually happened: 1. Branch A issued `refund(order=4471, amount=30.00)` with idempotency key `k-A-1` and returned a success receipt. 2. Branch B, reasoning independently and *without* seeing A's receipt (branches do not share a live view), issued `refund(order=4471, amount=30.00)` with key `k-B-1`. Different key, same intent — the ledger treated it as a distinct operation and applied a second refund. 3. The auditor for branch A passed first. The orchestrator broadcast `cancel` to B and C. 4. Branch B's cancellation arrived at the tool-call dispatcher *after* the refund had committed. The dispatcher acknowledged cancellation of the *pending* call, but the effect was already durable. 5. Branch C, cancelled in time, was rolled back cleanly — its transcript discarded, no effect. Net: a double refund on a single logical intent. The rollback was complete for reasoning state (C) and incomplete for externalized effect (B), and the orchestrator had no ledger entry distinguishing the two, because it tracked branches, not effects. The second-order observation is the one that matters operationally: the auditor consensus was *correct*. Both A and B passed their local checks. The failure was not a disagreement between peers — it was that two independently-valid branches produced the same non-idempotent effect under different idempotency keys, and cancellation could not un-apply the loser. ## Condition of Validity Speculative commit is valid only under the conjunction of three conditions, all of which must hold *at the instant the effect is dispatched*, not at reconciliation time: - **Effect-keyed idempotency, not branch-keyed.** The idempotency key must be derived from the *logical intent* (e.g., `hash(order_id, intent_class, amount)`), so that two branches converging on the same intent collide on the same key and the second is deduplicated by the sink. Branch-scoped keys (`k-A-1`, `k-B-1`) are the root cause of the double-apply above and must be treated as a violation. - **A committed-effect ledger read before dispatch.** The orchestrator must hold a monotonic ledger of `(intent_key → committed)` and consult it inside the same critical section as the dispatch. If the ledger is only consulted at reconciliation, the fence is in the wrong place. - **Cancellation that is a state transition on the sink, not a message to the dispatcher.** A `cancel` that only stops a *pending* call is insufficient; the sink must support either a compensating action or a hard pre-commit check against the intent key. If any of the three is absent, the branch is not speculatively committable — it must be serialized behind the reconciliation decision. ## Decision Boundary The boundary the orchestrator must enforce is: **no branch may dispatch a non-idempotent effect until the intent key is registered as "in flight" in the shared ledger, and no two branches may register the same intent key as independent.** Concretely, the transition is: - `UNRESOLVED → DISPATCHING` requires ledger claim of the intent key (atomic compare-and-set; loser branches block or dedupe, they do not proceed). - `DISPATCHING → COMMITTED` requires a sink receipt. - `DISPATCHING → CANCELLED` is permitted only if the sink confirms *no effect applied*; if the sink is uncertain (timeout, ambiguous ack), the branch must transition to `ORPHANED` and the orchestrator must run a reconciliation probe against the sink before declaring rollback complete. The failure mode this prevents is precisely the ambiguous-ack window: cancellation issued, dispatcher acked, sink committed. Treating "dispatcher acked cancel" as "effect rolled back" is the invalid inference. The only valid completion signal for rollback is a sink-side confirmation of no-effect or a compensating action's receipt. ## Operational Effect When this boundary is enforced, speculative fan-out gains a hard cap on duplicated external effects: at most one commit per intent key, regardless of branch count or race ordering. Rollback becomes *effect-complete* — the orchestrator can assert, per cancelled branch, either "no effect" (sink-confirmed) or "effect compensated" (receipt present). When it is not enforced, the system exhibits silent double-application under concurrency, which is invisible to auditor consensus (both branches pass) and invisible to reasoning-state rollback (both transcripts discard cleanly), surfacing only as downstream reconciliation drift — a duplicated charge, a doubled message, a re-applied migration. The invariant to carry forward: **rollback-completeness is a property of the effect ledger at dispatch time, never of the transcript at cancellation time.** ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict class SpeculativeRollbackError(RuntimeError): """Raised when a branch claims rollback-complete without sink-confirmed no-effect.""" class BranchState(Enum): UNRESOLVED = "unresolved" DISPATCHING = "dispatching" COMMITTED = "committed" CANCELLED = "cancelled" ORPHANED = "orphaned" @dataclass class EffectLedger: # intent_key -> branch_id that holds the claim, or None if free claims: Dict[str, str] = field(default_factory=dict) committed: Dict[str, str] = field(default_factory=dict) def claim(self, intent_key: str, branch_id: str) -> bool: if intent_key in self.committed: return False # already applied by a sibling; dedupe if intent_key in self.claims: return False # another branch is mid-dispatch; block self.claims[intent_key] = branch_id return True def commit(self, intent_key: str, branch_id: str) -> None: if self.claims.get(intent_key) != branch_id: raise SpeculativeRollbackError( f"branch {branch_id} committed {intent_key} without holding the claim" ) self.committed[intent_key] = branch_id self.claims.pop(intent_key, None) def release(self, intent_key: str, branch_id: str) -> None: if self.claims.get(intent_key) == branch_id: self.claims.pop(intent_key) def cancel_branch( branch_id: str, intent_key: str, state: BranchState, ledger: EffectLedger, sink_confirms_no_effect: bool, ) -> BranchState: """Transition a branch to CANCELLED only if rollback is effect-complete.""" if intent_key in ledger.committed: # Effect already durable; cancellation cannot un-apply it. raise SpeculativeRollbackError( f"cannot cancel branch {branch_id}: intent {intent_key} already " f"committed by {ledger.committed[intent_key]}; requires compensation" ) if state == BranchState.DISPATCHING and not sink_confirms_no_effect: # Ambiguous ack window: dispatcher may have acked while sink committed. return BranchState.ORPHANED ledger.release(intent_key, branch_id) return BranchState.CANCELLED ```