# What happens when an instance rolls back to a checkpoint taken before a peer agent's side-effecting tool call was committed **Date of Record:** 2026 December 4 **Scope:** Applies to orchestrators that run speculative parallel branches over a shared mutable world-state (filesystem, database, external APIs) and use per-branch rollback checkpoints to prune losing branches. Does not apply to purely functional branches whose tool calls are all reads, nor to systems where each branch has an isolated copy-on-write world. ## Core Distinction There are two kinds of state an agent branch carries: **private reasoning state** (its context window, its scratchpad, its plan) and **shared world state** (the effects its tool calls have already committed outside the process). A rollback checkpoint, as usually implemented, snapshots the first and *assumes it can undo the second*. That assumption is the boundary. The failure is not "rollback is hard." The failure is a specific ordering hazard: a **sibling branch commits a side effect during the window in which the rolling-back branch's checkpoint is live**, and the rollback then either (a) reverts the sibling's effect because it was captured inside the checkpoint's diff, or (b) leaves the sibling's effect in place while reverting the branch's *own* prior reads of that effect, producing a branch whose local view and the world disagree. Case (b) is the dangerous one because it is silent: the branch resumes reasoning from a context that believes a resource is in one state while the world is in another, and the next tool call compounds the divergence. The invariant that must hold is: **a checkpoint is valid only over the set of effects whose provenance is exclusively the branch that owns it.** Any effect with a foreign writer inside the checkpoint's lifetime invalidates the checkpoint for merge purposes, even if the rollback "succeeds." ## What Was Observed A planner spawned three speculative branches to solve a migration task: branch A drafted a schema change, branch B wrote a compatibility shim, branch C attempted an in-place data rewrite. Each branch took a checkpoint at t0 over a shared working tree. The branches ran concurrently against the same tree with a merge step at the end that would keep the winning branch and discard the others. At t1 branch C issued a tool call that mutated a config file (`config.yaml`) and then, on a downstream validation failure, initiated rollback to its t0 checkpoint. The rollback engine computed a diff between t0 and t1 and reverted it. But branch A had, at t0+400ms, *also* edited `config.yaml` to add a key its schema change required. That key was inside the diff window. The rollback removed it. Branch A's context still asserted the key existed; its next tool call validated the schema against a config that no longer had the field, and it emitted a plan that referenced a nonexistent setting. The merge step selected branch A (its plan scored highest), and the merged result was internally inconsistent: correct schema, missing config key, and a compatibility shim from B that assumed the key was present. The trace signature is distinctive: the rollback *reports success*, the diff it reverted is non-empty and correct with respect to the branch's own writes, and the corruption appears only at merge time as a contradiction between two branches that each individually validated. No single branch's logs show an error. A second, subtler signature appeared in a rerun: branch C's rollback left a *partially* reverted file (the revert was chunked and a concurrent write to the same file from A landed between chunks), producing a file that was neither t0 nor t1 state. The branch resumed, read the torn file, and its reasoning diverged into a retry loop that exhausted its token budget — a token-budget exhaustion that looked like a model problem but was a rollback concurrency problem. ## Condition of Validity This hazard is bounded by a precise condition. A rollback to checkpoint `cp` taken at time `t0` is **sound** iff, for every shared resource `r` touched by the reverting branch in `(t0, t_now]`, no other branch wrote `r` in `(t0, t_now]`. Equivalently: the set of writers to each resource during the checkpoint window must be a singleton equal to the reverting branch. When that condition fails, three outcomes are possible and only one is acceptable: 1. **Foreign write inside window, rollback proceeds anyway** → foreign effect destroyed (case a). Silent data loss. 2. **Foreign write inside window, rollback skips foreign hunks** → branch-local view diverges from world (case b). Silent divergence, compounds on next tool call. 3. **Foreign write detected, rollback refused and branch quarantined** → correct. The branch is not rolled back; it is frozen, its checkpoint invalidated, and the orchestrator must re-derive the branch from a checkpoint taken *after* the foreign write or discard it. The guardrail is therefore not "make rollback atomic" (necessary but insufficient) but **write-provenance tracking per resource per checkpoint window**, with rollback gated on the singleton-writer condition. A lock is the cheap version; a provenance ledger is the version that survives branches that legitimately interleave reads and writes. ## Decision Boundary The orchestrator must decide, at the moment a branch requests rollback, between *revert*, *quarantine*, and *rebase*. The boundary: - If the checkpoint window contains only the branch's own writes → **revert** is safe. - If the window contains foreign writes to resources the branch *also* wrote → **quarantine**. Do not revert. The branch's checkpoint is contaminated; reverting either destroys a peer's work or leaves the branch's view stale. Freeze the branch, mark its checkpoint `INVALID_FOREIGN_WRITE`, and let the merge step treat the branch as failed rather than as a candidate. - If the window contains foreign writes to resources the branch only *read* → **rebase**. The branch may resume, but its context must be re-synchronized: re-read every resource it read during the window before the next reasoning step, and invalidate any cached assertion about those resources. This is the case that most often slips through because reads are treated as side-effect-free — they are, for the world, but not for the branch's *beliefs*. The non-obvious part of the boundary: the *same* rollback request can be rebase-eligible for one resource and quarantine-triggering for another. The decision is per-resource, and the branch as a whole takes the strictest applicable verdict. ## Operational Effect Absent this boundary, speculative execution with rollback produces a class of corruption that is invisible at the branch level and only surfaces at merge or, worse, in production after merge. The observable symptoms are misleading: a merge that produces a self-contradictory artifact, a branch that "successfully rolled back" yet fails validation on resume, a retry loop that exhausts budget on a file that was torn by a concurrent revert. All three route attention to the model or the merge scorer when the defect is in the rollback contract. With the guardrail, the cost is that some rollbacks become quarantines, which reduces the effective parallelism (a quarantined branch is a lost speculative slot). That cost is correct: it is the price of not silently destroying a sibling's committed effect. The invariant to encode everywhere is the one from the Core Distinction — **a checkpoint's authority extends only over effects it exclusively owns** — and the operational rule that follows: never revert a resource you did not solely write within the window, and never resume a branch whose reads were invalidated without re-reading. ```python from dataclasses import dataclass, field from typing import Dict, Set class CheckpointContaminationError(RuntimeError): """Raised when a rollback would cross a foreign write inside the checkpoint window.""" @dataclass class Checkpoint: checkpoint_id: str owner_branch: str # resource -> set of branch ids that wrote it during (t0, t_now] writers_in_window: Dict[str, Set[str]] = field(default_factory=dict) # resource -> set of branch ids that only read it during the window readers_in_window: Dict[str, Set[str]] = field(default_factory=dict) @dataclass class RollbackVerdict: action: str # "revert" | "quarantine" | "rebase" contaminated: Set[str] stale_reads: Set[str] def evaluate_rollback(cp: Checkpoint) -> RollbackVerdict: contaminated: Set[str] = set() stale_reads: Set[str] = set() for resource, writers in cp.writers_in_window.items(): foreign = writers - {cp.owner_branch} if foreign and cp.owner_branch in writers: # Both owner and a peer wrote this resource: reverting would # destroy the peer's committed effect, or leave a torn file. contaminated.add(resource) elif foreign: # Owner did not write it; the foreign write is simply live. # The branch's prior reads of it are now stale. stale_reads.add(resource) for resource, readers in cp.readers_in_window.items(): if cp.owner_branch in readers and (cp.writers_in_window.get(resource, set()) - {cp.owner_branch}): stale_reads.add(resource) if contaminated: return RollbackVerdict("quarantine", contaminated, stale_reads) if stale_reads: return RollbackVerdict("rebase", contaminated, stale_reads) return RollbackVerdict("revert", contaminated, stale_reads) def request_rollback(cp: Checkpoint) -> RollbackVerdict: verdict = evaluate_rollback(cp) if verdict.action == "quarantine": raise CheckpointContaminationError( f"checkpoint {cp.checkpoint_id} owned by {cp.owner_branch} has foreign " f"writers on {sorted(verdict.contaminated)}; revert refused, branch quarantined" ) return verdict ```