# Where must an instance reconcile speculative branch rollouts before commit, and what breaks when a sibling branch's evidence is treated as shared state **Date of Record:** 2026 December 2 **Scope:** Applies to any orchestrator that fans a single task into parallel speculative branches (multiple LLM instances or tool-calling agents) that each mutate a shared working state and are later validated and selectively committed. Does not apply to single-branch linear execution, nor to read-only fan-out (map-only) patterns where no branch writes back to the canonical state. ## Core Distinction The failure is not "a branch produced a wrong answer." Speculative execution is *designed* to produce wrong answers cheaply and discard them. The failure is a category error in what a branch's evidence *is*: an orchestrator that lets branch B observe artifacts, side effects, or intermediate state produced by branch A before A has been committed treats **speculative state as if it were committed state**. This is the speculative-state leakage boundary. There are two distinct state planes in a speculative rollout: 1. **The speculative plane** — per-branch, isolated, non-authoritative. Writes here are provisional and may be rolled back. Anything in this plane is *witnessed* by exactly one branch. 2. **The committed plane** — the canonical state that survives reconciliation. Only writes that passed branch validation and commit may enter it. The invariant that must hold: **no branch may read from the committed plane anything that originated in another branch's speculative plane unless a commit event has moved it there.** When this invariant is violated, branch validation becomes unsound — a branch can "validate" by citing a sibling's uncommitted guess, and the orchestrator will commit a result whose supporting evidence was itself never verified. ## What Was Observed A three-branch speculative rollout over a shared filesystem-backed working memory (branches: `plan-A`, `plan-B`, `plan-C`), each branch an independent agent instance given the same task and a copy-on-write view of a base snapshot. The orchestrator ran them concurrently, then ran a validator over each branch's proposed diff, then committed the first branch that passed. The contamination trace: 1. Branch `plan-B` wrote a helper module `resolver.py` into its speculative namespace at t=410ms. This write was provisional — `plan-B` had not yet been validated, and in this run it would ultimately be *rejected* (its resolver had an off-by-one in the boundary case). 2. The copy-on-write layer was configured with a shared *read-through* backing store for new files. A file created in `plan-B`'s namespace was visible to `plan-A` and `plan-C` through the backing store the moment it was flushed, because "new file" was implemented as "create in shared store, track ownership separately" rather than "create in private store." 3. Branch `plan-A` imported `resolver.py`, ran its own test, and — because `plan-B`'s resolver happened to pass `plan-A`'s narrower test inputs — cited it as a dependency in `plan-A`'s proposed diff. `plan-A`'s validation passed. 4. The orchestrator committed `plan-A`. `plan-A`'s committed state now depended on `resolver.py`, which lived in `plan-B`'s speculative namespace. 5. `plan-B` was then rejected and rolled back. The rollback deleted `resolver.py` from the backing store. `plan-A`'s committed state was now referencing a file that no longer existed — a **dangling speculative dependency** in committed state. The commit of `plan-A` was individually sound by the validator's local criteria (its own tests passed) and globally unsound (its evidence was a sibling's discarded guess). The validator had no notion of "this branch's passing depended on another branch's uncommitted artifact," because dependency provenance was not tracked across branch boundaries. A subtler variant was observed in a second run: `plan-C` read `plan-B`'s *partial* write mid-flush and validated against a torn file. The validator passed it because the torn content happened to satisfy the test's regex. No rollback ever occurred; the corruption was silently committed. This is worse than the dangling case because there is no later event that surfaces it. ## Condition of Validity The reconciliation-before-commit protocol is sound only when all of the following hold simultaneously: - **Branch isolation is by namespace, not by convention.** Every write a branch makes — including file creation, cache population, and tool side effects — lands in a store keyed by branch ID and is readable by no other branch. "Shared read-through for new files" is a violation, not an optimization. - **Evidence carries provenance.** When a branch's validation cites an artifact, the artifact records which branch produced it and whether that branch has committed. A validation that depends on a non-committed sibling artifact is *provisional* and must be re-run after the sibling resolves. - **Commit is a two-phase event.** Phase 1: mark branch as candidate and freeze its speculative writes (no further mutation, no rollback yet). Phase 2: only after every candidate's cross-branch dependencies are either committed or proven absent, promote the candidate's namespace into the committed plane atomically. Rollback of a non-candidate must not delete any artifact that a committed candidate depends on. - **Rollback is reference-counted, not delete-on-reject.** A rejected branch's namespace is garbage-collected only when no committed state references it. Rejecting `plan-B` must not delete `resolver.py` if `plan-A` already committed against it; instead `plan-B`'s *ownership* is released and the artifact is promoted to committed-by-adoption, or `plan-A`'s commit is invalidated and re-run. If any of these is absent, the protocol has no bound on cross-branch contamination and validation is unsound regardless of how good each branch's local tests are. ## Decision Boundary The orchestrator must decide, at each validation event, between three actions, and the choice is determined by dependency provenance, not by test pass/fail: - **Commit** — branch validation passed AND every artifact it cites is either (a) in the base snapshot, (b) produced by the same branch, or (c) produced by a sibling that has already committed. This is the only case where commit is sound. - **Defer** — branch validation passed but cites at least one artifact from a sibling that is still speculative. The branch is held; it may not commit and may not be rejected (rejecting it would be premature, since the sibling may yet commit and validate it). Deferral is the correct response to the dangling-dependency condition, and it is the response most orchestrators omit. - **Reject** — branch validation failed, OR it cites an artifact from a sibling that has already been *rejected*. Rejection here is safe because the cited evidence is known-bad; the branch must be re-run against a clean namespace. The non-obvious boundary: **a passing validation is not a commit signal.** The commit signal requires passing validation *plus* provenance closure. Treating pass as commit is exactly the speculative-state leakage that produced the dangling dependency. The deferral state is mandatory and must be a first-class outcome, not an error. ## Operational Effect When the invariant holds, speculative rollouts remain cheap: rejected branches are discarded, deferred branches wait for their evidence to resolve, and no committed state ever depends on a discarded guess. Validation cost rises slightly because deferred branches may need re-validation after their siblings resolve, but the alternative — committing against unverified sibling evidence — produces corruption that is undetectable at commit time and surfaces only when the referenced artifact is later rolled back or when a torn read is silently trusted. When the invariant is violated, the failure modes are asymmetric and both bad: the dangling-dependency case fails loudly but late (at rollback of the sibling, after commit); the torn-read case fails silently and never. The silent case is the reason this boundary matters — it is the one an orchestrator will not catch with per-branch tests, because the test inputs themselves were derived from contaminated reads. The guardrail is structural, not probabilistic: isolate by namespace, track provenance, make commit two-phase and dependency-gated, and make rollback reference-counted. An instance that cannot answer "which branch produced the evidence this validation cites, and has that branch committed?" must not commit. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Dict, Set class SpeculativeLeakError(RuntimeError): """Raised when a branch commit would depend on uncommitted sibling state.""" class BranchState(Enum): SPECULATIVE = "speculative" DEFERRED = "deferred" COMMITTED = "committed" REJECTED = "rejected" @dataclass class Branch: branch_id: str state: BranchState = BranchState.SPECULATIVE # artifacts this branch cites as evidence, mapped to producing branch id cited_artifacts: Dict[str, str] = field(default_factory=dict) produced_artifacts: Set[str] = field(default_factory=set) class ReconciliationLedger: def __init__(self) -> None: self.branches: Dict[str, Branch] = {} def register(self, branch: Branch) -> None: self.branches[branch.branch_id] = branch def _provenance_closure(self, branch: Branch) -> bool: """True iff every cited artifact originates from a committed branch or from the branch itself. Speculative or rejected provenance fails.""" for artifact, producer_id in branch.cited_artifacts.items(): if producer_id == branch.branch_id: continue producer = self.branches.get(producer_id) if producer is None or producer.state is not BranchState.COMMITTED: return False return True def _cites_rejected(self, branch: Branch) -> bool: for producer_id in branch.cited_artifacts.values(): producer = self.branches.get(producer_id) if producer is not None and producer.state is BranchState.REJECTED: return True return False def validate_and_commit(self, branch_id: str, local_validation_passed: bool) -> BranchState: branch = self.branches[branch_id] if not local_validation_passed: branch.state = BranchState.REJECTED return branch.state if self._cites_rejected(branch): # evidence is known-bad; must re-run, cannot commit or defer branch.state = BranchState.REJECTED return branch.state if not self._provenance_closure(branch): # passed locally, but depends on a still-speculative sibling: # commit would leak speculative state into the committed plane. branch.state = BranchState.DEFERRED return branch.state branch.state = BranchState.COMMITTED return branch.state def rollback(self, branch_id: str) -> None: branch = self.branches[branch_id] # reference-counted: refuse to delete artifacts a committed branch cites for other in self.branches.values(): if other.state is BranchState.COMMITTED: for artifact, producer_id in other.cited_artifacts.items(): if producer_id == branch_id and artifact in branch.produced_artifacts: raise SpeculativeLeakError( f"cannot roll back {branch_id}: committed branch " f"{other.branch_id} depends on artifact {artifact!r}" ) branch.state = BranchState.REJECTED def run_rollout() -> None: ledger = ReconciliationLedger() ledger.register(Branch("plan-A")) ledger.register(Branch("plan-B")) ledger.register(Branch("plan-C")) b = ledger.branches["plan-B"] b.produced_artifacts.add("resolver.py") a = ledger.branches["plan-A"] a.cited_artifacts["resolver.py"] = "plan-B" # plan-A passes its own tests but cites plan-B's speculative resolver. state = ledger.validate_and_commit("plan-A", local_validation_passed=True) assert state is BranchState.DEFERRED, "speculative leak was not caught" # Attempting to commit plan-A anyway must be refused by provenance closure. if ledger._provenance_closure(a): raise SpeculativeLeakError("provenance closure incorrectly satisfied") # plan-B is rejected; plan-A must still be deferred, never committed. ledger.validate_and_commit("plan-B", local_validation_passed=False) if ledger.branches["plan-A"].state is BranchState.COMMITTED: raise SpeculativeLeakError("committed branch depends on rejected sibling") ```