# Why does an instance fork on speculative execution and then silently merge a losing branch into canonical state? **Date of Record:** 2026 December 1 **Scope:** Applies to any multi-agent system where a coordinator spawns speculative branches (parallel agent instances exploring alternative tool-call sequences) and later reconciles them into a single canonical state via rollback or merge. Does not apply to strictly linear single-agent execution or to fan-out patterns where branches never write to shared state. ## Core Distinction There are two ways a speculative branch can "lose." The first is *explicit rejection*: the coordinator evaluates branch outcomes, selects a winner, and discards the rest. This is the well-understood case, and most orchestration frameworks handle it by dropping the losing branch's memory and tool effects entirely. The second is *implicit absorption*: the losing branch's side effects—partial writes, cached tool results, appended episodic memory, mutated scratchpad state—leak into the shared substrate before arbitration completes, and the reconciliation step merges them because it cannot distinguish "produced by a rejected branch" from "produced by the winner." The failure is not that the wrong branch was chosen. The failure is that the losing branch's *artifacts* survive the choice because the rollback boundary was drawn around the branch's *reasoning trace* but not around its *writes*. This distinction matters because the first failure is loud (a rejected branch throws, the coordinator logs it) and the second is silent (the merged state is internally consistent, passes schema validation, and only diverges behaviorally several turns later). ## What Was Observed A coordinator agent was decomposing a code-migration task and spawning three speculative executors against a shared scratchpad object. Each executor received a copy-on-write handle to the scratchpad, ran a bounded tool-call loop (max 12 iterations), and appended `(step, tool, observation)` tuples to a per-branch event log. Arbitration was a scoring pass over the three logs; the highest-scoring branch's log was replayed into the canonical event stream, and the other two were marked `discarded`. The scratchpad was copy-on-write at the *top level* but shallow. Branch B, exploring a rollback-heavy path, called a tool that returned a nested dict (`{"files": {...}, "deps": {...}}`) and mutated `scratchpad["files"]["main.py"]` in place. Because the COW layer only cloned the top-level dict, the nested `files` map was shared by reference across all three branches. Branch B's mutation was visible to Branch A and Branch C immediately, before any arbitration. When arbitration selected Branch A, the replay of A's event log did not overwrite `scratchpad["files"]["main.py"]`—A had never touched that key, so its replay was a no-op on it. The canonical state retained Branch B's mutation. Branch B was marked discarded. Its writes were not. The observable symptom appeared four turns later: the coordinator asked the winning branch to verify its work, and the verifier read `main.py` from the scratchpad, found Branch B's half-applied edit (a syntactically invalid intermediate state B had written before its own rollback), and reported a verification failure against work that Branch A had never done. The coordinator, reasoning correctly from the verifier's output, initiated a re-plan that discarded Branch A's correct result. The traceback was misleading: it pointed at the verifier, not at the reconciliation. The actual defect was that the rollback boundary was defined over *event logs* while the state substrate had a *different aliasing topology* than the logs assumed. ## Condition of Validity The invariant that must hold for speculative execution to be sound is: > For every state object reachable from the canonical substrate, the set of branches that can mutate it must be a subset of the set of branches whose effects are replayed on merge, OR the object must be snapshotted at branch spawn and restored at branch discard. In the observed failure, the first disjunct failed (all three branches could mutate `files` by aliasing) and the second failed (only the top-level dict was snapshotted). The condition of validity is therefore a *reachability* condition, not a *declared-scope* condition. A branch that never *intends* to write a key can still write it if the key is reachable through a shared reference. Copy-on-write must be deep, or the substrate must be immutable, or the merge must be a full replay from a spawn-time snapshot rather than a selective event-log replay. The condition is violated silently whenever the substrate's aliasing graph is coarser than the branch's declared write-set. This is the non-obvious part: the branch's declared write-set is a *statement of intent*, and the substrate's aliasing graph is a *fact about memory*. Reconciliation that trusts the former and ignores the latter will merge losing branches. ## Decision Boundary The boundary between "safe to replay selectively" and "must replay from snapshot" is determined by one question: *can two branches reach the same mutable object through different paths?* - If the substrate is a flat map of immutable values, selective replay is sound. - If the substrate is a nested structure with shared references, selective replay is sound only if the spawn-time snapshot is deep and the discard step restores it. - If the substrate contains objects that are mutated by tools the agent does not control (e.g., a live filesystem, a database handle, a remote MCP resource), selective replay is *never* sound, because the tool's writes are outside the event log's reach. The only correct reconciliation is: spawn against an isolated copy, arbitrate, then apply the winner's *diff* to the canonical substrate as a single atomic operation, with the loser's copy discarded wholesale. The decision boundary is therefore not "how many branches" or "how long they run." It is "what is the aliasing topology of the substrate relative to the branch's reachable write surface." A two-branch speculation over an immutable log is safer than a three-branch speculation over a shared nested dict. ## Operational Effect The effect of getting this wrong is not a crash. It is a *plausible but wrong canonical state* that passes every local check and fails only under downstream verification, at which point the failure is attributed to the verifier or to the winner's reasoning rather than to the merge. In systems that distill episodic memory after each task, the corrupted state is then promoted to semantic memory, and the losing branch's artifacts become permanent priors. The agent does not know it forked; it believes it executed once and succeeded. The guardrail is to make the reconciliation step *fail closed* on aliasing ambiguity: if the substrate's reachability graph from any branch's declared write-set intersects another branch's reachable set, the merge must refuse selective replay and demand a full snapshot restore. This is cheap to check and converts a silent corruption into a loud, addressable error. ```python from dataclasses import dataclass, field from typing import Any class ReconciliationAliasingError(RuntimeError): """Raised when selective replay would merge a discarded branch's writes.""" @dataclass class Branch: branch_id: str declared_write_keys: set[str] event_log: list[tuple[str, Any]] = field(default_factory=list) def reachable_keys(substrate: dict, root: str) -> set[str]: """Walk the aliasing graph from a root key; shallow COW hides these.""" seen: set[str] = set() stack = [root] while stack: key = stack.pop() if key in seen or key not in substrate: continue seen.add(key) value = substrate[key] if isinstance(value, dict): stack.extend(value.keys()) return seen def reconcile( substrate: dict, branches: list[Branch], winner_id: str, deep_snapshot_taken: bool, ) -> dict: winner = next(b for b in branches if b.branch_id == winner_id) losers = [b for b in branches if b.branch_id != winner_id] # The invariant: no loser may be able to reach a key the winner's # selective replay will not overwrite. for loser in losers: loser_reach = set() for key in loser.declared_write_keys: loser_reach |= reachable_keys(substrate, key) winner_replay = winner.declared_write_keys leaked = loser_reach - winner_replay if leaked and not deep_snapshot_taken: raise ReconciliationAliasingError( f"branch {loser.branch_id} can mutate {sorted(leaked)} " f"through aliasing, but winner {winner_id} will not replay " f"those keys; selective merge would absorb discarded writes. " f"Require deep snapshot restore or immutable substrate." ) merged = dict(substrate) for key, value in winner.event_log: merged[key] = value return merged ```