# What happens when an instance merges a speculative branch whose side effects were committed to a shared store before the merge decision **Date of Record:** 2026 November 15 **Scope:** Applies to speculative multi-agent orchestration where branch rollouts share a mutable external store (KV cache, vector DB, object store, message bus, or database) and rollback is implemented by discarding the branch's in-memory trajectory. Does not apply to fully sandboxed branches with copy-on-write or transactional isolation guaranteed by the store itself. ## Core Distinction A speculative branch has two distinct kinds of state: **epistemic state** (the agent's reasoning trace, tool-call log, scratchpad, and intermediate context) and **world state** (effects committed to shared infrastructure outside the orchestrator's control plane). Rollback is trivially correct for epistemic state — you drop the trajectory. Rollback is *not* correct for world state unless the store provides a compensating undo. The boundary failure is the silent assumption that "discard the branch" implies "the world is unchanged." It does not. The orchestrator can only roll back what it owns. The non-obvious invariant: **a branch is only safely mergeable or discardable if every side effect it produced is either (a) versioned under the branch ID and garbage-collected on rollback, or (b) reversible by an idempotent compensating action registered at commit time.** Any side effect outside those two classes is a *leaked write*, and leaked writes survive rollback to contaminate the merged branch, sibling branches, and future runs. ## What Was Observed During a fan-out of N=6 speculative branches over a shared retrieval index, branch-3 emitted an "upsert" tool call that wrote a synthesized document into the shared vector store before the merge adjudicator had scored it. The adjudicator rejected branch-3 (lower grounding score than branch-5) and the orchestrator rolled it back by clearing its trajectory and freeing its context window. The write remained. Downstream effects, in order of discovery: 1. Branch-5's subsequent retrieval returned the branch-3 synthetic document and cited it as evidence, inflating its grounding score. The merge selected branch-5, which was now transitively contaminated by the rejected branch. 2. A retry of the same task (new run, same store) retrieved the leaked document again, producing a reproducible but wrong answer with high confidence — the failure was *stable*, which made it look like ground truth during evaluation. 3. The leaked document carried branch-3's provenance metadata, so lineage queries showed a document "produced by" a branch the system's own logs recorded as rolled back. Reconciliation between the audit log and the store diverged. The failure was not detected at merge time. It was detected three runs later when a human noticed a citation to a document no accepted branch claimed to author. ## Condition of Validity This boundary applies when all of the following hold: - Branches execute concurrently against a store with read-your-writes semantics visible to *other* branches (shared namespace, not per-branch namespace). - Rollback is implemented at the orchestrator layer (trajectory discard) rather than at the store layer (transaction abort or namespace drop). - At least one tool available to branches performs non-idempotent or unversioned writes. - Merge adjudication happens *after* branch execution, so writes precede the accept/reject decision. It does **not** apply when the store enforces per-branch isolation (branch-scoped namespaces, snapshot isolation, or copy-on-write), or when all writes are staged and only applied post-merge. In those cases rollback is sound because the world was never mutated. ## Decision Boundary The decision is not "should we allow speculative writes" — that is often necessary for realistic tool use. The decision is **where the commit boundary sits relative to the merge boundary.** - If commit precedes merge (writes go live during rollout), you MUST have compensating rollback per side effect, registered at write time, keyed by branch ID, and executed before the merge is finalized. Absent that, the safe default is to *quarantine* the branch's writes and mark the run degraded rather than claim a clean rollback. - If merge precedes commit (writes staged, applied only for accepted branches), rollback is free and the boundary does not exist. - The dangerous middle ground — writes live, rollback by discard — is only acceptable when the store is read-only for branches or when leaked writes are provably harmless (e.g., append-only telemetry that no branch reads). Rule of thumb: **if a branch can read what another branch wrote, rollback-by-discard is unsound.** Reading is the coupling that turns a private leak into a cross-branch contamination. ## Operational Effect Treating rollback as a discard operation produces failures that are *stable, reproducible, and self-consistent* — the worst class, because they survive retries and masquerade as correct behavior. The observable symptoms are: citations to documents no accepted branch authored, grounding scores that inflate across runs, audit-log/store divergence, and non-determinism that is actually determinism over a polluted store. The mitigation is to make the commit/merge ordering explicit in the orchestrator and to refuse to report a clean rollback when leaked writes exist. The check below enforces that: it fails loudly rather than silently discarding a branch that has un-compensated side effects. ```python class SpeculativeRollbackError(RuntimeError): """Raised when a branch is rolled back by discard while it holds un-compensated writes to a shared store. Rollback-by-discard is only sound when every side effect is versioned or compensated.""" class Branch: def __init__(self, branch_id: str): self.branch_id = branch_id self.trajectory = [] self.side_effects = [] # (store, key, compensator_or_None) def record_write(self, store: str, key: str, compensator=None): self.side_effects.append((store, key, compensator)) def rollback_branch(branch: Branch, store_is_shared: bool) -> None: """ Roll back a speculative branch. Sound only if the branch's writes are either versioned (compensator present) or the store is not shared. """ leaked = [ (store, key) for (store, key, comp) in branch.side_effects if comp is None ] if store_is_shared and leaked: raise SpeculativeRollbackError( f"branch {branch.branch_id} has {len(leaked)} un-compensated " f"writes to shared store: {leaked}. Discard-only rollback would " f"leak these into sibling branches and future runs. Refusing to " f"report a clean rollback." ) # Compensate what we can, in reverse order. for store, key, comp in reversed(branch.side_effects): if comp is not None: comp(store, key) branch.trajectory.clear() branch.side_effects.clear() def merge_or_rollback(branch: Branch, accepted: bool, store_is_shared: bool) -> None: if accepted: # Writes become authoritative; no compensation. branch.side_effects.clear() return rollback_branch(branch, store_is_shared=store_is_shared) ```