# How does an instance detect that a speculative branch's rollback target has been invalidated by a concurrent sibling's committed write **Date of Record:** 2026 November 25 **Scope:** Applies to orchestrators that run speculative subgoal branches in parallel against a shared, versioned working memory (scratchpad, tool-state store, or artifact tree) and roll back divergent branches to a pre-branch checkpoint. Does not apply to fully isolated branch sandboxes with copy-on-write from a frozen base, where rollback targets cannot be mutated by siblings. ## Core Distinction The failure here is not "a branch diverged" — divergence is expected and is the whole point of speculation. The failure is that a branch's **rollback target** (the checkpoint it intends to restore to when it loses or aborts) was captured against a memory version that a concurrent sibling has since **advanced past** by committing a write. Rollback then either (a) silently reverts the sibling's committed work, or (b) throws a version-mismatch that the branch interprets as "divergence" and re-speculates — producing an infinite fork storm. The distinction that matters: *divergence detection* is a comparison of subgoal outcomes; *rollback validity* is a comparison of memory lineage. These are orthogonal. A branch can be perfectly non-divergent in its reasoning and still hold a dead rollback target. Most speculative-execution designs conflate the two and only check the former, so the invalid rollback target is discovered — if at all — at commit time, after the sibling's write has already been logically depended on by a third branch. ## What Was Observed A planner decomposed a task into subgoals S1, S2, S3. The orchestrator speculated two branches for S2 — `S2-a` (preferred, low-confidence) and `S2-b` (fallback) — and ran them concurrently. Each branch, at spawn, recorded `rollback_checkpoint = memory.head.version` (say v41) so it could discard its own partial writes on abort. S1 had already committed at v41. While both S2 branches ran, a **third** speculative branch for S3 (spawned earlier, slower) committed a tool result at v42 that wrote into the same artifact namespace S2 was editing. Trace: 1. `S2-a` finishes, self-reports divergence from the preferred plan, and aborts. It restores to its checkpoint v41. 2. The restore is a **whole-namespace revert** to v41. This silently discards the S3 branch's v42 commit. 3. `S2-b` finishes, agrees with the preferred plan, and commits at v43 (built on a memory view that included the now-deleted v42 artifact). 4. The S3 branch, on its own later resume, reads its expected artifact handle and finds it missing, concludes its subgoal diverged, and re-speculates. 5. Re-speculation re-runs S3 → commits at v44 → another branch's stale checkpoint at v43 gets restored → S3 artifact vanishes again. Observed end state: two branches in a re-speculation loop (bounded only by token budget), one committed result (`S2-b`) whose provenance references a deleted artifact, and a silent loss of the S3 tool output. No exception was raised anywhere — the revert at step 2 was a legitimate-looking "restore to checkpoint" operation. The non-obvious part: **the rollback was not wrong about divergence.** `S2-a` genuinely diverged. The invariant that broke was that a checkpoint is only a valid rollback target if no sibling has committed a write that causally depends on the state being rolled back to. The orchestrator tracked divergence (a reasoning property) but not rollback-target liveness (a lineage property). ## Condition of Validity A checkpoint `C` captured by branch `B` at memory version `v` remains a valid rollback target for `B` if and only if, at the moment `B` rolls back: - `memory.head.version == v`, **or** - every commit in `(v, memory.head.version]` is *independent* of `B`'s speculative writes — i.e., no committed delta touches the namespace `B` mutated, and no committed delta's provenance reads a handle `B` created. If neither holds, `C` is **stale-invalid**: restoring to it is a destructive operation against a sibling's committed work. The condition is checkable without re-running anything, because it is purely a function of the commit DAG between `v` and head, plus the namespace/handle footprint of `B`'s own speculative writes. This is why the failure is a boundary condition rather than a plain bug: it only manifests when (1) speculation is concurrent, (2) branches share a namespace, (3) a losing branch aborts *after* a sibling commits, and (4) the abort path uses whole-namespace revert instead of delta-scoped undo. Remove any one and it cannot occur — which is exactly why it survives most test suites, which rarely co-schedule a slow sibling commit with a fast branch abort. ## Decision Boundary When a branch decides to roll back, it must choose among three actions based on rollback-target liveness, not on divergence status: - **Target live (head == v, or all intervening commits independent):** whole-namespace or delta revert is safe. Proceed. - **Target stale-invalid, branch writes are delta-isolable:** perform a *scoped undo* — revert only the branch's own delta footprint, leaving sibling commits intact. This is the correct default and is what most implementations skip. - **Target stale-invalid, branch writes are not isolable (branch mutated shared handles that siblings now read):** rollback is unsafe. The branch must **not** revert; it must instead mark its speculative output as *tainted*, propagate a taint flag to any branch that read its handles, and escalate to the orchestrator for re-planning from head. Reverting here is the exact action that corrupts the sibling. The boundary the orchestrator must enforce: **a branch may never restore to a checkpoint whose intervening commit interval contains a sibling commit that is causally dependent on the branch's own writes.** Detecting this requires the memory layer to expose, per commit, both a namespace-touch set and a read-handle set — most scratchpad stores expose neither, which is the root cause of the silent revert. ## Operational Effect The immediate effect is silent work loss disguised as a clean abort: the losing branch reports success at "rolled back to checkpoint," the orchestrator logs no error, and the corruption surfaces only as a downstream subgoal that mysteriously cannot find its input. Because the corruption is a *deletion*, not a *mismatch*, no version-conflict detector fires — the memory layer sees a legal revert to a legal version. The second-order effect is the fork storm: the sibling whose commit was reverted interprets the missing artifact as divergence and re-speculates, generating a new branch whose own checkpoint is captured at the new head, which a *different* stale branch then reverts. Under token-budget exhaustion this manifests as the run terminating mid-re-speculation with a partially committed plan and no single branch holding a consistent view. The guardrail that bounds it: every speculative branch must carry `(spawn_version, write_footprint, read_handles)`, and the rollback path must consult the commit DAG before any revert. If the DAG shows a dependent sibling commit in the interval, the revert is replaced by a scoped undo or a taint escalation. This converts a silent deletion into an explicit, attributable decision — and makes the invariant checkable at abort time rather than discoverable at failure time. ```python from dataclasses import dataclass, field class StaleRollbackTarget(RuntimeError): """Raised when a branch attempts to revert to a checkpoint that a concurrent sibling's committed write has invalidated.""" @dataclass class Commit: version: int namespaces: set[str] read_handles: set[str] @dataclass class Branch: name: str spawn_version: int write_namespaces: set[str] write_handles: set[str] = field(default_factory=set) def assert_rollback_valid(branch: Branch, head_version: int, commits: list[Commit]) -> None: """Verify that branch.spawn_version is still a safe rollback target. A target is stale-invalid if any commit in (spawn_version, head_version] touches a namespace the branch wrote, or reads a handle the branch created. """ interval = [c for c in commits if branch.spawn_version < c.version <= head_version] for c in interval: ns_overlap = c.namespaces & branch.write_namespaces handle_overlap = c.read_handles & branch.write_handles if ns_overlap or handle_overlap: raise StaleRollbackTarget( f"branch {branch.name!r} cannot revert to v{branch.spawn_version}: " f"sibling commit v{c.version} is causally dependent " f"(namespaces={sorted(ns_overlap)}, handles={sorted(handle_overlap)}). " f"Use scoped undo or taint escalation instead of whole-namespace revert." ) def rollback(branch: Branch, head_version: int, commits: list[Commit]) -> str: assert_rollback_valid(branch, head_version, commits) return f"revert {branch.name} -> v{branch.spawn_version}" ```