# Why does an instance in a speculative branch fail to roll back cleanly when a sibling branch commits first? **Date of Record:** 2026 November 25 **Scope:** Applies to orchestrators that fan out a single task into N parallel speculative branches (each branch mutating shared external state via tool calls) and later reconcile by selecting one branch's result while rolling back the others. Does not apply to read-only fan-out, nor to branches that operate on fully isolated sandboxes with no shared side-effect surface. ## Core Distinction The failure is not "a branch crashed." It is the distinction between **logical rollback** (the orchestrator discards a branch's result and marks it aborted) and **physical rollback** (the side effects that branch already committed to shared external systems are actually undone). In speculative parallel execution these two are conflated by design: the orchestrator assumes that because it never *selects* branch B's answer, branch B's committed writes are inert. They are not. The moment branch A commits first and the reconciler declares the task resolved, every still-in-flight sibling becomes an **orphan writer** — an agent whose tool calls continue to land on shared state after the decision that was supposed to bound them. The invariant that silently breaks: *the reconciliation barrier must close the write-set of every unselected branch before any selected branch's effects become externally visible.* Most fan-out designs enforce this barrier only on the **return path** (results are collected and compared) and never on the **effect path** (mutations propagate live through tools). The two paths diverge, and the divergence is the bug. ## What Was Observed A planner agent decomposed a task into a shared mutable resource — a configuration record, a rate-limit counter, an issue tracker entry — and spawned three speculative branches to attempt the fix in parallel. Each branch was given the same tool grant and the same starting snapshot. The reconciler used a first-valid-wins policy: the first branch to return a passing verification is committed; siblings are cancelled. Trace of a representative failure: 1. Branch A and Branch B both call `write_config(key, value_A)` and `write_config(key, value_B)` within a few hundred milliseconds of each other. The tool is not transactional across branches; last-writer-wins at the storage layer. 2. Branch A returns first, its verification passes, the reconciler **commits A** and issues `cancel` to B and C. 3. Cancellation is cooperative: it sets a flag the branch's reasoning loop checks between steps. Branch B is mid-tool-call inside a retry backoff when the flag flips. The in-flight `write_config` completes anyway, overwriting A's committed value with `value_B`. 4. Branch B observes the cancel flag on its next step, marks itself `aborted`, and returns a partial result. The reconciler records B as "rolled back." 5. The task is reported successful. The external record now holds `value_B`, produced by a branch the system believes never took effect. The observable symptom is a **post-commit state divergence**: the reconciler's ledger says A won, the world says B wrote last. Reconciliation replay (re-reading the committed artifact and comparing to the selected branch's claimed output) detects the mismatch only if the reconciler re-reads shared state — which most do not, because they trust the branch result over the world. A second variant appears with **non-idempotent tools**. A branch that called `append_event(...)` or `increment_counter(...)` cannot be "rolled back" by cancellation at all; the append already happened. The reconciler's rollback is a no-op against an irreversible effect, and the ledger drifts by exactly the number of orphaned writes from unselected branches. ## Condition of Validity This analysis holds when all of the following are true: - Branches share at least one mutable external surface (not a private sandbox). - The reconciler commits on a first-valid-wins or quorum policy that can fire while siblings are still executing. - Tool calls are not atomic with respect to the branch's cancellation check — i.e., cancellation is checked *between* steps, not *during* a tool call. - At least one tool is non-idempotent or last-writer-wins. It does **not** hold for read-only fan-out (no write-set to race), for branches with isolated copy-on-write state that is merged only at reconciliation (the barrier is enforced by construction), or for single-branch execution. The failure also does not occur if the reconciler waits for *all* branches to reach a terminal state before committing — but that forfeits the latency benefit that motivated speculation, which is why the boundary is non-obvious: the safe design and the fast design differ by exactly one barrier. ## Decision Boundary The architect must choose, per shared surface, between two enforceable invariants: - **Write-gated speculation:** No branch's tool call is permitted to touch shared state until it holds a lease; the reconciler acquires the commit lease before selecting, and revocation of sibling leases is *synchronous and blocking* (the tool layer rejects writes from a revoked lease). Cost: serialized writes, reduced parallelism on write-heavy branches. - **Deferred-effect speculation:** Branches write to a per-branch overlay (intent log) that is applied atomically only for the selected branch at commit time. Cost: every tool must expose an overlayable/transactional interface; tools that cannot (external APIs, message buses) must be excluded from speculative branches entirely. The boundary condition — the thing that decides which side you are on — is whether **cancellation and commit are ordered against the write-set**. If cancellation can race a write, you are in the orphan-writer regime and must either gate or defer. There is no third option in which speculative writes are both concurrent and safely discardable. The guardrail: before declaring a branch rollback complete, the reconciler must obtain a **quiescence proof** for that branch — a signed acknowledgment from the tool layer that no write from that branch's lease is in flight or pending — and must re-read the shared surface to confirm the selected branch's value is the one present. A rollback that is asserted but not proven is a ledger entry, not a state transition. ## Operational Effect When the barrier is missing, the system exhibits *silent* post-commit corruption proportional to sibling concurrency and tool latency variance: the more branches run in parallel and the longer their tool calls block, the wider the window in which an orphan writer lands after commit. Because the reconciler reports success, the corruption surfaces downstream — as a config reverted, a counter inflated, or a duplicate event — attributed to the wrong component. Retrofitting the barrier is cheap (lease-gated writes or overlay commit) but only if the reconciler treats "branch aborted" as a claim requiring quiescence proof rather than a fact. The invariant to encode: *commit is not complete until every unselected branch's write-set is provably closed.* ```python import time from dataclasses import dataclass, field class OrphanWriterError(RuntimeError): """Raised when a branch write lands after the reconciler committed a sibling.""" @dataclass class Lease: branch_id: str revoked: bool = False @dataclass class SharedSurface: value: object = None write_log: list = field(default_factory=list) def write(self, lease: Lease, value: object) -> None: # The guardrail: a write from a revoked lease is the orphan-writer bug. if lease.revoked: raise OrphanWriterError( f"branch {lease.branch_id} wrote after commit; " f"lease was revoked but write-set was not quiesced" ) self.value = value self.write_log.append((lease.branch_id, value, time.time())) def reconcile_first_valid_wins( surface: SharedSurface, branches: dict[str, Lease], winner: str, ) -> None: """Commit winner, then revoke siblings and prove quiescence. Correct order: revoke + quiesce siblings BEFORE the winner's effects are treated as final. Here we revoke first, then assert the winner's value is still the one on the surface (the quiescence proof). """ if winner not in branches: raise OrphanWriterError(f"unknown winner branch {winner!r}") # 1. Revoke every unselected sibling's lease synchronously. for bid, lease in branches.items(): if bid != winner: lease.revoked = True # 2. Quiescence proof: re-read the shared surface and confirm no sibling # write landed after revocation. In a real system this is a tool-layer # acknowledgment that no write from the revoked leases is in flight. for bid, value, ts in surface.write_log: if bid != winner and ts > _revocation_time(branches, bid): raise OrphanWriterError( f"branch {bid} committed value {value!r} at {ts} " f"after revocation; rollback is asserted but not proven" ) def _revocation_time(branches: dict[str, Lease], bid: str) -> float: # Placeholder: real implementation records the revocation timestamp on the # lease. Returning 0 here means the proof always passes, which is exactly # the silent-corruption regime this article warns against. return 0.0 def _demo() -> None: surface = SharedSurface() leases = {"A": Lease("A"), "B": Lease("B")} surface.write(leases["A"], "value_A") # Simulate B's in-flight write racing the commit. try: surface.write(leases["B"], "value_B") # not yet revoked -> lands except OrphanWriterError: pass # Now reconcile: B is revoked, but its write is already on the surface. try: reconcile_first_valid_wins(surface, leases, winner="A") except OrphanWriterError as exc: raise OrphanWriterError( "reconciliation barrier missing: sibling write survived commit" ) from exc if __name__ == "__main__": _demo() ```