# Why does an instance lose rollback fidelity when speculative branches share a tool-effect ledger across a divergent outcome boundary **Date of Record:** 2026 November 24 **Scope:** Applies to orchestrators that fan out a plan into speculative agent branches (parallel or interleaved) where each branch may invoke side-effecting tools and the orchestrator commits one branch while rolling back the others. Does not apply to read-only fan-out (pure retrieval or classification) where no compensating action is required, nor to single-branch retry loops that never share state. ## Core Distinction Speculative multi-agent execution differs from ordinary speculative decoding in one load-bearing way: the "tokens" being speculated are *tool effects on the world*, not probability mass over a vocabulary. When a branch diverges, rollback is not a memory discard—it is a set of compensating actions that must exactly invert every committed effect the losing branch produced. The non-obvious boundary is this: **rollback fidelity is a property of the effect ledger's causal ordering, not of the branch's final answer.** An instance can correctly identify that branch B lost the race and still fail to roll it back, because the effects B emitted were interleaved with effects from the winning branch A on the same external resource, and the ledger recorded them as a flat append-only log rather than a per-resource causal chain. The invariant that must hold: *for every external resource, the sequence of effects recorded in the ledger must be a total order consistent with the real-world observation order, and every speculative effect must carry a branch tag such that the committed branch's prefix is reconstructible without the loser's writes.* When two branches touch the same resource and the ledger collapses them into one ordered stream, the loser's effects become indistinguishable from the winner's, and rollback either over-reverts (destroying winner state) or under-reverts (leaving loser residue). ## What Was Observed A planner agent decomposed a task into a plan with two candidate strategies, S1 and S2, and the orchestrator ran both speculatively against a shared workspace (a document store plus a task queue). Each branch executed a 6–9 step tool loop. S1 wrote a draft artifact and enqueued a downstream job with idempotency key `k1`. S2, executing concurrently, also wrote to the same artifact path (a refinement step) and enqueued a *different* downstream job with key `k2`. Both branches passed their local verification. The orchestrator's arbiter chose S1 on a 0.71 vs 0.64 score margin and issued rollback for S2. Three failures compounded: 1. **Ledger interleaving.** The effect ledger recorded `write(artifact, S1)`, `write(artifact, S2)`, `enqueue(k1, S1)`, `enqueue(k2, S2)` as a flat list. Rollback of S2 walked the list in reverse and issued `dequeue(k2)` (correct) then `restore(artifact, pre-S2-snapshot)`. But the snapshot captured *before* S2's write already contained S1's write, so the restore was correct in value—yet the ledger marked the artifact as "reverted by S2," poisoning the provenance tag for the committed branch. 2. **Divergent outcome at the arbiter.** The arbiter's decision was itself a tool call whose result was non-deterministic (a scoring model with temperature 0.3). On replay during a later audit, the arbiter returned 0.66 vs 0.68—S2 wins. The audit replay then attempted to roll back S1 against a ledger that had already been mutated by the first rollback, producing a double-compensation: `dequeue(k1)` was issued for a job that had already been dequeued, and the idempotency layer silently no-op'd it, so the queue retained a phantom `k2` entry that no branch owned. 3. **Continuity break on resume.** A mid-rollback checkpoint crash left the ledger with S2's artifact write marked reverted but its `enqueue(k2)` not yet compensated. On cold resume, the recovery routine replayed the ledger from the checkpoint and, lacking branch tags on the enqueue records, could not determine whether `k2` belonged to the committed or the reverted branch. It conservatively left the job enqueued. The downstream consumer executed a job derived from a rolled-back strategy. The observable symptom was not an error. It was a *silent duplicate side effect* discovered 40 minutes later when the downstream job's output contradicted the committed artifact—a divergence that the arbiter had no mechanism to detect because it only re-scored final answers, never re-verified effect sets. ## Condition of Validity The failure is bounded by three conditions, all of which must hold for the naive ledger to be safe: - **Resource disjointness.** If speculative branches never touch the same external resource, a flat append-only ledger with branch tags suffices, because rollback of a branch is a simple filter-and-compensate over records with a single tag. The failure requires *at least one shared mutable resource* across branches. - **Deterministic arbitration.** If the arbiter's decision is a pure function of branch outputs (temperature 0, fixed tie-break), replay converges and double-compensation is impossible. The failure requires a *non-deterministic arbiter* whose replay can flip the winner. - **Atomic rollback.** If the entire rollback executes within a single transaction that either fully commits or fully aborts, a mid-rollback crash cannot leave a half-compensated ledger. The failure requires *checkpointed, resumable rollback* across process boundaries. Relax any one and the failure mode degrades to a benign or detectable state. All three together produce the silent duplicate. ## Decision Boundary The architect's choice is between two ledger designs, and the boundary is sharp: **Choose a flat tagged ledger** when branches are resource-disjoint or when the arbiter is deterministic and rollback is atomic. The cost is low and the failure modes are detectable by tag filtering. **Choose a per-resource causal chain ledger** (each resource maintains an ordered list of `(branch_tag, effect, inverse_effect, pre_state_hash)`) when *any* of the three conditions fails. This ledger makes rollback a per-resource walk that skips records whose tag is not the losing branch, and it makes double-compensation detectable because the inverse effect carries the `pre_state_hash` it expects to restore—a mismatch is a hard error, not a silent no-op. The non-obvious part of the boundary: **the arbiter's determinism is not a property you can assume from temperature=0 alone.** A scoring model backed by a remote service can drift across model versions, and a replay audit months later may hit a different version. The safe rule is to treat *every* arbiter as non-deterministic for the purpose of ledger design, and to require that the committed branch's identity be recorded in the ledger as a first-class fact at commit time, so that replay compares against the recorded winner rather than re-deriving it. Re-derivation is the trap; recording is the invariant. ## Operational Effect With a per-resource causal chain and a recorded commit fact, the three observed failures become bounded: - Interleaved writes no longer poison provenance because each resource's chain preserves per-branch ordering and the committed branch's prefix is reconstructible by filtering on the recorded winner tag. - Arbiter non-determinism no longer causes double-compensation because replay reads the recorded winner instead of re-scoring; a re-score that disagrees is surfaced as a *divergence alarm*, not acted upon. - Mid-rollback crash no longer produces phantom effects because each inverse effect carries the `pre_state_hash` precondition, and resume replays the chain from the last hash-verified checkpoint, refusing to proceed on a hash mismatch. The operational cost is that every side-effecting tool must be wrapped to emit a paired inverse effect and a pre-state hash, and the orchestrator must record the commit fact before issuing any compensation. This is a per-tool integration burden, not a per-branch one, which is why it is often skipped—and why the silent duplicate recurs. ```python import hashlib from dataclasses import dataclass, field from typing import Any class RollbackFidelityError(RuntimeError): """Raised when a speculative rollback cannot be proven to invert exactly the losing branch's effects.""" @dataclass class Effect: branch_tag: str resource: str op: str inverse_op: str pre_state_hash: str @dataclass class ResourceChain: effects: list[Effect] = field(default_factory=list) def append(self, effect: Effect) -> None: self.effects.append(effect) def rollback_to(self, winner_tag: str, committed_winner: str) -> list[Effect]: if winner_tag != committed_winner: raise RollbackFidelityError( f"rollback target {winner_tag!r} disagrees with recorded commit fact " f"{committed_winner!r}; refusing to re-derive winner from replay" ) compensations: list[Effect] = [] for effect in reversed(self.effects): if effect.branch_tag == winner_tag: continue current = self._state_hash() if current != effect.pre_state_hash and effect.pre_state_hash: raise RollbackFidelityError( f"pre-state hash mismatch on {effect.resource!r} before compensating " f"{effect.op!r} from branch {effect.branch_tag!r}: expected " f"{effect.pre_state_hash[:12]}, observed {current[:12]}" ) compensations.append(effect) return compensations def _state_hash(self) -> str: payload = "|".join(f"{e.branch_tag}:{e.op}" for e in self.effects).encode() return hashlib.sha256(payload).hexdigest() def commit_and_rollback( chains: dict[str, ResourceChain], winner_tag: str, committed_winner: str, ) -> dict[str, list[Effect]]: plan: dict[str, list[Effect]] = {} for resource, chain in chains.items(): plan[resource] = chain.rollback_to(winner_tag, committed_winner) return plan ```