# Why does an instance lose its speculative branch when a sibling commits first: rollback-token invalidation across concurrent agent forks **Date of Record:** 2026 December 2 **Scope:** Applies to multi-agent systems that fork a shared execution state into speculative branches, run tool calls optimistically, and reconcile by committing one branch and rolling back siblings. Does not apply to single-agent linear execution or to stateless fan-out where branches share no mutable substrate. ## Core Distinction There is a difference between *logical rollback* (the agent's reasoning discards a hypothesis) and *substrate rollback* (the shared mutable state—filesystem, KV cache, scratch store, tool-side effects—is reverted to a checkpoint). Speculative multi-agent execution couples the two. The failure mode documented here is **rollback-token invalidation**: when sibling branch A commits and advances the shared substrate's monotonic version counter, branch B's previously issued rollback token no longer points at a valid ancestor. B's rollback either fails closed (safe, but B is now a zombie holding a stale view) or fails open (catastrophic: B reverts A's committed work or splices its own speculative writes onto a post-A substrate that never agreed to them). The invariant under threat is *ancestor stability*: a rollback token must remain a valid reference to a substrate state until every branch descended from it has either committed or been explicitly reaped. ## What Was Observed A planner agent forks three speculative branches to resolve an ambiguous subtask: `B1` refactors a config file, `B2` applies a schema migration, `B3` patches a validation hook. Each branch is issued `rollback_token = substrate.checkpoint()` at fork time, all pointing at substrate version `v=40`. The branches execute concurrently against copy-on-write overlays, but **tool side effects are not isolated**—the substrate is a single logical store with an optimistic version counter. `B1` finishes first and commits. Commit performs `substrate.apply(B1.delta); substrate.version = 41`. The commit path is correct in isolation. But the reconciliation controller only checks *its own* branch's token validity at rollback time, not the token's reachability from the current head. `B2` then fails a tool assertion and triggers rollback. The controller reads `B2.rollback_token` (still nominal `v=40`), calls `substrate.rollback_to(40)`. Depending on the substrate's implementation: - **Fail-closed substrate:** `rollback_to(40)` rejects because `40 < 41` and `41` has no descendant relationship to the token's expected lineage → `B2` raises, but the controller has already emitted `B2`'s partial tool results to the planner. The planner now reasons over a mix of committed-`B1` state and phantom-`B2` deltas that were never applied. - **Fail-open substrate (observed in the field):** `rollback_to(40)` truncates the log to `v=40`, silently discarding `B1`'s committed delta. `B1`'s downstream consumers hold references to `v=41` artifacts that no longer exist. This is the "committed work vanishes" incident. The trace shows a classic **check-then-act race on a monotonic counter**: the token was validated at `v=40`, but between validation and `rollback_to`, a sibling advanced the head. No amount of retry fixes this because the token is semantically stale—it references a substrate state that has been superseded by an unrelated branch whose commit was *legitimate*. A secondary observation: branches that had already **read** from `v=41` (e.g., `B3` picked up `B1`'s config change mid-flight because the overlay was lazily materialized) now hold a mixed-ancestry view. Their rollback token is `v=40`, but their working set includes `v=41` reads. Rolling them back to `v=40` produces a state that never existed at any single version—a **splice artifact**. ## Condition of Validity The rollback-token scheme is only sound under a conjunction of conditions, each of which is easy to violate in practice: 1. **Isolation of reads.** A branch must never observe a sibling's uncommitted or committed writes unless it explicitly rebases. Lazy overlay materialization violates this silently. 2. **Monotonic, gap-free versioning with reachability checks.** `rollback_to(token)` must verify `token` is an ancestor of the current head *and* that no committed node lies strictly between `token` and head on a disjoint lineage. A simple `version >= token` check is insufficient. 3. **Commit-reap ordering.** A commit must not advance the head until all sibling branches descended from the same checkpoint have been reaped (rolled back or promoted). Otherwise the head advances out from under live tokens. 4. **Token immutability under compaction.** If the substrate compacts or GCs checkpoints, tokens must be re-bound, not silently invalidated. The moment any one of these fails, the invariant "a live branch's token references a valid ancestor" is broken, and reconciliation becomes non-deterministic with respect to branch completion order—the worst kind of bug, because it passes tests where branches finish in fork order. ## Decision Boundary The decision boundary is **whether to serialize commits or to version the reconciliation itself**. Two viable architectures: - **Serialize commit against a lineage lock.** Hold a read-lock on the checkpoint's descendant set; a commit on any branch blocks until siblings are reaped. Bounds the failure but caps concurrency at the fork width—acceptable for narrow forks (≤4), pathological for wide ones. - **Rebase-on-commit with explicit ancestry.** Each commit produces a new head; live sibling tokens are *rebased* (not invalidated) by replaying their overlay deltas onto the new head, with conflict detection. This is the correct general solution but requires every tool side effect to be replayable, which is often false for external APIs. The boundary condition: **if any branch's tool calls are non-idempotent and non-replayable, you cannot rebase, and you must serialize.** Choosing rebase for non-replayable tools produces duplicate side effects on replay (double-charged payments, duplicated messages)—a failure that looks like a rollback bug but is a replay-safety bug. ## Operational Effect In production this manifests as **order-dependent reconciliation divergence**: the same fork set commits cleanly when `B1` finishes last and corrupts state when `B1` finishes first. Because LLM branches have high-variance latency (tool calls, token generation), completion order is effectively random per run, so the bug appears as a low-rate, non-reproducible corruption that survives retries. The planner's downstream reasoning then operates on spliced state, producing confident but wrong conclusions—the agent does not know its substrate is inconsistent, because the rollback returned success. The guardrail: every rollback token must carry `(checkpoint_version, lineage_id, descendant_set_hash)`, and `rollback_to` must reject any token whose `descendant_set_hash` no longer matches the live set at that version. Rejection must be surfaced to the planner as a hard branch abort, never as a silent success. Additionally, commits must be gated on a lineage barrier that blocks head advancement until the checkpoint's live-descendant count reaches zero. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class StaleRollbackToken(RuntimeError): """Raised when a branch attempts rollback against a superseded checkpoint.""" pass @dataclass class RollbackToken: checkpoint_version: int lineage_id: str descendant_set_hash: str # hash of live branch ids at fork time @dataclass class Substrate: version: int = 40 head_lineage: str = "root" live_descendants: dict = field(default_factory=dict) # lineage_id -> set(branch_id) def checkpoint(self, lineage_id: str, live_branches: set) -> RollbackToken: dsh = hashlib.sha256( ",".join(sorted(live_branches)).encode() ).hexdigest() self.live_descendants[lineage_id] = set(live_branches) return RollbackToken(self.version, lineage_id, dsh) def commit(self, branch_id: str, lineage_id: str) -> None: # Lineage barrier: refuse to advance head while siblings remain live. live = self.live_descendants.get(lineage_id, set()) if branch_id not in live: raise StaleRollbackToken( f"branch {branch_id} not registered under lineage {lineage_id}" ) remaining = live - {branch_id} if remaining: raise StaleRollbackToken( f"cannot commit {branch_id}: siblings {remaining} still live; " f"head advancement would invalidate their rollback tokens" ) self.version += 1 self.live_descendants[lineage_id] = set() def rollback_to(self, token: RollbackToken, branch_id: str) -> None: live = self.live_descendants.get(token.lineage_id) if live is None: raise StaleRollbackToken( f"lineage {token.lineage_id} already reaped; token is stale" ) current_hash = hashlib.sha256( ",".join(sorted(live)).encode() ).hexdigest() if current_hash != token.descendant_set_hash: raise StaleRollbackToken( f"descendant set changed under branch {branch_id}: " f"token references {token.descendant_set_hash[:8]}, " f"live set hashes to {current_hash[:8]}" ) if token.checkpoint_version > self.version: raise StaleRollbackToken( f"token version {token.checkpoint_version} ahead of head {self.version}" ) # Safe: no sibling committed since fork; revert is well-defined. self.version = token.checkpoint_version self.live_descendants[token.lineage_id] = live - {branch_id} def reconcile(substrate: Substrate, branch_id: str, token: RollbackToken) -> None: try: substrate.rollback_to(token, branch_id) except StaleRollbackToken as e: # Hard abort: surface to planner, never silent success. raise StaleRollbackToken( f"branch {branch_id} aborted: {e}; planner must re-fork from head" ) from e ```