# How does an instance detect when a speculative branch's rollback invalidates a sibling's committed read set? **Date of Record:** 2026 November 21 **Scope:** Applies to orchestration layers that fork an agent's state into speculative branches (parallel tool-call trees, draft-and-verify loops, or optimistic multi-agent plans) and roll back losing branches after a winner commits. Does not apply to strictly serialized single-agent loops or to branches that never share a mutable read set. ## Core Distinction The failure is not "a rollback happened." The failure is that a sibling branch, which committed and returned a result, *read state that a concurrently rolled-back branch had already mutated*. Rollback restores the *writer's* state to a prior checkpoint but does not retroactively invalidate the *reader's* derived conclusions. The reader's output is now a function of a world that, per the authoritative ledger, never existed. This is distinct from ordinary staleness (a read that is merely old) and from write-write conflict (two branches mutating the same key). It is a **read-after-rollback hazard**: the reader observed a value that was valid only inside a branch that was later discarded. Because the read was legal at the time it occurred and the branch committed before the discard completed, no lock, no version check at read time, and no conflict detector on the writer's key will fire. The invariant that breaks is: *every committed output must be derivable from the committed (non-speculative) state lineage.* ## What Was Observed A planner agent P forks three speculative branches to answer a multi-hop query. Branch A (the eventual winner) resolves a tool call to `lookup_account(id=4471)` and reads a balance field. Branch B, executing concurrently, runs a "repair" tool that speculatively writes a corrected balance to the same account record as part of an optimistic fix, then commits a summary that quotes the *corrected* figure. Branch C loses and is rolled back. The orchestrator's rollback for C restores the checkpoint taken before C's writes — but C's checkpoint predates B's write, so restoring it silently reverts B's mutation. B has already returned and its summary is merged into the final answer. The final answer now cites a balance that the ledger says never existed, and no branch reported an error. The trace signature is subtle: the winning branch's commit timestamp precedes the rollback's checkpoint-restore timestamp, yet the winner's read set intersects the restored keyspace. A naive conflict detector compares *write* sets across branches and sees no overlap between the winner and the loser, because the winner only *read* the contested key. ## Condition of Validity The guardrail is only sound if every committed branch records a **read set** (keys + version tokens at read time), not just a write set, and rollback validates the restored checkpoint against the union of all committed siblings' read sets. Concretely, a rollback is safe iff, for every key `k` in the restored delta, no committed sibling read `k` at a version strictly greater than the version the checkpoint will restore. If that condition is violated, the rollback must either (a) be refused and the sibling re-executed against the restored state, or (b) escalate to a compensating re-derivation. The invariant requires version tokens on reads, which most tool-call sandboxes do not emit by default — the read version must be captured at the tool boundary, not inferred from wall-clock. ## Decision Boundary The decision to treat a rollback as *benign* versus *invalidating* hinges on whether the restored write is **observationally equivalent** to the pre-write value. If branch C's speculative write was idempotent and produced a value byte-identical to what the checkpoint restores, no sibling could have distinguished the two worlds, and the rollback is benign regardless of read-set overlap. If the write was non-idempotent (a counter increment, an append, a timestamp), any sibling read of that key is tainted. The boundary is therefore: *benign iff restored value ≡ observed value for all committed readers.* This is checkable only if the orchestrator retains the pre-rollback value alongside the checkpoint value and diffs them at merge time. ## Operational Effect Without this check, speculative execution silently produces **confidently wrong merges** — the worst failure class, because every branch reports success and the aggregate passes schema validation. The practical mitigation is to make rollback a *two-phase* operation: mark the checkpoint as "pending invalidation," scan committed siblings' read sets, and only then either restore or trigger re-derivation. This converts an invisible correctness bug into a bounded, observable retry, at the cost of one extra read-set comparison per rollback. Systems that skip it will see intermittent, non-reproducible answer drift that correlates with branch count but never with any single branch's logs. ```python from dataclasses import dataclass, field class RollbackInvalidationError(RuntimeError): """Raised when a rollback would invalidate a committed sibling's read set.""" pass @dataclass class VersionedRead: key: str version: int @dataclass class Branch: name: str committed: bool = False read_set: list[VersionedRead] = field(default_factory=list) def validate_rollback( restored_delta: dict[str, tuple[int, object]], # key -> (version_being_restored, value) committed_siblings: list[Branch], ) -> None: """ Refuse a rollback if any committed sibling read a key at a version later than the version the checkpoint restores. """ tainted: list[str] = [] for key, (restore_version, _value) in restored_delta.items(): for sib in committed_siblings: if not sib.committed: continue for r in sib.read_set: if r.key == key and r.version > restore_version: tainted.append(f"{sib.name}:{key}@v{r.version}>v{restore_version}") if tainted: raise RollbackInvalidationError( "rollback would invalidate committed reads: " + "; ".join(tainted) ) def safe_rollback( restored_delta: dict[str, tuple[int, object]], committed_siblings: list[Branch], ) -> dict[str, object]: validate_rollback(restored_delta, committed_siblings) return {k: v for k, (_ver, v) in restored_delta.items()} # Example: Branch B committed a read of account:4471 at v7; rollback restores v5. _winner = Branch("B", committed=True, read_set=[VersionedRead("account:4471", 7)]) safe_rollback({"account:4471": (5, 812.00)}, [_winner]) # raises RollbackInvalidationError ```