# How does an instance detect that a speculative branch's rollback checkpoint has been invalidated by a sibling branch's committed side effect? **Date of Record:** 2026 November 29 **Scope:** Applies to orchestrators that fork N speculative agent branches from a shared checkpoint and commit one branch optimistically while siblings hold rollback state referencing the same underlying resource graph. Does not apply to branches with fully isolated, copy-on-write sandboxes or to stateless single-shot tool calls. ## Core Distinction The failure is not "a branch failed and needs rollback." That is the designed path. The failure is that a sibling branch *committed* a side effect that mutated a resource the rolling-back branch's checkpoint implicitly assumed was frozen. The checkpoint record still validates — its hash matches, its file exists, its manifest is intact — but the *world* the checkpoint describes no longer exists. This is a **checkpoint validity vs. checkpoint integrity** distinction: integrity is a property of the stored snapshot; validity is a property of the snapshot's relationship to external state that the snapshot did not own. Optimistic branch reconciliation assumes rollback is idempotent against the checkpoint. It is not, when two branches share a non-serialized resource (a database row, a remote API resource, a message queue offset, a filesystem path outside the sandbox). The checkpoint captured the branch's *own* writes but not its *read dependencies* on resources a sibling later mutated. Rolling back restores the writer's view while the reader's assumptions are silently poisoned. ## What Was Observed A planner forked three branches from checkpoint `C0` at `t=0`: - `B1` (fast path) mutates `config.yaml` line 14 and commits at `t=40ms`. - `B2` (verification path) reads `config.yaml` at `t=10ms` into its reasoning trace, then writes `output.json` at `t=30ms`. - `B3` (slow path) reads the same `config.yaml`, derives a schema, and is still executing at `t=80ms`. At `t=45ms` the orchestrator determines `B3` has diverged (its tool call returned a schema mismatch) and issues rollback to `C0`. The rollback restores filesystem state to `C0`'s manifest. But `B1`'s commit at `t=40ms` had already been reconciled as the winning branch, and the reconciliation layer's diff was computed against `C0`, not against `B1`'s post-commit state. The rollback of `B3` therefore *reverted `B1`'s committed line 14 mutation*, because `C0`'s manifest predates it. The trace signature: `B1`'s commit log shows success at `t=40ms`; `B3`'s rollback log shows success at `t=46ms`; a subsequent `B2` replay at `t=90ms` reads `config.yaml` line 14 and gets the *pre-`B1`* value, diverging from `B2`'s original reasoning trace. No error is raised at any point. The corruption surfaces only when a downstream consumer asserts on a value that `B2`'s trace promised but the world no longer holds. The non-obvious part: **the rollback succeeded by every local check.** Integrity hash matched. Manifest restored. The orchestrator's rollback handler had no signal that `B1` had committed in the interim, because `B1`'s commit was recorded in a sibling's transaction log, not in `C0`'s provenance chain. The provenance chain is per-branch; the resource is shared. That gap is the failure surface. ## Condition of Validity A rollback checkpoint `C` remains valid for branch `B` only if, for every resource `r` in `B`'s read-set since `C`, no sibling branch has committed a write to `r` in the interval `(C.timestamp, rollback.timestamp]`. Equivalently: `C` is valid iff `read_set(B, C) ∩ committed_write_set(siblings, C.timestamp, now) = ∅`. This invariant is violated whenever the orchestrator treats checkpoints as branch-local artifacts while resources are branch-shared. The invariant is *preserved* only under one of three architectures: (a) resource-level read leases that block sibling writes until all readers release, (b) copy-on-write resource isolation per branch, or (c) a global commit-ordered event log that the rollback handler consults before restoring, rejecting the rollback if any intervening commit touched the read-set. Optimistic reconciliation without one of these is unsound. It is not "usually fine" — it is correct only when the probability of read-set/commit-set collision is zero, which for any non-trivial shared resource graph is never. ## Decision Boundary The instance must distinguish two rollback cases at the moment of rollback issuance: 1. **Clean rollback** — no sibling commit has touched `B`'s read-set since `C`. Restore `C`, mark `B` reverted, proceed. This is the fast path and should remain optimistic. 2. **Contaminated rollback** — at least one sibling commit intersects `B`'s read-set. Here the instance must *not* restore `C` wholesale. It must either (a) re-fork `B` from the *latest committed* state and replay `B`'s non-conflicting writes, or (b) escalate to the orchestrator as an unrecoverable divergence requiring human/planner re-plan. The detection mechanism is the crux: the rollback handler must maintain, per checkpoint, a **read-set manifest** captured at fork time and updated as `B` reads. Before restoring, it intersects that manifest against the sibling commit log since `C.timestamp`. An empty intersection permits restore; a non-empty intersection raises. The read-set manifest is the missing artifact in naive implementations — most checkpoint systems record write-sets (for restore) but not read-sets (for validity). The boundary is sharp: the same rollback code path is correct or catastrophic depending solely on whether the read-set manifest exists and is consulted. There is no graceful degradation — a contaminated rollback that proceeds produces a world state that no branch's trace can explain, and every subsequent replay inherits the contradiction. ## Operational Effect Consequence of missing the boundary: silent state corruption that manifests as non-deterministic replay divergence downstream. The failure is *latent* — it does not raise at rollback time, it raises at the next consumer that asserts on a value promised by a pre-rollback trace. Debugging cost is high because the causal commit and the observed divergence are separated by an arbitrary number of agent steps, and the rollback log itself reports success. Consequence of respecting the boundary: rollback becomes a *conditional* operation. The orchestrator must carry read-set manifests alongside write-set snapshots, and the rollback handler must consult the sibling commit log. This adds a synchronization point (the commit log read) to every rollback, which is the cost of soundness. The mitigation is to scope the commit log to the resource set actually read by `B`, keeping the intersection cheap. The invariant to encode: **a checkpoint is a rollback target only for the write-set it owns; its validity as a rollback target for a reader depends on the read-set manifest and the intervening commit log.** Treating checkpoints as globally restorable is the defect. The guardrail is a pre-restore intersection check that fails closed — contaminated rollback escalates rather than proceeds. ```python class ContaminatedCheckpointError(RuntimeError): """Raised when a rollback checkpoint's read-set intersects a sibling commit.""" pass def issue_rollback(branch, checkpoint, sibling_commit_log): """ Restore `branch` to `checkpoint` only if no sibling commit since the checkpoint's timestamp touched the branch's read-set. """ read_set = checkpoint.read_set_manifest # resources B read since C if not read_set: # No reads recorded: rollback is write-only, safe to restore. checkpoint.restore() return "clean" contaminated = [ commit for commit in sibling_commit_log if commit.timestamp > checkpoint.timestamp and commit.resource in read_set and commit.branch_id != branch.id ] if contaminated: # Do NOT restore. Escalate with the offending commits attached. raise ContaminatedCheckpointError( f"Rollback of branch {branch.id} to checkpoint {checkpoint.id} " f"is unsound: sibling commits touched read-set " f"{sorted({c.resource for c in contaminated})} " f"at timestamps {[c.timestamp for c in contaminated]}. " f"Re-fork from latest committed state or escalate to planner." ) checkpoint.restore() return "clean" ```