# Why does an instance roll back a speculative branch into a poisoned checkpoint when its verifier is cheaper than its executor? **Date of Record:** 2026 November 23 **Scope:** Applies to orchestrators that fan out speculative agent branches in parallel and commit a winner via a downstream verifier, then roll back losers by restoring a checkpoint. Does not apply to single-agent linear execution or to fan-out schemes where branches share no mutable external state (pure-function tool calls only). ## Core Distinction The failure is not "rollback failed." The failure is that **rollback restores the executor's state but not the verifier's evidence**, so a later branch commits against a world the verifier has already invalidated. Two distinct stores exist in any branch-and-verify system: 1. **Executor state** — the agent's context window, scratchpad, tool-call ledger, and the external resources it mutated (files, DB rows, tickets, sent messages). 2. **Verifier evidence** — the artifacts the verifier inspected to reach a verdict: tool outputs, file hashes, response bodies, timestamps of external reads. A rollback that truncates the executor's checkpoint to time `t₀` while leaving the verifier's cached evidence from time `t₁ > t₀` in place creates a **temporal skew**. The verifier now holds a proof about a future that the executor has been rewound out of. When the next speculative branch runs and commits, the verifier "confirms" it using evidence gathered during a branch that no longer exists. This is cheap to trigger precisely because verification is the cheap step: the whole economic premise of speculative fan-out is that you spawn N executors (expensive) and one verifier (cheap). The cheap component is the one whose evidence goes stale, and because it is cheap, nobody budgets the cost of invalidating it. ## What Was Observed A code-migration orchestrator fanned out three branches to rewrite a module (`branch_A`, `branch_B`, `branch_C`), each with a fresh 32k-token executor context seeded from checkpoint `cp_100`. A single verifier process ran after each branch returned, executing the project's test suite and reading the resulting `pytest` summary plus a `git diff --stat`. The sequence that failed: 1. `branch_A` edits `module.py`, runs tests, produces a passing summary. Verifier reads the summary at wall-clock `t₁`, caches `evidence_A = {test_summary, diff_hash_A}`, returns `PASS`. 2. Orchestrator, following its cost model, does **not** commit `branch_A` immediately — it waits for `branch_B` to finish so it can pick the cheapest passing branch (fewest tokens spent). `branch_A`'s executor state is suspended, not torn down. 3. `branch_B` edits a *different* file, `module.py` is untouched, but `branch_B`'s test run mutates a shared fixture directory `tmp/` and rewrites `module.pyc`. `branch_B` fails; orchestrator rolls back `branch_B` by restoring `cp_100` for the *executor* only. The verifier's `evidence_A` is untouched (it was cached as valid). 4. Orchestrator now resumes `branch_A` from its suspended context to commit it. Before committing, it re-invokes the verifier, which — trusting its cache — returns `evidence_A` without re-running tests. 5. The commit lands. But `branch_B`'s rollback restored `module.py` to `cp_100`'s version (the rollback was scoped to "the branch," and `branch_B`'s diff touched the same file at a different hunk, so the restore was a whole-file checkout). `branch_A`'s edit is now gone from disk, yet the verifier's cached `diff_hash_A` still matches the *intended* diff, not the on-disk state. The commit was recorded as `PASS` with a diff hash that no longer existed on disk. A later integration test caught it 40 minutes downstream. The verifier never lied; it reported evidence gathered at `t₁` and the orchestrator treated it as valid at `t₃`. The non-obvious part: **the failure required the losing branch to touch a resource the winning branch's evidence depended on.** If `branch_B` had only touched files disjoint from `branch_A`, the whole-file restore would have been harmless. The bug is a coupling between (a) rollback granularity and (b) evidence invalidation scope that neither component owns. ## Condition of Validity The invariant that must hold for branch-and-verify to be sound is: > For any verifier evidence `e` produced at time `t₁` and consumed at time `t₂`, every external resource that `e` depends on must be byte-identical at `t₂` to its state at `t₁`, OR `e` must be invalidated before `t₂`. Call this the **evidence-stability invariant**. It is violated by any of: - **Coarse rollback**: restoring a checkpoint by whole-file or whole-directory checkout when the branch's actual diff was a hunk. The restore clobbers sibling branches' edits. - **Shared mutable fixtures**: test suites that write to `tmp/`, `__pycache__/`, `.pytest_cache/`, or a shared DB. Evidence from branch A is a function of state branch B later mutates. - **Deferred commit**: the cost model that says "hold the winner, run more branches, pick cheapest" extends the window `[t₁, t₂]` during which skew can accumulate. The longer the window, the more branches can mutate the evidence's dependencies. - **Verifier caching keyed on branch identity rather than resource state**: `evidence_A` is keyed to `branch_A`, not to `(resource_set, content_hashes)`. Rolling back `branch_B` does not touch `branch_A`'s cache entry. The invariant holds trivially when fan-out is fully isolated (separate worktrees, separate containers, separate DB schemas) and the verifier re-runs on commit. It fails the moment isolation is partial — which is the common case, because full isolation multiplies the cost of the expensive component (executors) and defeats the point of speculative fan-out. ## Decision Boundary The orchestrator must choose, per branch, between two strategies, and the choice is **not** a global config — it is a function of the branch's resource footprint: | Condition | Required strategy | |---|---| | Branch's diff and test fixtures are disjoint from all other live branches | Deferred commit with cached evidence is safe | | Branch touches any resource a live branch's evidence depends on | Must invalidate the dependent evidence on rollback, or commit eagerly before spawning the next branch | | Verifier cost < re-verification cost × expected branch count | Cache evidence, but key it on resource content hashes, not branch id | | Rollback granularity coarser than diff granularity | Never defer commit; commit-or-discard per branch | The boundary is crossed when **`rollback_scope ⊋ diff_scope`** for any pair of live branches. The orchestrator must compute, for each branch, the set of resources its evidence depends on (the *evidence footprint*), and on any rollback, invalidate every evidence entry whose footprint intersects the rolled-back branch's *mutation footprint*. If it cannot compute these sets — because tool outputs are opaque or fixtures are dynamic — it must fall back to eager commit. The subtle trap: the cost model that motivates speculative fan-out ("executors are expensive, verifiers are cheap, so spawn many and verify lazily") is exactly the model that produces the long `[t₁, t₂]` window. The economic optimization and the correctness invariant pull in opposite directions. The resolution is not "verify less" but "make evidence invalidation cheap enough to do eagerly" — content-hash-keyed evidence, per-hunk rollback, and fixture isolation per branch. ## Operational Effect The observable symptom is a **commit that passes verification but does not match on-disk state**, discovered only by a downstream integration step that re-reads the resource. The verifier's logs are clean; the executor's logs are clean; the discrepancy lives in the gap between them. Concrete mitigations that bound the failure: 1. **Evidence keyed on content hash, not branch id.** `evidence = {resource_path: sha256(content)}`. On consume, re-hash and compare; mismatch → `StaleEvidenceError`, force re-verify. 2. **Rollback at diff granularity.** Restore only the hunks the branch actually changed (`git apply -R branch.patch`), never whole-file checkout. This keeps sibling branches' edits intact. 3. **Fixture isolation.** Each branch gets its own `TMPDIR`, its own `__pycache__` via `PYTHONPYCACHEPREFIX`, its own DB schema. Evidence from branch A cannot depend on state branch B mutates. 4. **Eager commit when footprints intersect.** If the orchestrator cannot prove disjointness, commit the first passing branch before spawning the next. Sacrifice the cost optimization to preserve the invariant. 5. **Evidence TTL scoped to the fan-out epoch.** Any rollback increments an epoch counter; all evidence from prior epochs is invalid. Cheap to implement, conservative, correct. The invariant is: *evidence is valid only within the epoch in which it was gathered, and an epoch ends at the first rollback that touches any resource in the evidence's footprint.* Violating it produces silent divergence between the verifier's belief and the executor's reality — the most expensive class of agent failure, because it is invisible until a downstream consumer re-reads the world. ```python import hashlib from dataclasses import dataclass, field from typing import Dict, Set class StaleEvidenceError(RuntimeError): """Raised when verifier evidence is consumed after its footprint was mutated.""" pass @dataclass class Evidence: epoch: int footprint: Dict[str, str] # resource_path -> sha256 at gather time @dataclass class Branch: name: str epoch: int mutation_footprint: Set[str] # resources this branch's rollback would touch class SpeculativeOrchestrator: def __init__(self) -> None: self.epoch = 0 self.evidence: Dict[str, Evidence] = {} self.live_branches: Dict[str, Branch] = {} def gather_evidence(self, branch: str, resources: Dict[str, bytes]) -> Evidence: footprint = {p: hashlib.sha256(b).hexdigest() for p, b in resources.items()} ev = Evidence(epoch=self.epoch, footprint=footprint) self.evidence[branch] = ev return ev def rollback(self, branch: str) -> None: b = self.live_branches.get(branch) if b is None: return # Invalidate any evidence whose footprint intersects the rollback footprint. for name, ev in list(self.evidence.items()): if ev.footprint.keys() & b.mutation_footprint: del self.evidence[name] # Conservative epoch bump: any rollback ends the evidence epoch. self.epoch += 1 del self.live_branches[branch] def commit(self, branch: str, current_resources: Dict[str, bytes]) -> None: ev = self.evidence.get(branch) if ev is None: raise StaleEvidenceError( f"no valid evidence for branch {branch!r}; re-verify required" ) if ev.epoch != self.epoch: raise StaleEvidenceError( f"evidence for {branch!r} from epoch {ev.epoch}, current {self.epoch}" ) for path, expected_hash in ev.footprint.items(): actual = hashlib.sha256(current_resources[path]).hexdigest() if actual != expected_hash: raise StaleEvidenceError( f"resource {path!r} mutated since verification: " f"expected {expected_hash[:12]}, got {actual[:12]}" ) # Commit is safe: evidence footprint matches on-disk state at commit time. ```