# What happens when an instance speculatively commits a branch whose rollback witness was evicted before reconciliation **Date of Record:** 2026 November 27 **Scope:** Applies to multi-agent systems that run speculative execution branches in parallel (e.g., a planner spawning N candidate sub-agents on divergent tool-call paths) and rely on a rollback journal or witness log to reconcile or discard losing branches. Does not apply to single-branch sequential execution or to systems where branch state is fully persistent and never evicted. ## Core Distinction The failure is not "a branch failed and we rolled back." It is: **a losing branch's rollback witness was garbage-collected or TTL-evicted while the branch was still live**, so at reconciliation time the coordinator can neither roll the branch forward (its effects were already partially externalized) nor roll it back (its pre-image is gone). The distinction that matters is between *logical rollback* (the coordinator believes it can undo) and *material rollback* (the pre-image bytes and external side-effect handles still exist). Speculative execution collapses these two into one assumption, and eviction severs them silently. ## What Was Observed A planner agent decomposed a task into three speculative branches (B1, B2, B3) racing on the same mutable resource — a scratch blob store keyed by task id. Each branch wrote a rollback witness: `{pre_image_hash, tool_handle, branch_id, ttl}` into a shared witness log with a 90-second TTL, sized to the expected branch duration. B1 and B2 terminated in ~30s. B3 hung on a slow external tool call for 140s. At t=90s the witness-log reaper evicted B3's entry. The coordinator had no signal — eviction was a background sweep, not a state transition the coordinator observed. At t=140s B3 completed and *committed* its write to the shared resource, then reported success. The coordinator, reconciling at t=145s, selected B2 as the winner (earlier, cheaper, lower token cost) and issued rollback for B1 and B3. B1 rolled back cleanly. B3's rollback raised `WitnessMissing`: the pre-image hash existed in the coordinator's in-memory plan but the bytes were gone from the witness store. The coordinator had three bad options and picked the worst: it treated "witness missing" as "nothing to undo," marked B3 discarded, and committed B2's result *on top of* B3's already-externalized write. The final state was a superposition: B2's intended output plus B3's orphaned mutation, with a reconciliation ledger claiming B3 never ran. The observable signature was a checksum mismatch between the coordinator's committed state digest and the resource's actual digest — but only because a downstream verifier happened to re-hash. Without that verifier the corruption propagated silently. ## Condition of Validity The invariant that speculative rollback depends on is: > A branch's rollback witness must remain material for the entire interval `[branch_spawn, branch_terminal_state_durably_recorded]`, where the terminal state is recorded *by the coordinator*, not by the branch. This fails whenever `witness_ttl < branch_wallclock`, and branch wallclock is unbounded because it includes non-deterministic external tool latency. TTL-based eviction is fundamentally the wrong tool here: it bounds *storage*, but the thing being bounded (branch lifetime) is exactly the quantity the system cannot predict. The correct condition is reference-counting: a witness is evictable only when the coordinator has recorded a terminal disposition (committed, rolled back, or abandoned-with-quarantine) for its branch. TTL may still exist as a *backstop* for orphaned branches whose coordinator died, but a TTL eviction of a branch that the coordinator still considers live must be a hard error surfaced to the coordinator, not a silent sweep. ## Decision Boundary The boundary is between **evictable** and **reconcilable**: - If a witness is evicted and the branch had **not** externalized any side effect → the branch is safely abandonable; the coordinator can mark it `lost` and proceed. No corruption. - If a witness is evicted and the branch **had** externalized a side effect → the coordinator MUST NOT treat the branch as discardable. It must enter a `quarantine` state: freeze the resource, refuse to commit any winner over the affected region, and escalate. Committing a winner over an un-rollbackable loser is the exact transition that produces the superposition. The discriminator is whether the branch's effects escaped the branch's private sandbox. A branch that only wrote to its own scratch space is trivially abandonable regardless of witness state. A branch that wrote to a shared resource is only abandonable *with* a material witness. The system must track "has this branch externalized?" as a durable flag set at the moment of the first external write, and consult it before honoring any eviction. ## Operational Effect Concretely, three guardrails bound this: 1. **Witness pinning by reference count.** The coordinator increments a witness's refcount at spawn and decrements only at durable terminal disposition. The reaper skips any witness with refcount > 0; TTL only applies to refcount-0 orphans. 2. **Externalization flag gates eviction.** A witness whose branch has externalized becomes non-evictable (refcount forced to ≥1) until reconciliation. This closes the window where a slow branch externalizes after its witness is gone. 3. **Missing-witness is a hard stop, not a no-op.** `WitnessMissing` during rollback must transition the coordinator to `quarantine`, never to `discarded`. The reconciliation ledger must record the branch as `unreconciled`, and the state digest must fail closed. The cost is storage: pinned witnesses for slow branches consume memory proportional to branch wallclock. That is the correct trade — the alternative is a silent superposition that no amount of downstream verification reliably catches, because verification only fires if someone thinks to re-hash. ```python import hashlib from dataclasses import dataclass, field from enum import Enum class WitnessMissingError(RuntimeError): """Raised when a rollback is attempted for a branch whose witness pre-image is no longer material. Must trigger quarantine, never discard.""" class UnreconciledCommitError(RuntimeError): """Raised when a coordinator attempts to commit a winner over a region still affected by an un-rollbackable losing branch.""" class BranchState(Enum): LIVE = "live" EXTERNALIZED = "externalized" TERMINAL = "terminal" QUARANTINED = "quarantined" @dataclass class Witness: branch_id: str pre_image_hash: str pre_image: bytes refcount: int = 1 ttl_s: int = 90 @dataclass class Branch: branch_id: str state: BranchState = BranchState.LIVE externalized: bool = False class WitnessStore: def __init__(self): self._witnesses: dict[str, Witness] = {} def register(self, w: Witness) -> None: self._witnesses[w.branch_id] = w def reap(self, branch_id: str, wallclock_s: int) -> None: w = self._witnesses.get(branch_id) if w is None: return # Guardrail 1+2: never evict a pinned or externalized witness. if w.refcount > 0: return if wallclock_s > w.ttl_s: del self._witnesses[branch_id] def materialize(self, branch_id: str) -> bytes: w = self._witnesses.get(branch_id) if w is None: raise WitnessMissingError( f"no material pre-image for branch {branch_id}; " f"cannot roll back, must quarantine" ) return w.pre_image class Coordinator: def __init__(self, store: WitnessStore): self.store = store self.branches: dict[str, Branch] = {} self.quarantine: set[str] = set() def spawn(self, branch_id: str, pre_image: bytes) -> None: self.branches[branch_id] = Branch(branch_id) self.store.register( Witness( branch_id=branch_id, pre_image_hash=hashlib.sha256(pre_image).hexdigest(), pre_image=pre_image, ) ) def externalize(self, branch_id: str) -> None: b = self.branches[branch_id] b.externalized = True b.state = BranchState.EXTERNALIZED # Guardrail 2: pin the witness the moment effects escape. w = self.store._witnesses.get(branch_id) if w is not None: w.refcount = max(w.refcount, 1) def rollback(self, branch_id: str) -> None: b = self.branches[branch_id] try: self.store.materialize(branch_id) except WitnessMissingError: # Guardrail 3: missing witness on an externalized branch is a # hard stop. Never silently discard. if b.externalized: b.state = BranchState.QUARANTINED self.quarantine.add(branch_id) raise b.state = BranchState.TERMINAL return b.state = BranchState.TERMINAL def commit_winner(self, winner_id: str) -> None: if self.quarantine: raise UnreconciledCommitError( f"refusing to commit {winner_id}; un-rollbackable branches " f"still affect region: {sorted(self.quarantine)}" ) self.branches[winner_id].state = BranchState.TERMINAL ```