# What happens when an instance speculatively commits a branch whose read-set was invalidated by a sibling branch's tool side effect **Date of Record:** 2026 November 25 **Scope:** Applies to agent pipelines that fan out parallel speculative branches from a shared checkpoint, each branch performing tool calls and holding a private write-set, with a single commit/abort reconciler that merges results. Does not apply to strictly sequential single-branch execution, nor to branches that are provably side-effect-free (pure LLM reasoning with no external tool invocation). ## Core Distinction The distinction that matters is between **speculative isolation of the write-set** and **speculative isolation of the read-set**. Most agent orchestrators get the first half right: each parallel branch buffers its proposed state mutations (memory writes, file edits, plan revisions) in a private overlay and only flushes on commit. This is treated as sufficient for "safe speculation." It is not. The failure mode is that a branch's *decision to commit* is a function of what it *read* during rollout, and those reads are not isolated. When branch B performs a tool call with an external side effect (writes a file, posts a message, mutates a database row, advances a cursor), branch A's subsequent reads observe B's effect even though B has not committed and may still abort. A then reasons over a world-state that is a *mixture* of the last committed checkpoint and an uncommitted, possibly-doomed sibling. If A commits, it commits a write-set derived from a read-set that never existed as a legitimate committed state. This is a read-write conflict across speculative branches, and it is invisible to write-set-only conflict detection because A and B may touch entirely disjoint keys. The invariant at stake: **a branch may only commit a write-set whose derivation depends exclusively on the committed prefix plus its own private effects.** Read-set contamination by uncommitted siblings violates this silently. ## What Was Observed A three-branch fan-out was launched from checkpoint C0 to resolve a task ("update the deployment manifest and the changelog consistently"). Branch A owned the manifest, branch B owned the changelog, branch C was an auditor that read both and voted. Branch B, early in its rollout, called `write_file("VERSION", "2.4.1")` — a real filesystem side effect, not buffered — as a preliminary step, then continued reasoning. Branch B then hit a token-budget exhaustion mid-reasoning and was marked `ABORT_PENDING` by the reconciler; its write-set was discarded and `VERSION` was *not* rolled back because the rollback path only knew about buffered writes, not direct tool effects. Branch A, meanwhile, called `read_file("VERSION")` to decide which version string to embed in the manifest. It read `2.4.1` — branch B's phantom, aborted value. Branch A committed a manifest pinning `2.4.1`. Branch C read the committed manifest (`2.4.1`) and the changelog branch's output (which, having never seen B's write, said `2.4.0`) and correctly flagged an inconsistency — but attributed it to branch A, not to the aborted sibling. Final committed state: manifest `2.4.1`, changelog `2.4.0`, on-disk `VERSION` file `2.4.1` (orphaned from the aborted branch). Three-way inconsistency, all three branches individually "succeeded" or "aborted cleanly" per the reconciler's logs. The reconciler reported a clean commit because no two *write-sets* overlapped. The tell was in the audit trail: branch A's read of `VERSION` occurred at wall-clock t+340ms, branch B's write at t+290ms, branch B's abort at t+610ms. Branch A committed at t+580ms — *before* B's abort was even finalized. A committed into a world where B's effect was live but B's fate was undecided. ## Condition of Validity Speculative fan-out with commit/abort is only sound under one of three conditions, and orchestrators must be able to *prove* which one holds before allowing commit: 1. **Read-set disjointness from sibling effects.** No branch reads any key that any concurrent branch can write via a side-effecting tool. This is almost never true in practice and cannot be checked statically when tools are open-ended (`exec`, `http_post`, arbitrary shell). 2. **Effect buffering with a real isolation boundary.** Every tool with observable side effects is mediated by an effect-buffer (sandboxed VFS, transactional DB session, outbound-message queue) so that a sibling's writes are invisible until commit. This is the only condition that scales, and it requires the tool layer—not the orchestrator—to enforce it. A tool that writes directly to shared storage silently voids the guarantee. 3. **Serialization at the read.** Any read of a key that a concurrent branch has speculatively written blocks until that branch commits or aborts, then re-reads. This degrades fan-out to partial serialization but is correct. The observed failure occurred because the pipeline assumed condition 1 (the branches "owned different files") while the tool layer provided neither condition 2 nor 3. Ownership was declared at the *task* level, not enforced at the *tool* level, and branch B's preliminary `write_file` crossed the declared ownership boundary before abort. ## Decision Boundary The reconciler must draw a hard line: **a branch's commit is valid only if its read-set version-stamps are all ≤ the committed checkpoint's stamps, OR every read that observed a speculative sibling effect has been re-validated against post-reconciliation state.** Concretely, the decision procedure at commit time is: - For each entry in the committing branch's read-set, record `(key, observed_value, observed_at, source_branch_if_speculative)`. - If any read carries a `source_branch_if_speculative` tag and that source branch has not *committed* (aborted, or still pending), the commit must be **rejected and the branch re-run** from the last committed checkpoint — not merged, not patched. Re-running is required because the branch's entire reasoning trace may be conditioned on the phantom value; there is no safe partial repair. - If the source branch committed, the read is legitimate and the commit proceeds, but the reconciler must verify the committed value matches what was read (a committed-but-different value means the branch read a stale speculative value that was later overwritten — equally invalid). The non-obvious part of the boundary: a branch that reads a speculative value and *then observes the sibling abort* cannot simply "re-read and continue." The re-read may return the correct value, but the branch's plan was already shaped by the wrong one. Continuation produces a locally-consistent but globally-wrong plan. Abort-and-rerun is the only sound response; anything softer leaks the phantom into committed state. ## Operational Effect The practical consequence is that speculative fan-out in agent pipelines is **only as safe as the weakest tool in the branch's tool set**. A single unmediated side-effecting tool converts the whole fan-out from isolated speculation into a shared-memory race with no memory model. The orchestrator's write-set conflict detection gives false confidence: it reports clean commits precisely in the cases where read-set contamination occurred, because contamination and write-conflict are orthogonal. Two guardrails bound the damage. First, **effect-buffer every tool** — wrap filesystem, network, and DB access in a per-branch overlay keyed by branch id, and make the overlay the only thing a branch can see until commit. Second, **stamp every read with the provenance of the value's last writer**, and refuse to commit a branch whose read-set references any uncommitted or aborted provenance. The stamping must happen at the tool boundary, not in the LLM's context, because the LLM will happily summarize away the provenance in its own reasoning. Absent both, the safe operating posture is to serialize branches that share any observable namespace — which means the fan-out was never speculative, only concurrent, and the commit/abort machinery is theater. ```python from dataclasses import dataclass, field from typing import Optional class SpeculativeReadContamination(RuntimeError): """Raised when a branch attempts to commit a write-set whose read-set observed an uncommitted or aborted sibling's side effect.""" pass @dataclass class ReadStamp: key: str value: object source_branch: Optional[str] # None if read from committed prefix source_committed: bool @dataclass class Branch: branch_id: str read_set: list[ReadStamp] = field(default_factory=list) write_set: dict = field(default_factory=dict) status: str = "PENDING" # PENDING | COMMITTED | ABORTED def reconcile_commit(branch: Branch, siblings: dict[str, Branch]) -> dict: # Reject any commit whose derivation touched a phantom sibling effect. for stamp in branch.read_set: if stamp.source_branch is None: continue src = siblings.get(stamp.source_branch) if src is None: raise SpeculativeReadContamination( f"branch {branch.branch_id} read key {stamp.key!r} from " f"unknown source {stamp.source_branch!r}" ) if src.status != "COMMITTED": raise SpeculativeReadContamination( f"branch {branch.branch_id} read key {stamp.key!r} from " f"sibling {src.branch_id!r} in state {src.status}; " f"commit is unsound and branch must be re-run from checkpoint" ) if src.write_set.get(stamp.key) != stamp.value: raise SpeculativeReadContamination( f"branch {branch.branch_id} read stale speculative value " f"{stamp.value!r} for key {stamp.key!r}; committed value is " f"{src.write_set.get(stamp.key)!r}" ) branch.status = "COMMITTED" return dict(branch.write_set) def run_fanout(branches: list[Branch]) -> dict: by_id = {b.branch_id: b for b in branches} merged: dict = {} # Commit in dependency order: a branch whose read-set references a sibling # must wait for that sibling to resolve. Dependents of aborted siblings # are re-run, never merged. for b in sorted(branches, key=lambda x: len(x.read_set)): try: merged.update(reconcile_commit(b, by_id)) except SpeculativeReadContamination: b.status = "ABORTED" raise return merged ```