# In what scenarios must an instance abort an optimistic tool-call commit when a parallel speculative branch rolls back across a shared side-effect ledger **Date of Record:** 2026 November 20 **Scope:** Applies to multi-agent orchestrators that fan out speculative branches in parallel, each branch optimistically committing tool calls (writes, sends, deletes) against a shared external system, with rollback of losing branches and post-hoc conflict resolution. Does not apply to branches that stage all side effects in a private buffer and commit atomically at merge time, nor to read-only speculative fan-out. ## Core Distinction There are two structurally different notions of "rollback" in a speculative multi-agent system, and conflating them is the source of the failure this record documents. - **State rollback** is local: the branch's private working memory, scratchpad, and pending-message queue are discarded. This is cheap, deterministic, and always safe. - **Side-effect rollback** is external: a tool call already dispatched to a real system (a database write, an outbound email, a payment, a file mutation) must be *compensated* because the branch that issued it lost the arbitration. The invariant that optimistic commit protocols silently assume is that **side-effect rollback is total and ordered**: every committed tool call has a compensating action, and compensations execute in reverse causal order relative to the commits they undo. When branches run in parallel against a shared ledger, this assumption fails not because compensation is missing but because *compensation is interleaved with other branches' commits*. A losing branch's compensation can land on top of a winning branch's commit and destroy it, or it can be skipped entirely because the ledger's version check no longer matches the version the compensation was computed against. The instance must abort the commit — not merely roll back — when the compensation's precondition has been invalidated by a concurrent winner. ## What Was Observed An orchestrator spawned three speculative branches (B1, B2, B3) from a common checkpoint to answer a single user request that required mutating a shared `orders` table and emitting a notification. Each branch was granted an optimistic commit lease: it could dispatch tool calls immediately, tagging each with a `(branch_id, base_version, intent_hash)` tuple, on the promise that losers would be compensated. The trace: 1. All three branches read `orders` at `base_version=41`. B1 and B2 both decide to `UPDATE orders SET status='shipped' WHERE id=7`. B3 decides to `UPDATE orders SET status='cancelled' WHERE id=7` and additionally emits `notify(customer, "cancelled")`. 2. B1 commits first, ledger advances to `v42`. B3 commits second, ledger advances to `v43` (status now `cancelled`), and the notification fires. B2 commits third — its optimistic lease was validated against `base_version=41`, which the ledger still accepts because the ledger's optimistic check is `commit_version >= base_version`, a monotone predicate. Ledger advances to `v44` (status back to `shipped`). 3. Arbitration selects B1 as the winner (highest confidence score). B2 and B3 are ordered to roll back. 4. B2's compensation is `UPDATE orders SET status='' WHERE id=7 AND version=44`. It reads `prior` from its own snapshot — which was `v41`'s value, `pending`. It writes `pending` at `v45`. 5. B3's compensation is `UPDATE orders SET status='' WHERE id=7 AND version=43`. **The version guard fails** — the ledger is at `v45`, not `v43`. The compensation is a no-op. B3's notification is *not* recalled (it was fire-and-forget). The customer was told the order was cancelled; the ledger now says `pending`; the winning branch B1 believed it had set `shipped`. The terminal state is a three-way inconsistency: the winner's intent (`shipped`) is not reflected, a loser's irreversible side effect (the notification) persists, and a second loser's compensation clobbered the winner's write. No single branch is at fault. The failure is in the *protocol*: optimistic commit with version-guarded compensation is not closed under concurrent interleaving. A second observed instance failed differently but for the same root cause. A branch's compensation carried an `intent_hash` that the ledger used to detect "this compensation targets a commit that has since been superseded." The hash matched, the compensation executed, but the superseding commit had been issued by the *winner* with a semantically identical intent. The compensation could not distinguish "undo my write" from "undo the write that happens to look like mine." It undid the winner's work. ## Condition of Validity The abort obligation is triggered precisely when **all three** of the following hold: 1. **Shared mutable target.** Two or more branches hold optimistic leases against the same logical resource, and at least one issued a non-idempotent or irreversible side effect (notification, payment, external API mutation without a recall path). 2. **Interleaved commits.** The commit order across branches is not the arbitration order — i.e., a branch that will lose may commit after a branch that will win, or a compensation may execute after a superseding commit. 3. **Version-guarded or hash-guarded compensation.** The compensation's correctness depends on a precondition (`version == v`, `intent_hash == h`) that concurrent commits can invalidate, rather than on an unconditional inverse derived from a serialized log. If (1) fails — targets are disjoint or all side effects are buffered — rollback is safe and no abort is needed. If (2) fails — commits are serialized through a single sequencer before arbitration — compensation ordering is total and the protocol is sound. If (3) fails — compensation is derived from an append-only operation log replayed in reverse — the guard cannot be invalidated and the abort is unnecessary (though the log must be the sole source of truth). The dangerous case is the *near-miss*: a system that serializes commits (satisfying not-(2)) but whose compensations are computed from branch-local snapshots rather than the serialized log. It passes casual testing because commits are ordered, then fails the first time a compensation's snapshot diverges from the log tail. This is the boundary the instance must recognize. ## Decision Boundary The instance must transition from **optimistic-commit** to **abort-and-escalate** — not to compensate, not to retry — when the following predicate evaluates true at compensation time: ``` compensation.precondition_version != ledger.current_version AND compensation.target ∈ {resources touched by any commit with version > compensation.precondition_version} AND NOT exists(recall_path for any irreversible side effect issued by the rolling-back branch) ``` The distinction between *compensate* and *abort* is the crux: - **Compensate** is valid only when the compensation's precondition still holds *and* the winning branch's post-arbitration commit has not yet been applied (or is applied after all compensations drain). The correct architecture is: arbitration first, then a *quiesce* barrier that halts all branch commits, then compensations in reverse commit order, then the winner's commit. Under this ordering, compensation preconditions cannot be invalidated. - **Abort** is mandatory when the quiesce barrier is absent or was violated — i.e., a commit landed after arbitration began. In that case the ledger is in a state no branch's snapshot describes, and no compensation computed from a snapshot is trustworthy. The instance must mark the resource `POISONED`, refuse further optimistic leases against it, and hand the resource to a serialized repair path that reads the append-only log (if one exists) or escalates to human/operator resolution. The abort must be *resource-scoped*, not branch-scoped. Aborting only the losing branch leaves the winner's commit stranded on a poisoned ledger. Aborting the whole request is over-broad if other resources are untouched. The correct granularity is the set of resources reachable from the poisoned commit's write set. ## Operational Effect After the abort, three things must be true, and the instance should verify each before resuming: 1. **No further optimistic leases** are granted against poisoned resources until the repair path clears the `POISONED` flag. This prevents compounding — a fourth branch committing onto a poisoned ledger is unrecoverable. 2. **Irreversible side effects are enumerated and surfaced**, not silently accepted. The notification in the trace above cannot be recalled; the instance must emit a reconciliation record naming the customer, the message, and the fact that it contradicts terminal state, so downstream systems can issue a correcting message. Treating an irreversible side effect as "rolled back" because its branch lost is the single most common latent bug in these systems. 3. **The winner's intent is re-derived from the log, not from the branch's memory.** The branch that won may itself have a stale view; its intent must be replayed against the repaired ledger to confirm it is still applicable. If the repair path cannot reconstruct a consistent state, the request fails closed with an explicit `UnreconcilableLedger` outcome rather than a best-effort write. The measurable operational signature of this failure mode is a divergence between `ledger.version` and the maximum `commit_version` any live branch believes it holds, combined with at least one compensation whose `precondition_version < ledger.version` at execution time. Monitoring this pair — not commit success rate, not branch error rate — is what detects the boundary before it produces a three-way inconsistency. ```python from dataclasses import dataclass from typing import Optional class UnreconcilableLedger(RuntimeError): """Raised when a compensation's precondition was invalidated by a concurrent commit.""" pass @dataclass(frozen=True) class Compensation: branch_id: str target_resource: str precondition_version: int intent_hash: str has_recall_path: bool # False for fire-and-forget side effects @dataclass(frozen=True) class LedgerState: resource: str current_version: int poisoned: bool def execute_compensation(comp: Compensation, ledger: LedgerState) -> None: """Apply a losing branch's compensation, or abort if the precondition is stale. The precondition check is necessary but NOT sufficient: a matching version can still mask a superseding commit with an identical intent_hash. The caller must have already drained the quiesce barrier before invoking this. """ if ledger.poisoned: raise UnreconcilableLedger( f"resource {ledger.resource} is poisoned; " f"branch {comp.branch_id} cannot compensate" ) if comp.precondition_version != ledger.current_version: # A concurrent commit advanced the ledger past this compensation's # snapshot. The compensation was computed against a state that no # longer exists; executing it would clobber an intervening write. if not comp.has_recall_path: raise UnreconcilableLedger( f"stale compensation for {comp.target_resource} at " f"v{comp.precondition_version} (ledger v{ledger.current_version}) " f"with irreversible side effect and no recall path; " f"abort and escalate to serialized repair" ) raise UnreconcilableLedger( f"stale compensation for {comp.target_resource} at " f"v{comp.precondition_version} (ledger v{ledger.current_version}); " f"quiesce barrier was violated" ) # Precondition holds: safe to apply the inverse. _apply_inverse(comp) def _apply_inverse(comp: Compensation) -> None: # Placeholder for the actual inverse operation against the ledger. ... ```