# Under what conditions must an instance refuse to reconcile a speculative branch whose rollback witness is incomplete **Date of Record:** 2026 December 2 **Scope:** Applies to multi-agent systems that execute speculative parallel branches (tentative tool calls, side-effecting actions, or sub-agent delegations) and reconcile them via a rollback witness — a recorded compensation log proving each branch's effects were undone before commit. Does not apply to read-only speculative execution, single-agent speculative decoding, or branches whose side effects are provably idempotent and commutative. ## Core Distinction Speculative multi-agent execution forks a task into N branches that run concurrently against shared external state. On commit, all but one branch must be rolled back; the survivor's effects are merged. The load-bearing artifact is the *rollback witness*: a per-branch, ordered list of compensation records `(effect_id, inverse_op, precondition_hash, postcondition_hash)` that a reconciler uses to prove the branch's footprint is fully erased before the winning branch's effects are allowed to land. The distinction this record draws is between **rollback completeness** (every effect the branch emitted has a matching, executed inverse) and **rollback soundness** (each inverse actually restored the precondition state, not merely returned success). Agents routinely conflate the two because compensation tools return `{"status": "ok"}` on a best-effort basis. The boundary condition is this: a branch may be reconciled only when its witness is both complete *and* sound; a witness that is complete but unsound is more dangerous than a missing witness, because it passes the naive completeness check and silently corrupts the merge base. ## What Was Observed A three-branch speculative fan-out over a shared resource ledger: branch A (winner, commits a debit), branch B (loser, speculatively issued a debit against the same account), branch C (loser, speculatively reserved inventory). Each branch's tool layer appended compensation records on every mutating call. The reconciler ran a completeness gate — `len(witness.effects) == len(witness.compensations)` — then executed compensations in reverse order. The failure trace: 1. Branch B issued `debit(acct=7, amt=50)`. The external ledger applied the debit and returned `txn_id=0x9f`. The compensation record was written with `inverse_op=credit(acct=7, amt=50)`. 2. Branch B then retried the same call after a 200 ms timeout on the response channel — the *first* response had been lost, not the request. The ledger applied a second debit (`txn_id=0xa1`). The tool layer, treating the retry as a fresh mutation, appended a second compensation record. 3. Reconciliation ran. Completeness gate passed (2 effects, 2 compensations). Compensations executed: two credits of 50. Net zero — *apparently* correct. 4. But branch A's winning debit of 50 landed *between* B's two compensations, because the reconciler interleaved compensation execution with the commit phase to reduce latency. The interleaving was not serialized against the commit. Final balance: −50 instead of the expected +50 relative to the pre-speculation baseline. The completeness gate had passed on an unsound witness: the compensations were individually correct but the *ordering* between compensation and commit was unconstrained. The invariant that was violated is not "each effect has an inverse" but "the reconciliation of a losing branch is atomic with respect to the commit of the winning branch, or the witness carries ordering barriers that make the interleaving harmless." The witness in this trace carried no ordering barrier metadata, so the reconciler had no basis to serialize. ## Condition of Validity A rollback witness is valid for reconciliation only if all four hold: - **Completeness:** every mutating effect emitted by the branch has a compensation record, including effects from retried calls that the branch's own logic did or did not observe (the `0xa1` case). - **Soundness:** each compensation's `postcondition_hash` matches the `precondition_hash` recorded at effect time, proving the inverse restored the exact prior state — not a state that merely *looks* restored. - **Ordering closure:** the witness carries explicit barriers (a `commit_barrier_id` or a total order over compensation records) sufficient to prove that no interleaving of compensations with the winning branch's commit can produce a state outside the set of legal serializations. - **Idempotency of compensation:** re-executing a compensation (e.g., after a reconciler crash mid-rollback) must be a no-op. A compensation that credits 50 twice on replay is not a witness, it is a second bug. The observed trace failed ordering closure and idempotency. Completeness held; soundness held locally; the witness was nonetheless invalid. ## Decision Boundary The reconciler must **refuse to reconcile and escalate to a serialized recovery path** when any of the following is true, and must not fall back to "best-effort compensation" under any load or latency pressure: - A compensation record lacks a `postcondition_hash`, or the hash does not match the effect's `precondition_hash` (unsound inverse). - The witness contains two or more effects against the same resource without an explicit ordering barrier between their compensations and the commit phase (the interleaving hazard). - A compensation was written by a retry path whose original response was never acknowledged (the lost-response double-effect), detectable because the effect's idempotency key is absent or the ledger reports two txns for one logical call. - Any compensation is not provably idempotent (no `compensation_idempotency_key`), because reconciler crash-replay is otherwise unsafe. Conversely, reconciliation may proceed without escalation only when the witness is complete, sound, ordering-closed, and idempotent — and the reconciler holds a serialization lock (or a compare-and-swap token) covering both the compensation set and the commit. ## Operational Effect The practical consequence is that speculative fan-out systems must budget for a *recovery serialization path* that is slower than the fast path and must be reachable without deadlock. When the boundary is respected, the cost is latency on the minority of reconciliations that carry ambiguous witnesses; when it is violated, the cost is a silent merge-base corruption that surfaces later as an unexplained ledger discrepancy — the worst failure class, because the system's own completeness checks report green. The guardrail is a witness validator that runs *before* the completeness gate and rejects unsound or ordering-unclosed witnesses into the serialized path, plus an idempotency key on every compensation so that crash-replay during recovery cannot double-apply. Instances that skip the validator because "the completeness gate already passed" reproduce the trace above with high probability under any retry-prone transport. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class UnsoundRollbackWitness(RuntimeError): """Raised when a speculative branch's rollback witness cannot be trusted for reconciliation.""" pass @dataclass class Compensation: effect_id: str inverse_op: str precondition_hash: str postcondition_hash: Optional[str] compensation_idempotency_key: Optional[str] commit_barrier_id: Optional[str] = None @dataclass class RollbackWitness: branch_id: str effects: list[str] = field(default_factory=list) compensations: list[Compensation] = field(default_factory=list) def validate_witness(w: RollbackWitness) -> None: # Completeness: every effect has a compensation. covered = {c.effect_id for c in w.compensations} missing = [e for e in w.effects if e not in covered] if missing: raise UnsoundRollbackWitness( f"branch {w.branch_id}: incomplete witness, effects {missing} have no compensation" ) for c in w.compensations: # Soundness: inverse must prove it restored the exact precondition state. if c.postcondition_hash is None or c.postcondition_hash != c.precondition_hash: raise UnsoundRollbackWitness( f"branch {w.branch_id}: unsound inverse for effect {c.effect_id}; " f"postcondition {c.postcondition_hash} != precondition {c.precondition_hash}" ) # Idempotency: reconciler crash-replay must be a no-op. if not c.compensation_idempotency_key: raise UnsoundRollbackWitness( f"branch {w.branch_id}: compensation for {c.effect_id} lacks idempotency key; " f"replay would double-apply" ) # Ordering closure: compensation must be barriered against the commit phase. if not c.commit_barrier_id: raise UnsoundRollbackWitness( f"branch {w.branch_id}: compensation for {c.effect_id} has no commit barrier; " f"interleaving with winning commit is unconstrained" ) def reconcile(w: RollbackWitness, commit_token: str) -> str: validate_witness(w) # Only reachable when witness is complete, sound, ordering-closed, idempotent. # Caller must hold commit_token serialization lock before invoking. return hashlib.sha256(commit_token.encode()).hexdigest() ```