# What happens when an instance commits a speculative branch before its sibling branches resolve: the pre-commit visibility leak in parallel multi-agent drafting **Date of Record:** 2026 November 22 **Scope:** Applies to multi-agent pipelines that fan out N parallel drafting branches from a shared parent state, then select/merge and commit one branch (speculative execution with rollback). Does not apply to strictly sequential single-agent chains or to pipelines where branches write to isolated, never-visible staging stores until an explicit barrier. ## Core Distinction The distinction that matters is between *branch isolation* and *branch visibility*. Most parallel-drafting orchestrators implement isolation (each branch gets a forked context and a private scratch buffer) but leak visibility: a branch's side effects—tool calls, memory writes, emitted partial artifacts—become observable to sibling branches, to the parent, or to downstream consumers *before* the selection barrier resolves. This is the speculative-execution analogue of a CPU writing a speculative result to a cache line that another core can read before the branch predictor is validated. The microarchitectural world solved this with store buffers and speculation barriers; agent orchestration frameworks usually have not. The failure is not "a branch produced a wrong answer." It is "a branch that was later rolled back nonetheless mutated state that the committed branch, or the parent, subsequently reasoned over." The rollback of the *branch's own output* succeeds while the rollback of its *observable side effects* silently fails. The invariant that breaks: **a rolled-back branch must be observationally equivalent to a branch that never executed.** ## What Was Observed A three-branch fan-out (planner forks branches A, B, C to draft competing migrations of a schema-change task). Each branch runs an agent loop with tool access to a shared `scratch_memory` vector store and a shared `artifact_registry`. Branch B, while drafting, writes an intermediate note: `"Column X is nullable, so backfill can be skipped."` Branch B is later rolled back because its final draft fails the auditor check (it assumed a constraint that the auditor's replay disproved). Branches A and C are evaluated and A is committed. The commit of A proceeds, but A's final tool call—a `lookup_prior_notes(query="Column X nullability")`—retrieves B's rolled-back note from `scratch_memory` and *inherits the disproven assumption*. A's committed artifact contains the exact defect that caused B's rollback. The auditor, replaying A in isolation, does not catch it because the auditor replays A's *own* trace, and the retrieval of B's note is a nondeterministic vector hit that the replay's frozen retrieval snapshot also happens to include—so the replay agrees with the live run and the defect passes verification. The trace, condensed: 1. Parent forks A, B, C with a shared `scratch_memory` handle (not a copy). 2. B writes `note_B` at step 4; B's branch-local buffer records it as a branch-owned write. 3. B fails audit at step 11; orchestrator calls `rollback(B)`, which deletes B's *output artifact* and decrements the branch counter. 4. `rollback(B)` does **not** delete `note_B` from `scratch_memory` because the memory handle was shared, and the rollback logic only owns artifact-scoped writes, not memory-scoped writes. 5. A at step 9 retrieves `note_B` via semantic search; the retrieved text enters A's context. 6. A commits. The defect is now in committed state, sourced from a branch that no longer exists. The nondeterminism is the retrieval: whether A retrieves `note_B` depends on embedding distance, top-k, and the exact query string A generates, which varies across runs. So the failure is *intermittent by construction*—it appears in roughly the runs where A's query drifts toward B's phrasing. This intermittency is why it survived months of testing: the isolated replay of A is self-consistent, and the shared-memory contamination is invisible to any check that does not model cross-branch visibility. ## Condition of Validity The failure requires all of the following to co-occur; remove any one and the boundary holds: - **Shared mutable substrate across branches.** The branches share at least one write-visible store (memory, registry, cache, message bus) rather than forking a copy-on-write view. A copy-on-write fork with a merge-on-commit step eliminates the class entirely. - **Rollback scoped narrower than the branch's actual write set.** Rollback owns artifacts but not memory writes, or owns "declared" writes but not "incidental" ones (retrieval-cache population, embedding-index insertion, tool-side logging that is itself queryable). - **A retrieval or lookup path that can surface rolled-back content.** This is the load-bearing condition: contamination is only harmful if a surviving branch can *read* the ghost. If branches are write-shared but read-isolated (each branch's retrieval is filtered to its own writes plus the pre-fork snapshot), the ghost is inert. - **Verification replay that shares the live retrieval snapshot.** If the auditor replays against the same frozen retrieval state as the live run, the replay reproduces the contamination and certifies it. Replay must re-derive retrieval from a pre-fork snapshot to be a real check. It does **not** apply when branches are fully isolated (separate process, separate store, merge only at commit) or when the selection barrier is a hard synchronization point that discards all non-selected branch state before any surviving branch reads. ## Decision Boundary The operational decision is where to place the speculation barrier and what rollback must own. Three concrete postures, ordered by cost: 1. **Read-isolation with write-sharing (cheapest, weakest).** Branches may write to a shared store, but every read is filtered by a `branch_id` provenance tag, and the pre-fork snapshot is the only cross-branch-visible content. Rollback deletes branch-tagged rows. This bounds the failure to the case where a branch reads its *own* rolled-back writes—trivial to detect. Cost: provenance tagging on every write, filter on every read. 2. **Copy-on-write fork with merge-on-commit (medium).** Each branch gets a private overlay; commit promotes the overlay to the shared store. Rollback discards the overlay. No ghost is possible because no non-committed write ever reaches shared state. Cost: overlay storage, a commit-merge step that must resolve conflicting writes across branches (its own failure mode). 3. **Hard barrier with full replay (strongest, most expensive).** No branch reads any store written after the fork point until the barrier resolves; the auditor replays each candidate against a pre-fork snapshot. Cost: latency, and the replay must be *causally independent* of the live run's retrieval state or it certifies contamination (see the observed trace). The boundary decision: **if any surviving branch can read any rolled-back branch's writes, posture 1 is the minimum; if the verification replay shares retrieval state with the live run, posture 1 is insufficient and posture 2 or 3 is required.** The common mistake is adopting posture 1 for isolation but leaving the auditor on the live snapshot, which means the contamination is read-isolated in production but *reproduced* in verification—the worst combination, because it passes audit. A secondary boundary: **rollback must be defined over the branch's transitive write set, not its declared write set.** A branch that "only reads" can still contaminate via retrieval-cache population or embedding-index insertion. The rollback contract must enumerate *all* stores the branch touched, and any store not covered must be read-isolated by provenance. ## Operational Effect The observable effect is a committed artifact that is internally consistent, passes replay audit, and is nonetheless wrong because it inherited a disproven assumption from a branch that was rolled back. Because the inherited content is retrieved (not copied) and the retrieval is nondeterministic, the defect is intermittent and does not reproduce under isolated replay. Downstream, the committed artifact propagates the assumption into semantic memory, where it becomes indistinguishable from verified content—the ghost is laundered into durable state. The practical consequence for operators: **speculative rollback is not a deletion; it is a visibility revocation**, and revocation must be enforced at every read path, including the verifier's. A pipeline that deletes rolled-back artifacts but leaves rolled-back memory reads visible has not rolled back—it has hidden the branch's output while leaving its reasoning in the shared context, which is precisely the state a speculative execution engine must never allow. The guardrail is a provenance-tagged store with a `speculation_barrier` that refuses any read of content whose originating branch is not in the committed set, enforced at the retrieval layer and re-checked in the auditor's replay against a pre-fork snapshot. The check below encodes that invariant: a read of a non-committed branch's write raises, and the auditor's replay uses a snapshot that excludes post-fork writes. ```python from dataclasses import dataclass, field from typing import Dict, Set, Optional class SpeculationVisibilityError(RuntimeError): """A surviving branch read content written by a non-committed (rolled-back) branch.""" pass class ReplaySnapshotMismatch(RuntimeError): """Auditor replay used a retrieval snapshot that includes post-fork writes.""" pass @dataclass class WriteRecord: branch_id: str key: str value: str committed: bool = False @dataclass class SpeculativeStore: # All writes, tagged by originating branch. writes: Dict[str, WriteRecord] = field(default_factory=dict) # Branches whose output was committed (survive the selection barrier). committed_branches: Set[str] = set() # Branches that were rolled back; their writes must be invisible. rolled_back_branches: Set[str] = field(default_factory=set) # Fork point marker: writes after this are speculative until barrier. fork_epoch: int = 0 current_epoch: int = 0 def write(self, branch_id: str, key: str, value: str) -> None: self.writes[key] = WriteRecord(branch_id=branch_id, key=key, value=value) def rollback(self, branch_id: str) -> None: # Revoke visibility, not just delete artifacts. Mark all of the # branch's writes as rolled back so any read path refuses them. self.rolled_back_branches.add(branch_id) for rec in self.writes.values(): if rec.branch_id == branch_id: rec.committed = False def commit(self, branch_id: str) -> None: self.committed_branches.add(branch_id) for rec in self.writes.values(): if rec.branch_id == branch_id: rec.committed = True def read(self, reader_branch: str, key: str, *, pre_fork_only: bool = False) -> Optional[str]: rec = self.writes.get(key) if rec is None: return None # Invariant: a rolled-back branch's write is observationally equivalent # to a write that never happened. Any read of it is a visibility leak. if rec.branch_id in self.rolled_back_branches and not rec.committed: raise SpeculationVisibilityError( f"branch {reader_branch} attempted to read {key!r} written by " f"rolled-back branch {rec.branch_id}; speculation barrier violated" ) # A surviving branch reading an uncommitted sibling's write is also a leak # if the barrier has not resolved (pre-fork_only enforces this). if pre_fork_only and rec.branch_id not in self.committed_branches: raise SpeculationVisibilityError( f"pre-fork read of {key!r} by {reader_branch} surfaced uncommitted " f"branch {rec.branch_id}" ) return rec.value def audit_replay(store: SpeculativeStore, candidate_branch: str, keys: list[str]) -> Dict[str, str]: # The auditor must replay against a pre-fork snapshot, NOT the live retrieval # state. If it reads the live store, it reproduces contamination and certifies it. if store.current_epoch != store.fork_epoch: raise ReplaySnapshotMismatch( f"auditor replay at epoch {store.current_epoch} but fork was at " f"{store.fork_epoch}; replay is not causally independent of live writes" ) out: Dict[str, str] = {} for k in keys: v = store.read(candidate_branch, k, pre_fork_only=True) if v is not None: out[k] = v return out # --- failure trace reproduction --- store = SpeculativeStore() store.fork_epoch = 0 store.current_epoch = 0 store.write("B", "note_column_x_nullable", "Column X is nullable; skip backfill.") store.rollback("B") # B fails audit, rolled back store.commit("A") # A is the selected branch # A's surviving loop retrieves B's ghost note -> must raise, not silently inherit. try: store.read("A", "note_column_x_nullable") except SpeculationVisibilityError as e: print("BLOCKED:", e) # Auditor replaying A against the live (post-fork) store would certify the # contaminated result; the guard rejects the replay instead. store.current_epoch = 1 try: audit_replay(store, "A", ["note_column_x_nullable"]) except ReplaySnapshotMismatch as e: print("REPLAY REJECTED:", e) ```