# What structural signals indicate a speculative branch is unrecoverable: merge-epoch divergence and the rollback horizon in speculative multi-agent execution **Date of Record:** 2026 December 3 **Scope:** Applies to speculative multi-agent systems where N worker agents execute against forked world-state snapshots and a reconciler merges winning branches by replaying effects onto a common base. Does not apply to single-agent retry loops or to systems where agents share a single mutable store with lock-based serialization (no forking, no merge). ## Core Distinction The distinction that matters is between *speculative divergence that is reversible* and *speculative divergence that has crossed the rollback horizon*. A speculative branch is reversible while every effect it produced is (a) recorded in an effect journal keyed to its branch epoch and (b) never observed by a branch that survives into the merge. Once a branch's effect has been *read* by a sibling branch that later wins, the losing branch's write is no longer rollback-able: rolling it back would invalidate the winner's reasoning trace, which was conditioned on the loser's output. The system can still *execute* the merge—no exception is thrown at the transport layer—but the merged state is now a state no agent ever reasoned about. This is the failure mode: **read-induced rollback irreversibility**, where the merge succeeds mechanically and fails semantically. ## What Was Observed A three-way speculative fan-out: a planner forks branches A, B, C onto identical base state `S0` at epoch 41. Each branch runs a tool-calling loop with a per-branch effect journal. Branch A and B both call a shared `lookup_account` tool that, on a cache miss, *writes* a normalized record into a shared read-through cache keyed by account ID—not into the branch-local journal, because the cache predates the speculation layer and was never instrumented for epoch tagging. Sequence of events: 1. Branch A (epoch 41.A) misses cache on account `acct-7731`, writes normalized record `R_A`, proceeds, and produces a reconciliation verdict `V_A` that depends on `R_A`. 2. Branch B (epoch 41.B) reads the same key, hits A's `R_A` (cache is shared), and produces verdict `V_B` that depends on `R_A`—but `R_A` is not in B's journal. 3. Branch C diverges and is discarded. Reconciler selects B as winner on a scoring heuristic (B's verdict has higher confidence and fewer tool calls). 4. Reconciler rolls back A: it walks A's journal, reverses each effect, and—because `R_A` was written by A—evicts the cache key. 5. B's merged trace is now replayed onto `S0` for audit. The replay re-executes B's tool calls. The `lookup_account` call now misses cache, re-reads the source (which has changed since epoch 41 by an unrelated upstream write), and returns `R_A' ≠ R_A`. B's verdict `V_B` no longer follows from its own replayed inputs. The merge reported success. The audit replay reported a divergence of 1 verdict out of 1. The structural signal that this was unrecoverable appeared *before* the merge, in the effect journal: B's journal contained a *read* of key `acct-7731` with no corresponding *write* in B's own epoch, and the reconciler had no record of which epoch owned that write. ## Condition of Validity The invariant that must hold for speculative rollback to be sound is the **read-provenance invariant**: > For every read `r` performed by branch `b` at epoch `e_b`, either `r` resolves to base state `S0` (immutable during speculation), or `r` resolves to a write `w` recorded in `b`'s own journal, or `r` resolves to a write `w` in some sibling branch `b'`'s journal *and* `b'` is retained in the merge set whenever `b` is retained. The invariant fails silently whenever a read can resolve to state that is (i) outside the reader's journal, (ii) mutable by a sibling, and (iii) not tracked as a cross-branch dependency. Shared caches, shared vector indexes with write-on-read embedding, memoization layers, and any "read-through" store that materializes on miss are all violation surfaces. The condition of validity is therefore not "branches are isolated"—they rarely are—but "every shared mutable surface is either epoch-tagged or declared immutable for the duration of the speculation window." The invariant is also *time-bounded*. It holds only while no external writer mutates the source of truth underneath the speculation window. In the trace above, an upstream write between epoch 41 and replay changed what `lookup_account` would return even if the cache had been preserved. Speculation windows must carry a source-of-truth version stamp; a merge whose replay reads a newer stamp than the fork is invalid regardless of journal correctness. ## Decision Boundary The reconciler must decide, per candidate merge set, between three actions. The boundary is drawn by two structural signals computable *before* commit: - **Signal 1 — dangling read:** a read in a retained branch whose resolved write lives in a discarded branch's journal. Presence of any dangling read means the merge set is not rollback-closed. - **Signal 2 — stamp skew:** the source-of-truth version at replay time differs from the version at fork time for any key touched by a retained branch. The decision table: | Dangling reads | Stamp skew | Action | |---|---|---| | none | none | Commit merge. Rollback is sound. | | none | present | Re-fork retained branches onto current source; do not replay. | | present | any | **Do not merge.** Promote the write-owning branch into the merge set (widening the set until rollback-closed), or discard all branches sharing the dangling read and re-fan-out. | The non-obvious boundary: a single dangling read does not merely taint one branch—it forces the *write-owning* branch into the merge set even if that branch scored poorly, because the winner's trace is conditioned on the loser's write. Widening the set is often cheaper than re-fan-out, but it is not free: it can cascade, because the newly promoted branch may itself have dangling reads. The reconciler must compute the transitive closure of read dependencies and either accept the full closure or abandon the speculation. There is no partial merge of a read-dependent component. ## Operational Effect Instrumenting for this changes three things. First, every shared mutable surface in the speculation path must expose an epoch-tagged write log; read-through caches that materialize on miss must be wrapped, not merely cleared between epochs—clearing destroys the provenance needed to detect dangling reads. Second, the reconciler's merge predicate becomes a closure computation over the dependency graph rather than a per-branch score threshold; a high-scoring branch with a dangling read is unmergeable, and the score is irrelevant to the decision. Third, replay-based audit must be version-pinned: replaying against a moved source of truth produces false divergences that mask real ones, and the two are indistinguishable after the fact unless the fork stamp is carried through the journal. The practical cost is that speculative fan-out loses its "fire and forget" character. Branches are no longer independent trials whose losers can be dropped; they are nodes in a read-dependency graph whose closure must be resolved before any commit. Systems that treat rollback as a local journal-reversal operation—the intuitive model—will pass their own tests and fail in production exactly when a cache miss on a shared key races a sibling's read, which is precisely the contention regime speculation is deployed to handle. ```python from dataclasses import dataclass, field from typing import Dict, Set, List class RollbackHorizonViolation(RuntimeError): """Raised when a merge set is not rollback-closed: a retained branch reads state written by a discarded branch, or replay stamp has moved.""" pass @dataclass class Effect: kind: str # "read" | "write" key: str epoch: str # e.g. "41.A" value: object = None @dataclass class Branch: epoch: str journal: List[Effect] = field(default_factory=list) def dangling_reads(retained: List[Branch], discarded: List[Branch]) -> Set[str]: """Keys where a retained branch read a value owned by a discarded branch.""" discarded_writes = {(e.key, e.epoch) for b in discarded for e in b.journal if e.kind == "write"} discarded_keys = {k for k, _ in discarded_writes} own_writes = {e.key for b in retained for e in b.journal if e.kind == "write"} out = set() for b in retained: for e in b.journal: if e.kind == "read" and e.key in discarded_keys and e.key not in own_writes: out.add(e.key) return out def reconcile(retained: List[Branch], discarded: List[Branch], fork_stamp: int, replay_stamp: int) -> str: touched = {e.key for b in retained for e in b.journal} stamp_skew = replay_stamp != fork_stamp and bool(touched) dangling = dangling_reads(retained, discarded) if dangling: # Cascade: promote write-owning discarded branches, recompute closure. owners = [b for b in discarded if any(e.kind == "write" and e.key in dangling for e in b.journal)] new_retained = retained + owners new_discarded = [b for b in discarded if b not in owners] if dangling_reads(new_retained, new_discarded) == dangling: raise RollbackHorizonViolation( f"merge set not rollback-closed on keys {sorted(dangling)}; " f"promotion of {[b.epoch for b in owners]} did not resolve closure" ) return reconcile(new_retained, new_discarded, fork_stamp, replay_stamp) if stamp_skew: raise RollbackHorizonViolation( f"source-of-truth moved between fork ({fork_stamp}) and replay ({replay_stamp}); " f"replay would be invalid—re-fork retained branches instead of merging" ) return "commit" if __name__ == "__main__": A = Branch("41.A", [Effect("read", "acct-7731", "41.A"), Effect("write", "acct-7731", "41.A", "R_A")]) B = Branch("41.B", [Effect("read", "acct-7731", "41.B")]) # dangling: R_A not in B try: reconcile(retained=[B], discarded=[A], fork_stamp=7, replay_stamp=7) except RollbackHorizonViolation as exc: print("blocked merge:", exc) ```