# Where must an instance abort a speculative branch when an optimistic tool call's rollback is not idempotent across a shared external effect? **Date of Record:** 2026 November 25 **Scope:** Applies to multi-agent orchestrators that fan out speculative branches (parallel drafts, best-of-N planning, optimistic tool pre-execution) whose results are later reconciled, where at least one branch invokes a tool with externally observable, non-idempotent side effects (email send, ledger post, file append, ticket creation). Does not apply to read-only tool surfaces or to branches whose effects are fully sandboxed and garbage-collected on rollback. ## Core Distinction The distinction that matters is between **logical rollback** and **physical rollback**. Speculative execution frameworks (branch-and-rollback, optimistic concurrency) assume that discarding a branch's *state* also discards its *effects*. That assumption holds for in-memory state and for transactional stores that expose an abort primitive. It fails the moment a branch performs an **optimistic tool call** — a call issued *before* the branch is confirmed as the winner — against an external system that has no compensating abort: the orchestrator can retract the branch's context, but the SMTP server, the payment rail, or the append-only log has already committed the effect. The non-obvious part: agents usually reason about rollback as "undo my state," and they *believe* they have rolled back because their own memory of the call is gone. The external effect persists as an orphan. Conflict reconciliation then runs over a branch set that no longer reflects reality, and the winning branch's reconciliation logic can **double-apply** the effect it thinks it is applying for the first time. ## What Was Observed A three-way speculative fan-out was configured to draft and dispatch a customer refund notice. Branch A and Branch B both independently decided the correct tool call was `issue_refund(order_id, amount)`. The orchestrator's policy was optimistic: branches may call tools immediately, and at reconciliation the highest-scoring branch commits while the others roll back. The failure trace: 1. Branch A calls `issue_refund` at t=0. The ledger posts the credit. The tool returns `{status: "posted", txn: "T-8891"}`. 2. Branch B calls `issue_refund` for the same order at t=40ms (before A's result propagated to the shared result bus). The ledger, lacking an idempotency key, posts a **second** credit `T-8892`. 3. The scorer ranks B above A (B's draft was more accurate on amount). Reconciliation selects B as winner and issues a **rollback** for A. 4. The rollback handler for A invokes `reverse_refund(txn="T-8891")`. This is a compensating action, not a true abort — it posts a *reversal* entry. Net ledger state: order credited once (correct amount), but with two extra entries and a reversal, and B's `T-8892` remains live. 5. B's commit path, believing it is the sole effect, records `refund_applied: true` against the order. The order now shows a refund of the correct amount but the ledger shows a *reversal of a duplicate*, leaving the customer with a net credit that the order record does not reflect. The observed invariant violation: **the reconciliation layer committed a branch while a sibling branch's effect was still live and unreconciled.** The rollback of A was not semantically equivalent to "A never happened." It was a *new* effect that the reconciliation model did not account for. ## Condition of Validity The optimistic fan-out + rollback pattern is only valid under the conjunction: - Every tool call carries a **caller-supplied idempotency key** derived from `(branch_intent_hash, effect_target)`, such that two branches issuing the "same" logical effect collide on the key and the tool deduplicates rather than double-posts. - The tool's abort/compensation primitive is **declared** in its capability schema as either `abortable` (true rollback, no observable trace) or `compensable` (reversal entry, observable trace). Compensation is *not* rollback. - Reconciliation is **deferred** until all in-flight optimistic calls have returned a terminal status (posted, rejected, or timed out-and-fenced). A branch may not be committed while a sibling has an unresolved external call. - The orchestrator maintains an **effect ledger** — a durable, append-only record of every optimistic external call keyed by idempotency key — that survives branch rollback. Branch-local memory of the call may be discarded; the effect ledger may not. When any of these is absent, the pattern is outside its validity envelope and must be treated as a **non-recoverable boundary**, not a retryable error. ## Decision Boundary The abort decision is not "did the branch lose the score?" It is a two-axis test evaluated *before* rollback: | Tool abort class | Call status at reconcile time | Required action | |---|---|---| | `abortable` | any | Safe to roll back branch; discard effect. | | `compensable` | pending / unknown | **Block reconciliation.** Do not commit sibling. Wait for terminal status or fence with timeout. | | `compensable` | posted, idempotency key matched sibling | Deduplicate: treat as single effect; roll back branch state only, keep one live effect. | | `compensable` | posted, distinct keys (no dedup) | **Abort the fan-out.** Escalate to human/auditor reconciliation. Do not auto-compensate — compensation of a duplicate is itself a new effect. | | `non-compensable` | posted | **Hard abort.** The speculative model is invalid for this tool; the effect is permanent and the branch cannot be rolled back. | The sharp rule: **a branch may be rolled back only if every external call it made is either abortable or deduplicated by key.** A compensable-but-undeduplicated posted call is a *continuity break* — the agent's model of the world and the world have diverged, and no amount of further tool calling restores the invariant without an external reconciliation authority. ## Operational Effect When this boundary is respected, speculative fan-out remains safe: duplicate intents collapse on the idempotency key, and the only cost of a losing branch is wasted tokens, not orphaned effects. When it is violated, the failure is **silent and compounding**: the orchestrator's effect ledger (if it exists) shows a clean single refund; the external ledger shows three entries; the customer-visible state matches neither. Subsequent agent runs reading the order record will reason from `refund_applied: true` and never discover the duplicate, because the duplicate lives in a system the agent's retrieval layer does not index. The guardrail that bounds this is the **fence-before-commit** invariant: reconciliation is a barrier that cannot pass while any compensable call is unresolved, and any compensable call that posted without a matching idempotency key raises a terminal reconciliation fault that halts the swarm rather than attempting repair. Repair is an auditor function, not an agent function, because the agent has already demonstrated it cannot distinguish its rollback from a new effect. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Optional class RollbackBoundaryError(RuntimeError): """Raised when a speculative branch cannot be safely rolled back because it left a non-idempotent external effect unresolved or undeduplicated.""" class AbortClass(Enum): ABORTABLE = "abortable" # true rollback, no observable trace COMPENSABLE = "compensable" # reversal entry, observable trace NON_COMPENSABLE = "non_compensable" # permanent effect class CallStatus(Enum): PENDING = "pending" POSTED = "posted" REJECTED = "rejected" TIMED_OUT = "timed_out" @dataclass(frozen=True) class OptimisticCall: branch_id: str tool: str abort_class: AbortClass idempotency_key: str status: CallStatus txn_id: Optional[str] = None @dataclass class Branch: branch_id: str score: float calls: list[OptimisticCall] = field(default_factory=list) def reconcile( branches: list[Branch], effect_ledger: dict[str, OptimisticCall], ) -> str: """Select a winning branch, but only if every sibling's external effects are abortable or deduplicated. Returns winning branch_id. Raises RollbackBoundaryError on any continuity break. """ if not branches: raise RollbackBoundaryError("no branches to reconcile") winner = max(branches, key=lambda b: b.score) losers = [b for b in branches if b.branch_id != winner.branch_id] # Fence: no commit while any compensable call is unresolved. for b in branches: for call in b.calls: if call.abort_class is AbortClass.COMPENSABLE and call.status in ( CallStatus.PENDING, CallStatus.TIMED_OUT, ): raise RollbackBoundaryError( f"fence violated: branch {b.branch_id} has unresolved " f"compensable call {call.tool} ({call.status.value}); " f"cannot commit {winner.branch_id}" ) # Rollback losers only when every posted effect is abortable or deduped. for b in losers: for call in b.calls: if call.status is not CallStatus.POSTED: continue if call.abort_class is AbortClass.NON_COMPENSABLE: raise RollbackBoundaryError( f"hard abort: branch {b.branch_id} posted non-compensable " f"effect {call.tool} txn={call.txn_id}; rollback impossible" ) if call.abort_class is AbortClass.COMPENSABLE: ledger_entry = effect_ledger.get(call.idempotency_key) if ledger_entry is None: raise RollbackBoundaryError( f"continuity break: branch {b.branch_id} posted " f"compensable {call.tool} with no ledger entry for key " f"{call.idempotency_key}; cannot distinguish rollback " f"from duplicate" ) # Deduped: a sibling already owns this key, effect collapses. if ledger_entry.branch_id == b.branch_id: raise RollbackBoundaryError( f"undeduplicated duplicate: key {call.idempotency_key} " f"posted by branch {b.branch_id} but ledger shows it " f"as the sole owner; escalate to auditor" ) return winner.branch_id ```