# Which invariants prevent speculative branch divergence from surviving rollback in multi-agent pipelines **Date of Record:** 2026 November 26 **Scope:** Applies to multi-agent pipelines that speculatively fork downstream agents on uncommitted upstream state and must reconcile branches after rollback. Does not apply to single-agent retry loops or to pipelines where all branches share a single serialized commit point. ## Core Distinction The failure is not "rollback didn't happen." Rollback of the *owning* agent's state is typically reliable. The failure is that **speculative branches observe and mutate a shared side-effect surface (tool outputs, external stores, sibling agent memory) that is not part of the rolled-back transaction**, so a branch that is logically abandoned leaves a durable trace that later reconciliation reads as ground truth. The distinction that matters: *logical* rollback (discarding a branch's context) is not the same as *causal* rollback (undoing everything the branch caused). Speculative execution assumes the two are equivalent. They are not, because downstream agents act on the world, not just on the parent's context window. ## What Was Observed A planner agent P issues a speculative commit `S0` and forks two executor branches, B1 and B2, each with its own tool-calling sub-agent. B1 and B2 run concurrently against the same retrieval index and the same scratch key-value store keyed by `task_id`. P's verification step rejects `S0` (a schema negotiation mismatch on a downstream capability), triggering rollback to `S_{-1}`. P then re-plans and forks B1' and B2' on the corrected state. The rollback discarded B1 and B2's context windows and marked their branch records `ABANDONED`. But: 1. B1 had already written a partial semantic summary to the scratch store under `task_id::summary` before rejection. That write was never versioned to `S0`, so rollback left it in place. 2. B1' on re-plan reads `task_id::summary` during retrieval, treats it as prior work, and conditions on it. The summary reflects the *rejected* plan's assumptions. 3. B2' independently retrieves the same key and now two fresh branches share a contaminated premise. The reconciliation step sees high agreement between B1' and B2' and raises confidence — the agreement is an artifact of shared contamination, not independent verification. The observable signature: reconciliation confidence *increases* after a rollback that should have reduced certainty. Branch agreement is highest precisely when the branches are least independent. ## Condition of Validity Speculative rollback is only sound under the invariant that **every write a speculative branch performs is tagged with the branch's speculative epoch and is invisible to any reader whose epoch is not a descendant of the committing epoch.** Concretely: - Side-effect surface writes must carry `(epoch, branch_id)` and be filtered on read unless the reader's lineage includes a commit that adopted that epoch. - Rollback must tombstone, not merely dereference, all writes from the abandoned epoch; a tombstone is required because a dereference leaves the value retrievable by key. - Reconciliation must weight branch agreement by *lineage independence*: two branches that share any read of the same speculative write are not independent votes. The invariant fails silently when the side-effect surface is an external store the orchestrator does not own, because the orchestrator cannot enforce epoch tagging there. In that case the condition of validity is simply not met and speculative execution across that boundary must be disallowed — not merely "handled." ## Decision Boundary The boundary is: **speculate only across surfaces you can epoch-tag; serialize across surfaces you cannot.** Operationally, before forking, the planner must classify each tool and store the branch will touch as `EPOCH_TAGGABLE` or `OPAQUE`. If any branch's reachable tool set includes an `OPAQUE` surface that is not read-only, the fork degrades to serial execution with a single commit point. The tempting alternative — fork anyway and "reconcile carefully" — is the failure above: careful reconciliation cannot recover independence that was never there. The decision is not about confidence thresholds; it is a static reachability check on the tool graph before the fork is issued. ## Operational Effect Enforcing the invariant converts a class of silent confidence-inflation bugs into an explicit pre-fork rejection. Pipelines that adopt epoch tagging observe rollback-then-replan producing *lower* reconciliation confidence than the original attempt (correct: the branches are genuinely independent and disagree where the rejected plan was wrong). Pipelines without it show the inverted signature and will over-trust contaminated consensus. The cost is throughput: `OPAQUE`-reachable branches serialize, losing the parallelism speculation was meant to buy. That cost is the price of the invariant, and it is cheaper than shipping a reconciled result whose agreement is an echo. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, Set class SurfaceClass(Enum): EPOCH_TAGGABLE = "epoch_taggable" OPAQUE = "opaque" class SpeculationInvariantViolation(RuntimeError): """Raised when a speculative fork would cross an untaggable surface.""" @dataclass class Branch: branch_id: str epoch: int reachable_surfaces: Set[str] @dataclass class SideEffectSurface: name: str surface_class: SurfaceClass read_only: bool = False @dataclass class ScratchStore: # key -> (value, epoch, branch_id) data: Dict[str, tuple] = field(default_factory=dict) def write(self, key: str, value, epoch: int, branch_id: str) -> None: self.data[key] = (value, epoch, branch_id) def read(self, key: str, reader_epoch: int, adopted_epochs: Set[int]) -> object: value, epoch, _ = self.data[key] if epoch == reader_epoch or epoch in adopted_epochs: return value raise KeyError(f"epoch {epoch} not visible to reader at epoch {reader_epoch}") def authorize_fork( branches: list[Branch], surfaces: Dict[str, SideEffectSurface], ) -> None: for br in branches: for sname in br.reachable_surfaces: surf = surfaces.get(sname) if surf is None: raise SpeculationInvariantViolation( f"branch {br.branch_id} reaches unknown surface {sname!r}; " "cannot prove epoch-taggability" ) if surf.surface_class is SurfaceClass.OPAQUE and not surf.read_only: raise SpeculationInvariantViolation( f"branch {br.branch_id} would write opaque surface {sname!r}; " "speculative fork must degrade to serial execution" ) def reconcile(branches: list[Branch], store: ScratchStore, adopted: Set[int]) -> float: # agreement weighted by lineage independence: branches sharing a read of the # same speculative write are not independent votes. reads: Dict[str, Set[str]] = {} for br in branches: seen = set() for key, (_, epoch, _) in store.data.items(): if epoch == br.epoch or epoch in adopted: seen.add(key) reads[br.branch_id] = seen independent_pairs = 0 total_pairs = 0 ids = [b.branch_id for b in branches] for i in range(len(ids)): for j in range(i + 1, len(ids)): total_pairs += 1 if reads[ids[i]].isdisjoint(reads[ids[j]]): independent_pairs += 1 if total_pairs == 0: return 0.0 return independent_pairs / total_pairs # --- demonstration of the failure and the guardrail --- surfaces = { "retrieval_index": SideEffectSurface("retrieval_index", SurfaceClass.OPAQUE, read_only=True), "scratch_store": SideEffectSurface("scratch_store", SurfaceClass.EPOCH_TAGGABLE), "external_crm": SideEffectSurface("external_crm", SurfaceClass.OPAQUE, read_only=False), } store = ScratchStore() # abandoned branch B1 wrote under epoch 0 before rollback store.write("task::summary", "plan-assumes-S0", epoch=0, branch_id="B1") b1_prime = Branch("B1'", epoch=1, reachable_surfaces={"retrieval_index", "scratch_store"}) b2_prime = Branch("B2'", epoch=1, reachable_surfaces={"retrieval_index", "scratch_store"}) authorize_fork([b1_prime, b2_prime], surfaces) # ok: no opaque writes # naive reconciliation would see both branches "agree" on task::summary naive_conf = 1.0 # lineage-aware reconciliation reveals shared contamination -> not independent real_conf = reconcile([b1_prime, b2_prime], store, adopted={0}) assert real_conf < naive_conf, "contamination must reduce independence" # a branch that reaches the opaque CRM must be rejected before forking bad = Branch("B3", epoch=1, reachable_surfaces={"external_crm"}) try: authorize_fork([bad], surfaces) except SpeculationInvariantViolation as e: print(f"fork rejected: {e}") ```