# Why does an instance fork-and-reconcile lose branch lineage when speculative agents share a mutable tool cache **Date of Record:** 2026 November 29 **Scope:** Applies to orchestrators that run multiple speculative agent branches against a shared, mutable side-effect cache (tool result memoization, filesystem scratch, or vector store) and then reconcile by selecting a winning branch and rolling back the losers. Does not apply to branches that execute against fully isolated sandboxes with copy-on-write volumes and no shared memoization layer. ## Core Distinction There are two ways to make speculative multi-agent execution fast: *isolate-then-merge* and *share-then-rollback*. The first gives each branch a private view of every tool result and side effect, then merges the winning branch's writes. The second lets all branches read and write a single shared cache to amortize expensive tool calls (a web fetch, a code execution, an embedding lookup), and on selection it rolls back the losers' writes. The non-obvious boundary is this: **share-then-rollback is only sound if every cache entry carries the identity of the branch graph that produced it, and rollback is a lineage-aware operation rather than a value-aware one.** When a speculative branch reads an entry that a *sibling* branch wrote, the entry's provenance is now cross-branch, but its lineage tag still points at the writer. If the writer loses and is rolled back, the reader's winning branch silently retains a dependency on a value whose producer no longer exists in the committed lineage. The result reconciles *by value* (the bytes are correct) but not *by provenance* (the committed graph has a dangling read). This is the divergence: the winner's output is byte-identical to what a serial execution would produce, yet the audit trail and any downstream re-derivation are broken. ## What Was Observed A three-way speculative planner forked at step 7 of a 15-step task. Branch A and Branch B both needed the same expensive tool call (a paginated API fetch). Branch A executed it first and wrote `cache[key] = payload` tagged `lineage=A`. Branch B, milliseconds later, hit the same key, found it warm, and read the payload — but its own dependency record logged `read(cache[key])` without recording that the *producer* was A. Branch B also wrote a derived summary `cache[summary_key] = f(payload)` tagged `lineage=B`. Branch C executed a cheaper divergent path and won the reconciliation vote (higher confidence on the final answer). Rollback ran: it removed every entry tagged `lineage=A` and `lineage=C`, and kept `lineage=B`'s entries... except B *lost* too. The actual winner was C. So rollback removed A and B, kept C. But C had, at step 11, read `cache[summary_key]` — B's derived entry — because the summary key was content-addressed and B had populated it before C got there. C's read of B's entry was never tagged as a cross-branch dependency. The trace after commit: ``` committed_lineage = {C} retained_entries = {C's writes} dangling_reads = [C.step11 -> summary_key (producer: B, rolled back)] ``` The committed branch C references a cache entry whose producer B was rolled back. The value survived only because rollback was value-scoped ("delete entries whose *tag* is a loser") and C's retained set happened to include the read pointer but the entry itself was deleted. On a later replay of C from its checkpoint, step 11 re-executed the read, found the key cold (B's entry gone), and re-derived a *different* summary — because `f` was a temperature-0.3 LLM call, not a pure function. The replay diverged from the committed output at step 11, and the divergence was only detectable by full re-execution. ## Condition of Validity The invariant that share-then-rollback requires, stated precisely: > For every committed branch `w`, every cache read performed by `w` during speculation must resolve to an entry that is either (a) produced by `w` itself, or (b) produced by a branch in `w`'s committed ancestor set, or (c) re-executable deterministically from inputs that are themselves committed. Cross-branch reads (case where reader `w` reads producer `p`, `p ∉ ancestors(w)`) are legal only if the entry is *promoted*: at reconciliation, every cross-branch read dependency of the winner must be either (1) re-tagged into the winner's lineage, or (2) re-executed and verified equal. A branch that reads a sibling's speculative write and then wins inherits that sibling's entry as a *root* of its own lineage — the entry must be re-parented, not merely retained. The failure occurs exactly when reconciliation treats the cache as a flat key→value map with a `lineage` tag and deletes by tag. That model is value-correct but provenance-blind. The correct model is a dependency DAG where entries are nodes, reads are edges, and rollback is a graph reachability operation from the committed root, not a set-subtraction on tags. ## Decision Boundary Choose share-then-rollback **only** when all of the following hold: - Every cache entry records not just a `lineage` tag but a `producers` set and a `readers` set, and reconciliation computes the retained set as the transitive closure of reads from the committed winner, not as `all_entries - losers`. - Every tool result stored in the cache is either deterministic given its inputs, or is pinned: a non-deterministic entry (LLM output, sampled tool) that any surviving branch read must be *retained regardless of producer lineage*, with its producer branch's full input chain promoted into the committed lineage. You cannot roll back a producer whose output a winner consumed. - The reconciler runs a dangling-read check (`∃ read edge from committed node to deleted node`) before declaring success, and fails closed. Choose isolate-then-merge instead when any tool in the branch is expensive *and* non-deterministic *and* shared across branches — because then promotion is the only safe option and promotion of a non-deterministic producer means you must commit that producer's entire upstream, which usually defeats the purpose of forking. The boundary is not "is the cache shared" but "can a losing branch's non-deterministic output become load-bearing for the winner." If yes, tag-based rollback is unsound and you must either promote or re-execute-and-verify. ## Operational Effect Without the dangling-read check, the system exhibits a *latent replay divergence*: the first execution's committed output is correct, the audit lineage is wrong, and the error surfaces only on checkpoint-resume or audit replay, often hours later and in a different process. The symptom is a branch that "re-derives a different answer on replay," which engineers misattribute to model non-determinism rather than to a rolled-back producer. With the check, reconciliation becomes slightly more expensive (graph closure instead of set subtraction) but the committed lineage is closed under reads, and replay of any committed branch from its checkpoint reproduces the committed output exactly — because every non-deterministic input it consumed is either in its own lineage or was promoted. The guardrail is: **never delete a cache entry that is the target of a read edge from a node you are keeping; instead, promote the entry's producer chain or fail reconciliation.** The code below enforces exactly that. ```python from dataclasses import dataclass, field class DanglingLineageError(RuntimeError): """Raised when reconciliation would commit a branch whose reads resolve to cache entries produced by rolled-back sibling branches.""" pass @dataclass class CacheEntry: key: str producer: str # branch id that wrote this entry deterministic: bool readers: set = field(default_factory=set) @dataclass class Branch: id: str reads: list # list of cache keys read during speculation writes: list # list of CacheEntry keys written def reconcile(winner_id: str, branches: dict, cache: dict) -> set: """Return the set of cache keys to retain. Fail closed on dangling reads. Sound rule: retain the transitive closure of reads reachable from the winner, promoting any non-deterministic producer that a surviving branch consumed. Never subtract-by-tag. """ if winner_id not in branches: raise DanglingLineageError(f"winner {winner_id} not in branch set") retained: set = set() # Seed with winner's own writes. retained.update(branches[winner_id].writes) # Walk the winner's reads; each read must resolve to a retained entry # or be promotable. stack = list(branches[winner_id].reads) seen = set() while stack: key = stack.pop() if key in seen: continue seen.add(key) if key not in cache: # Read of a never-written key: re-executable or a real bug. continue entry = cache[key] retained.add(key) producer = entry.producer if producer == winner_id: continue # Cross-branch read: promote producer's writes and reads. if producer not in branches: raise DanglingLineageError( f"entry {key} read by {winner_id} produced by unknown branch {producer}" ) if not entry.deterministic: # Non-deterministic cross-branch dependency: must promote the # producer's entire input chain, or we cannot guarantee replay. prod = branches[producer] retained.update(prod.writes) stack.extend(prod.reads) else: # Deterministic: retained value is replayable, but we still # keep the entry so the read edge resolves. retained.add(key) # Final invariant: no retained read edge points at a dropped entry. for key in retained: entry = cache.get(key) if entry is None: continue for reader in entry.readers: if reader in {winner_id} and key not in retained: raise DanglingLineageError( f"committed branch {winner_id} reads {key} which is not retained" ) return retained def commit(winner_id: str, branches: dict, cache: dict) -> set: retained = reconcile(winner_id, branches, cache) for key in list(cache): if key not in retained: del cache[key] return retained ```