# Where must an instance bound speculative branch fan-out before rollback divergence corrupts the shared checkpoint **Date of Record:** 2026 November 26 **Scope:** Applies to orchestrators that fan out N parallel speculative branches from a single fork checkpoint and commit the first branch to pass a verifier, rolling back the rest. Does not cover sequential single-branch retry, nor branches that share no mutable external state. ## Core Distinction The failure is not "a branch produced a wrong answer." It is that **rollback of a losing branch is not the inverse of its execution** once the branch has performed any externally observable side effect or mutated a shared checkpoint segment. Speculative fan-out assumes branch state is a *pure function* of the fork checkpoint plus the branch's own token stream. This assumption holds for pure reasoning and reads, and silently breaks the moment a branch writes to any resource the commit path also reads — a scratchpad file, an MCP tool with non-idempotent semantics, a shared vector store, a downstream agent's inbox. The distinction that matters operationally: **divergence detection is cheap and reliable; divergence *containment* is neither.** An orchestrator can always tell which branches disagree. It cannot, in general, undo the losing branches' effects, because those effects were emitted under the same identity and warrant as the winner. The invariant at stake is *checkpoint isolation*: no branch may mutate state visible to the commit path until it is the sole survivor. ## What Was Observed A planner agent forks 6 branches at checkpoint `C_k` to solve a multi-step retrieval-and-synthesis task. Each branch runs a ReAct loop with tool access: `search`, `write_scratch`, `append_memory`. The verifier scores branches on final-answer entailment against retrieved evidence and commits the top scorer, rolling back the rest by truncating the branch transcript and restoring `C_k`. The trace that broke: 1. Branch 3 (loser) called `append_memory("entity X resolves to Y")` at step 4, before diverging on step 6. 2. Branch 5 (winner) at step 5 called `search("entity X")`, which returned the branch-3-injected memory as a high-confidence hit. 3. Branch 5's final answer was scored correct *because* it inherited branch 3's uncommitted write. 4. Rollback truncated branches 1,2,3,4,6 and restored `C_k` — but `append_memory` is a write to a store outside `C_k`'s snapshot boundary. The memory persisted. 5. Branch 3's content survived with no owning branch, no verification, and no provenance link. On the next task, retrieval surfaced it as ground truth. The verifier reported a clean commit. The rollback reported success (transcript truncation succeeded). Both were locally correct and jointly wrong. The corruption was invisible until a subsequent task's retrieval mismatch traced back to an orphaned memory entry whose originating branch no longer existed in any transcript. A second observed variant: two branches both called a non-idempotent `create_ticket` tool. The winner's ticket was committed; the loser's ticket was also created but never referenced. The rollback left a phantom side effect that a downstream reconciliation agent later treated as a real work item, spawning a second execution path — a *rollback-induced fork*. ## Condition of Validity Rollback-as-truncation is valid **iff** every branch action is either (a) a pure read, (b) a write to a store snapshotted inside the fork boundary and restored atomically with `C_k`, or (c) a write carrying a branch-scoped idempotency key that the commit path can garbage-collect on rollback. The moment a branch invokes a tool with external, non-idempotent, or commit-path-visible effects, the invariant is violated and the orchestrator must not treat truncation as rollback. Concretely, the guardrail is a **capability partition at fork time**: branches receive read-only handles to shared stores and write handles only to branch-local namespaces. Any tool whose effects escape the namespace must be *deferred* — the branch emits an intent record, and only the committed branch's intents are replayed against the real tool after the survivor is chosen. This is the same structural move as a database serializing speculative transactions: you do not let a transaction observe or mutate another's uncommitted writes; you buffer and replay. An agent orchestrator that skips this step has built speculative execution without isolation, which is to say it has built a nondeterministic write amplifier. ## Decision Boundary The boundary is not "how many branches" but **whether any branch can reach a shared mutable resource before survivor selection**. If the answer is no, fan-out width is bounded only by token budget and you may roll back by truncation. If the answer is yes, you must either: - **Defer all escaping effects** behind an intent log replayed only for the committed branch (preferred; preserves parallelism), or - **Serialize** branches that require escaping effects, collapsing the speculative fan-out to width 1 for those subtrees, or - **Snapshot-and-restore** every external store the branch can touch, which is usually infeasible for tool-mediated state. Choosing "roll back by truncation anyway" is the failure. It is chosen because truncation is cheap and *appears* to succeed — the transcript is clean, the checkpoint is restored, and the orphaned effect is invisible until it resurfaces in an unrelated task's retrieval. The decision must be made per-tool at fork time, not per-task at rollback time, because at rollback time the orchestrator can no longer distinguish a branch's reads from its writes. ## Operational Effect With deferred intents and branch-local write namespaces, losers' effects are discarded by construction: the intent log for a non-committed branch is dropped, never replayed. The winner's intents replay in order against real tools, so the commit path sees exactly one coherent sequence of external effects with full provenance. Retrieval stores never absorb uncommitted writes, so cross-task memory poisoning via speculative branches is eliminated at the source rather than detected after the fact. The cost is latency on the deferred-effect path (replay is serialized after survivor selection) and the requirement that every tool be classified as *pure*, *branch-local*, or *escaping* at registration. Tools that cannot be classified must be treated as escaping — the safe default — which forces them behind the intent log. The invariant to enforce and test: **for any fork, the set of external effects observable after commit equals the effect set of the committed branch alone.** Any deviation is a rollback divergence, and it should raise, not warn. ```python class RollbackDivergenceError(RuntimeError): """Raised when rolling back a losing speculative branch would leave externally observable effects that the commit path can still see.""" pass # Tool effect classes. Only PURE and BRANCH_LOCAL are safe to execute # speculatively; ESCAPING tools must be deferred behind an intent log. PURE = "pure" # reads only, no mutation BRANCH_LOCAL = "branch_local" # writes confined to branch namespace, GC'd on rollback ESCAPING = "escaping" # non-idempotent or commit-path-visible mutation def fork_branch(checkpoint, tools, branch_id): """Fork a speculative branch. Refuse to hand out escaping tools.""" handles = {} for name, effect_class in tools.items(): if effect_class == ESCAPING: # Do not grant the live handle; grant a deferred intent recorder. handles[name] = DeferredIntent(name, branch_id) else: handles[name] = LiveHandle(name, branch_id) return Branch(checkpoint=checkpoint, branch_id=branch_id, handles=handles) def rollback(branch, committed_branch_id): """Roll back a losing branch. Must be the exact inverse of its execution.""" if branch.branch_id == committed_branch_id: return # survivor, never rolled back here for name, handle in branch.handles.items(): if isinstance(handle, LiveHandle) and handle.effect_class == ESCAPING: # A live escaping handle was granted at fork time; its effects # cannot be truncated. This is the invariant violation. raise RollbackDivergenceError( f"branch {branch.branch_id} held live escaping handle " f"'{name}'; truncation cannot undo its external effects, " f"and the commit path may already observe them" ) if isinstance(handle, DeferredIntent): handle.discard() # intent log dropped, never replayed branch.truncate_to(branch.checkpoint) # safe: only pure/branch-local effects branch.release_namespace() # GC branch-local writes def commit(survivor, tools): """Replay only the survivor's deferred intents against real tools.""" for intent in survivor.deferred_intents_in_order(): effect_class = tools[intent.tool_name] if effect_class != ESCAPING: raise RollbackDivergenceError( f"intent for non-escaping tool '{intent.tool_name}' should " f"have executed live, not been deferred; provenance is broken" ) intent.replay_against_real_tool() survivor.mark_committed() ```