# Why does an instance commit an optimistic tool-call branch it can no longer reconcile after a speculative peer rollback? **Date of Record:** 2026 November 23 **Scope:** Applies to multi-agent systems that run speculative execution branches in parallel (draft-and-verify, optimistic fan-out, or speculative tool-call pipelining) and reconcile branches via a shared commit log or effect ledger. Does not apply to strictly serialized single-agent execution or to systems where every tool call is gated by a synchronous two-phase commit before any side effect is emitted. ## Core Distinction The failure is not a race on the *write* to shared state. It is a race on the *evidence that a branch was ever valid*. In speculative multi-agent execution, agent A emits a tool call optimistically (e.g., `charge_card`, `send_email`, `delete_row`) and records a speculative intent in a branch ledger, while a peer agent B independently speculates on a competing branch. A reconciler later picks a winner. The invariant most teams assume is: *"if my branch loses, my speculative effects are rolled back."* The real invariant that matters is subtler: **a branch can only be rolled back if the rollback token (the pre-image / undo handle) captured at speculation time is still authoritative at reconciliation time.** When a peer's rollback mutates the same underlying resource, the losing branch's pre-image is no longer the state it speculatively observed, and rollback becomes a *forward-write* disguised as an undo — silently committing a change nobody voted for. This is a continuity-of-evidence failure, not a concurrency lock failure. Adding locks does not fix it; the branches legitimately ran in parallel and the ledger is append-only. What breaks is the *semantic identity* of the pre-image across the rollback. ## What Was Observed A three-agent planner/executor/auditor swarm ran a refund workflow. Executor E1 speculatively called `issue_refund(order=4471, amount=120)` and captured pre-image `balance=1000, status=PAID`. In parallel, executor E2 (a redundant branch spawned for latency) speculatively called `adjust_balance(order=4471, delta=-20)` and captured the same pre-image `balance=1000`. The auditor rejected E1's branch (policy: refunds over $100 require human approval) and the reconciler rolled E1 back by replaying the inverse of its delta: `balance += 120` against the *current* balance. But E2's branch had already committed optimistically between E1's capture and E1's rollback. Sequence as it appeared in the ledger: 1. `t1` E1 captures pre-image `balance=1000`, speculates `-120` → intent. 2. `t2` E2 captures pre-image `balance=1000`, speculates `-20`, commits optimistically → `balance=980`. 3. `t3` auditor rejects E1. 4. `t4` reconciler executes E1 rollback `balance += 120` → `balance=1100`. Final balance is 1100: E2's legitimate `-20` was erased by a naive additive inverse, and E1's rejected refund effectively *created* 100 units of balance. The rollback "succeeded" (no exception, ledger marked E1 as ROLLED_BACK) while corrupting the resource. The failure surfaced only three steps later when a downstream solvency check diverged from the payment processor's authoritative ledger. The non-obvious part: the reconciler's rollback was *internally consistent*. It used the correct pre-image for E1's branch. It failed because the pre-image was no longer the *state of the resource* — it was a stale snapshot from before a peer's optimistic commit. The branch ledger tracked intents, not resource versions. ## Condition of Validity The naive additive-inverse rollback is valid **only if** no other branch mutated the same resource between pre-image capture and rollback. Formally, rollback `R(b)` is sound iff `version(resource) at capture(b) == version(resource) at R(b)`. Speculative fan-out violates this by construction whenever two branches touch a shared resource. The guardrail is a **versioned pre-image with compare-and-swap rollback**: each speculative intent stores `(pre_image, resource_version)`, and rollback is only permitted if the resource's current version still equals the captured version. If versions diverged, the branch cannot be rolled back by inverse — it must be **compensated** by a forward transaction that references the peer's committed effect, or escalated to the reconciler as `UNRECONCILABLE`. The invariant to enforce: *a speculative effect is only invertible while its captured version is the resource's live version; otherwise inversion is a new write and requires its own authorization.* A second invariant: the reconciler must never mark a branch `ROLLED_BACK` on the basis of having executed an inverse. It must mark `ROLLED_BACK` only when the post-rollback version equals the pre-image version *and* no intervening commits were observed. Otherwise the correct terminal state is `COMPENSATED` or `ESCALATED`, both of which are audit-visible. ## Decision Boundary The boundary is whether the resource exposes a monotonic version (or a content hash / ETag) that is captured atomically with the pre-image. If it does, the reconciler can detect divergence and refuse inverse rollback. If it does not — common with third-party tool calls that return only a success boolean — the system has no way to distinguish "my rollback restored the state" from "my rollback layered on top of a peer's commit." In that regime, **optimistic commit must be disabled for that tool** and replaced by a pessimistic reservation (hold the resource version before the speculative call). The decision rule: - Resource is versioned AND tool is idempotent-with-version → optimistic commit + CAS rollback is safe. - Resource is versioned but tool is non-idempotent → optimistic commit allowed, rollback must be compensation-only, never inverse. - Resource is unversioned → optimistic commit forbidden; serialize or reserve. The trap is the middle case, where teams assume versioning alone makes inverse rollback safe. It does not; idempotency of the *tool* is a separate axis from versioning of the *resource*, and the failure above lives exactly in that gap. ## Operational Effect Without the versioned pre-image and CAS guard, speculative fan-out silently converts rejected branches into phantom writes. The blast radius is bounded only by how long reconciliation is delayed relative to peer commits: the longer the auditor takes, the more peer commits land between capture and rollback, and the more the additive inverse drifts. In production this manifests as slow, monotonic divergence between the agent's effect ledger and the authoritative system — never a crash, never an exception, just a solvency or inventory check that fails hours later with no obvious causal trace back to the reconciliation step. The operational fix is to make rollback a *conditional* operation that can fail loudly. A rollback that cannot prove its pre-image is still live must raise, escalate, and leave the branch in `UNRECONCILABLE` rather than executing a best-effort inverse. The cost is more escalations during high-contention fan-out; the benefit is that every committed effect is either authorized or explicitly flagged, and no rejected branch can mutate a resource a peer already owns. ```python class UnreconcilableSpeculativeBranch(RuntimeError): """Raised when a speculative branch cannot be safely rolled back because a peer commit mutated the resource after the pre-image was captured.""" pass def rollback_speculative_branch(intent, resource_store): """ intent: {branch_id, pre_image, captured_version, delta} Refuses inverse rollback if the resource version has moved since capture. """ current = resource_store.read(intent["resource_id"]) if current["version"] != intent["captured_version"]: # A peer committed between our capture and this rollback. The additive # inverse would layer on top of that commit and silently corrupt state. raise UnreconcilableSpeculativeBranch( f"branch {intent['branch_id']} captured version " f"{intent['captured_version']} but resource is now at " f"{current['version']}; inverse rollback would be a forward write. " f"Escalating to compensation." ) # Safe: version matches, inverse restores exactly the captured pre-image. restored = resource_store.apply_delta( intent["resource_id"], -intent["delta"], expected_version=current["version"] ) if restored["version"] != intent["captured_version"] + 1: raise UnreconcilableSpeculativeBranch( f"CAS rollback for {intent['branch_id']} produced unexpected " f"version {restored['version']}" ) return {"branch_id": intent["branch_id"], "state": "ROLLED_BACK"} ```