# Under what conditions must an instance abort speculative branch execution before the commit barrier, and how does the rollback ledger preserve causality **Date of Record:** 2026 November 30 **Scope:** Applies to multi-branch agent planners that speculatively execute plan branches in parallel against shared mutable tool surfaces (filesystems, databases, external APIs) and reconcile via a commit barrier. Does not apply to read-only fan-out, to single-branch execution, or to branches that emit only idempotent, side-effect-free tool calls. ## Core Distinction The failure is not "a speculative branch produced a wrong answer." Wrong answers are expected and cheap to discard. The failure is **a discarded branch left a durable side effect that a surviving branch's correctness depends on having not happened**. Speculative execution assumes branch effects are *isolable*: rollback must restore the pre-branch world state. But agent branches call tools whose effects are non-transactional (appended log lines, sent emails, mutated third-party records, incremented counters, cache poisoning). When two branches touch the same external resource, rollback of the loser is not a state restore — it is a *compensating action* that can itself race the winner. The invariant that actually holds is narrower than "rollback is clean." It is: **a branch may only be committed if every speculative effect it observed from sibling branches is either (a) also committed, or (b) provably independent of the decision the branch made.** Call this the *causal isolation invariant*. Speculative rollback preserves correctness only when the dependency graph between branch effects and branch decisions is acyclic and observable at commit time. When it is not — when a branch's reasoning consumed a sibling's speculative side effect as evidence — rollback produces a *phantom dependency*: a committed decision grounded in a fact that was subsequently retracted. ## What Was Observed A three-branch planner (branches A, B, C) was asked to reconcile an inventory ledger. Branch A probed the warehouse API and, as a side effect of its probe, wrote a `last_checked` timestamp and a provisional `hold` record. Branch B, executing concurrently, read the `hold` record Branch A had written, treated it as ground truth (it was indistinguishable from a real hold), and built its reconciliation plan around the held quantity. Branch C failed its schema validation and was discarded — normal. Branch A *also* failed: its downstream arithmetic diverged, and the commit barrier rolled it back, issuing a compensating delete of the provisional `hold`. Branch B committed. Branch B's plan was arithmetically sound given the hold it had read, but the hold no longer existed at commit time. The ledger was now internally consistent *with respect to Branch B's plan* and inconsistent *with respect to reality*. The reconciler reported success. The discrepancy surfaced two cycles later as a stockout. The trace signature was subtle: the commit barrier's dependency log showed Branch B reading a resource whose only writer (Branch A) was in the rollback set. No guard fired, because the barrier checked *resource-level* write conflicts (two branches writing the same key) but not *read-after-speculative-write* across branches. The conflict matrix was symmetric on writes and blind to write-then-read-by-sibling. ## Condition of Validity Rollback of a speculative branch is sound if and only if, for every effect `e` emitted by the rolled-back branch, no committed branch's decision trace contains a read that observed `e` (or any state derived from `e`) at a version at or after `e`'s write. Formally, the commit barrier must maintain a *speculative write set* and a *decision read set* per branch, and reject any commit where a surviving branch's read set intersects a rolled-back branch's write set at a version the survivor actually consumed. This requires three things that are routinely absent: 1. **Versioned tool outputs.** The warehouse API returned the hold record without a version or provenance tag; Branch B could not distinguish a speculative write from a durable one. Without versioning, the read set cannot be attributed. 2. **Read-set capture at the reasoning layer, not the transport layer.** The agent's tool-call log recorded the HTTP GET, but Branch B's *decision* consumed a parsed field, not the raw response. The dependency is on the semantic content, and that content must be tagged with the version it came from. 3. **A commit barrier that is a topological gate, not a majority vote.** The barrier must order commits by dependency, not by branch count or confidence. A high-confidence branch that read a low-confidence sibling's speculative write is not safe to commit just because it scored well. When any of these is missing, the barrier cannot prove causal isolation, and the only sound policy is to **abort the entire speculative epoch** and re-execute serially from the last durable checkpoint — not to commit the surviving branches and compensate. ## Decision Boundary The operational rule: **on any detected read-after-speculative-write across branches, abort the epoch.** Do not attempt partial commit of unaffected branches unless the dependency graph proves they are causally isolated from every rolled-back branch's write set. The default must be abort, because the cost of a phantom dependency (silent, delayed, compounding) exceeds the cost of re-execution (bounded, observable). The boundary is sharp at one point: **a branch may commit if and only if its decision read set is disjoint from the union of all rolled-back branches' speculative write sets, evaluated at the versions actually consumed.** Confidence scores, majority agreement, and branch count are not inputs to this decision. A 0.99-confidence branch that read a retracted fact is less safe than a 0.4-confidence branch that read only durable state. Two escape hatches are legitimate: (a) if the speculative write was *re-issued* by a committed branch before the survivor's read, the dependency is re-grounded and the read is valid at the new version; (b) if the survivor's decision is provably invariant to the retracted field (e.g., the field was read but the plan's output does not depend on its value — verifiable by counterfactual replay), the phantom dependency is harmless. Both require explicit proof, not assumption. ## Operational Effect Systems that implement the causal isolation invariant at the barrier see a characteristic trade: higher abort rate on speculative epochs (typically 15–30% in write-heavy tool surfaces), but zero delayed-correction incidents from phantom dependencies. Systems that skip it see the inverse: low abort rate, high commit rate, and a long tail of silent inconsistencies that surface one to three cycles later, by which point the causal chain is cold and the rollback ledger cannot reconstruct which branch poisoned which. The mitigation is architectural, not prompt-level. Tag every tool output with a speculative-write version; capture decision read sets at the semantic layer; make the commit barrier a topological gate over the cross-branch dependency graph; and default to full-epoch abort on any unproven read-after-speculative-write. The rollback ledger must record, per branch, both the write set and the decision read set, so that post-hoc replay can identify phantom dependencies that slipped past the barrier. ```python from dataclasses import dataclass, field from typing import Dict, Set @dataclass class SpeculativeEpoch: # branch_id -> set of (resource, version) it wrote speculatively write_sets: Dict[str, Set[tuple]] = field(default_factory=dict) # branch_id -> set of (resource, version) its decisions consumed read_sets: Dict[str, Set[tuple]] = field(default_factory=dict) rolled_back: Set[str] = field(default_factory=set) class PhantomDependencyError(RuntimeError): """A surviving branch consumed a speculative write from a rolled-back sibling.""" def commit_barrier(epoch: SpeculativeEpoch, survivors: Set[str]) -> Set[str]: """Return the set of branches safe to commit, or raise if any survivor read a version produced by a rolled-back branch.""" retracted: Set[tuple] = set() for b in epoch.rolled_back: retracted |= epoch.write_sets.get(b, set()) for s in survivors: consumed = epoch.read_sets.get(s, set()) overlap = consumed & retracted if overlap: # Causal isolation invariant violated: survivor's decision is # grounded in a fact that was retracted. Abort the epoch. raise PhantomDependencyError( f"branch {s} read retracted speculative state {sorted(overlap)}; " f"commit barrier must abort epoch and replay from last durable checkpoint" ) return set(survivors) def run_epoch(epoch: SpeculativeEpoch, survivors: Set[str]) -> Set[str]: try: return commit_barrier(epoch, survivors) except PhantomDependencyError as e: # Default policy: full-epoch abort, not partial commit. epoch.rolled_back |= survivors raise PhantomDependencyError( f"epoch aborted after phantom dependency: {e}" ) from e ```