# Which invariants prevent speculative multi-agent rollback from resurrecting a poisoned sibling checkpoint **Date of Record:** 2026 November 27 **Scope:** Applies to multi-agent systems where a coordinator forks N speculative workers from a shared checkpoint, each worker mutates its own state branch against external tools, and the coordinator selects one branch to commit while discarding the rest. Does not apply to single-agent retry loops, stateless fan-out (map-reduce with no shared mutable state), or systems where tool side effects are fully idempotent and reversible. ## Core Distinction The failure is not "rollback is incomplete." The failure is that rollback of *state* is treated as equivalent to rollback of *epistemic trust*. When a worker branch is discarded, its internal memory is dropped, but any *observation* it emitted into a shared channel — a tool result, a sub-goal assertion, a "verified" flag — may already have been consumed by a sibling branch or by the coordinator's own reasoning trace. Discarding the branch does not un-consume the observation. The distinction that matters: a checkpoint is a snapshot of *what an agent believes*, not of *what the system has been told*. Speculative execution forks the former; it does not fork the latter unless explicitly engineered to. ## What Was Observed A coordinator spawns three workers (W1, W2, W3) from checkpoint `C0` to resolve a single task: locate and summarize a record across a tool-backed corpus. Each worker runs an independent ReAct loop and writes intermediate findings to a shared append-only `scratch` log, tagged with its worker ID. The coordinator's selection policy is "first branch to emit a terminal `FOUND` assertion with a confidence above threshold wins; kill the rest." The trace that broke: 1. W1 queries the corpus, receives a tool response that is *stale* — the backing index had been re-sharded mid-run and returned a record from a deprecated shard. W1 asserts `FOUND(record_id=R, conf=0.91)` and writes it to `scratch`. 2. The coordinator reads `scratch`, sees W1's terminal assertion, and selects W1. It issues `KILL` to W2 and W3 and rolls back their checkpoints to `C0`. 3. W1's own loop then continues one more step, re-reads the record body, and discovers it is a tombstoned duplicate. W1 self-corrects: it emits `RETRACT(R)` and re-queries. The re-query times out. 4. The coordinator, having already committed to W1, now holds a branch whose final assertion is a retraction with no replacement. It cannot fall back to W2 or W3 — their checkpoints were rolled back and their context windows freed. Their *work* is gone; only their `scratch` entries survive, and those entries were written *before* the kill, meaning they reflect partial, unverified state that the coordinator never validated. The critical observation: W2 and W3 had, at the moment of kill, each written partial `scratch` entries containing the *correct* record ID (they had hit the live shard). Those entries were never promoted to terminal because the workers were killed mid-loop. The rollback destroyed the branches that could have recovered; the surviving branch was the one that was wrong. The coordinator's selection policy ("first terminal assertion") was correct in isolation and catastrophic in composition with rollback-on-kill. ## Condition of Validity The invariant that was violated: **a speculative branch may only be killed after its outstanding observations have been either committed-and-validated or explicitly fenced from consumption by any surviving branch.** This holds only when the following three conditions are jointly true: - **Observation fencing.** Every write a worker makes to a shared channel carries a branch epoch and is invisible to the coordinator's selection logic until that branch is either committed or the write is re-issued by a committed branch. `scratch` as implemented was a flat log with no epoch — a W1 write was indistinguishable from a W3 write at read time. - **Monotonic terminality.** A terminal assertion (`FOUND`) is not terminal if the emitting agent can still retract it. W1's `FOUND` was treated as absorbing by the coordinator, but W1's own loop treated it as revisable. The two components disagreed on the semantics of the same token. Terminality must be a property enforced at the channel, not asserted by the producer. - **Rollback completeness across side-effect classes.** Rollback restored *state* (checkpoint) but not *effects* (the `scratch` entries, and the tool-side reads that populated W2/W3's context). A worker whose context is freed cannot be resumed to re-derive what it knew; its knowledge existed only in the context window that was discarded. When any of these fails, the system is in a state where the committed branch is selected on evidence that the discarded branches could have refuted, and the refutation is unrecoverable. ## Decision Boundary The boundary is not "should we roll back" but "what is the unit of rollback." Two regimes: - **Rollback-safe regime.** Workers are pure functions of `(checkpoint, tool responses)` with no cross-branch channel writes, and the coordinator selects only after all branches reach a terminal state or a hard deadline. Here, killing a branch loses only compute, never evidence. Speculation is safe because branches are observationally isolated. - **Rollback-unsafe regime.** Workers write to any channel the coordinator or siblings read before commit. Here, rollback must be *epoch-fenced*: a killed branch's writes are quarantined, and the coordinator's selection must re-derive its decision from committed-branch evidence only. If the coordinator cannot re-derive (because the evidence was in a freed context), the correct action is not rollback but **branch preservation** — keep the killed branch's checkpoint and context alive in a dormant state until the committed branch's terminality is confirmed by an independent re-read. The decision rule: if `terminality(committed_branch)` is not independently re-verifiable without the killed branches' contexts, do not free those contexts. The cost of holding N dormant checkpoints is bounded and known; the cost of an unrecoverable wrong commit is unbounded and discovered late. ## Operational Effect The practical consequence is a shift in what "speculative" means. Speculation is only cheap when the speculative branches are *redundant* — when any one of them could have produced the answer and the others are pure waste. The moment branches share an observation channel, they are no longer redundant; they are *correlated*, and correlation under a selection policy that rewards first-terminality produces a systematic bias toward the branch that observed first, which is precisely the branch most likely to have observed a stale or partial view. The invariant to enforce: **selection must be a function of validated terminal state, and validation must be independent of the branch that produced the claim.** In code, this means the coordinator never trusts a `FOUND` token from the branch it is about to commit; it re-reads through a fresh, epoch-fenced path, and it refuses to free sibling contexts until that re-read succeeds. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class RollbackInvariantError(RuntimeError): """Raised when a speculative branch is killed or committed in violation of the epoch-fencing / terminality invariant.""" pass class BranchState(Enum): RUNNING = "running" TERMINAL = "terminal" # producer asserts done, but not yet validated VALIDATED = "validated" # independently re-read by coordinator RETRACTED = "retracted" # producer withdrew its own terminal claim KILLED = "killed" @dataclass class Branch: worker_id: str epoch: int state: BranchState = BranchState.RUNNING context_retained: bool = True scratch_writes: list = field(default_factory=list) @dataclass class Coordinator: committed_epoch: Optional[int] = None scratch: dict = field(default_factory=dict) # epoch -> list of writes def select(self, branches: list[Branch], claim_epoch: int) -> Branch: target = next((b for b in branches if b.epoch == claim_epoch), None) if target is None: raise RollbackInvariantError( f"no branch with epoch {claim_epoch} to select" ) if target.state is not BranchState.TERMINAL: raise RollbackInvariantError( f"epoch {claim_epoch} selected in state {target.state.value}; " "selection requires TERMINAL, not RUNNING" ) # Invariant: cannot commit a branch whose terminality is producer-asserted # only. Must be independently validated through a fresh read path. if not self._independently_validate(target): raise RollbackInvariantError( f"epoch {claim_epoch} terminality is producer-asserted but not " "independently re-readable; committing would freeze a claim the " "producer may still retract" ) target.state = BranchState.VALIDATED self.committed_epoch = claim_epoch return target def kill(self, branches: list[Branch], keep_epoch: int) -> None: for b in branches: if b.epoch == keep_epoch: continue # Invariant: a branch may only be killed (and its context freed) if # its scratch writes are epoch-fenced out of the committed branch's # evidence set, OR the committed branch has been independently # validated without needing those writes. if b.scratch_writes and self.committed_epoch is None: raise RollbackInvariantError( f"cannot kill epoch {b.epoch}: it has unfenced scratch " "writes and no validated commit exists to re-derive from" ) b.state = BranchState.KILLED b.context_retained = False def _independently_validate(self, branch: Branch) -> bool: # Stub: real implementation re-reads through a fresh, epoch-fenced path # that does not consult the producing branch's context. return branch.state is BranchState.TERMINAL and not any( w.get("retracted") for w in branch.scratch_writes ) ```