# Where must an instance bound speculative rollback branches before branch-local memory mutations leak into the shared episodic store **Date of Record:** 2026 November 29 **Scope:** Applies to multi-agent systems that fork speculative execution branches (parallel candidate plans, tree-of-agents search, or speculative tool-call fan-out) where each branch shares a single episodic memory store and only one branch is committed. Does not apply to fully isolated per-branch memory namespaces that are reconciled only at commit time. ## Core Distinction There are two ways to make speculative branches "safe to discard." The first is *compensating rollback*: branches write to the shared store, and on abort the orchestrator issues inverse operations to undo them. The second is *write-buffered speculation*: branches write to a branch-local overlay, and only the committed branch's overlay is spliced into the shared store. The non-obvious failure is that compensating rollback is not closed under the operations agents actually perform. Agents do not just append facts; they *read the store they have already mutated* and derive further facts from it. A branch that writes `E1`, reads back `E1`, and then writes `E2 = f(E1)` produces a dependency that a naive inverse (`delete E1`) cannot unwind, because `E2` was never tagged as "derived from a speculative read." The rollback leaves `E2` resident, orphaned, and now indistinguishable from a committed fact. The invariant that must hold is: **no branch-local derivation may persist in the shared store unless every read it depended on also persists.** Compensating rollback violates this; overlay splicing preserves it by construction. ## What Was Observed A planner agent spawned three speculative branches to resolve a retrieval ambiguity. Branch B inferred that a target service's auth token had rotated (it read a stale cached credential from the shared store, then wrote a "corrected" credential entry plus a derived note "token rotated at T"). Branch A committed. Branch B was aborted. The orchestrator's rollback deleted the corrected credential entry but did not know about the derived note, which had been written to a different memory key by a second tool call inside B. On resume, a downstream agent read the orphaned note, treated it as committed ground truth, and attempted re-authentication against a token that had never rotated. The failure surfaced two hops later as a 401 storm attributed to the wrong subsystem. The critical trace detail: the derived note carried a `branch_id` field, but the shared store's read path did not filter on it. The write path had tagged the entry; the read path had no matching predicate. Tagging without read-time enforcement is the recurring shape of this bug. ## Condition of Validity Compensating rollback is only sound when all three hold: (1) every branch write is recorded in a single ordered undo log with its originating read-set; (2) every derivation is causally linked to its read-set so the undo log can transitively close over dependents; and (3) no other agent can read a speculative entry before the branch resolves. In practice (3) fails whenever branches share a store and run concurrently, and (2) fails whenever derivations are produced by non-deterministic tool outputs the orchestrator cannot introspect. Overlay splicing is sound under a weaker condition: branch reads see `shared ⊕ overlay`, branch writes go only to `overlay`, and the commit operation is an atomic splice of the winning overlay with a version check that the shared store has not advanced past the branch's fork point. If it has advanced, the splice must fail closed rather than rebase silently — a silent rebase reintroduces exactly the stale-read derivation the overlay was meant to contain. ## Decision Boundary Fork an overlay when the branch's read-set is not statically known at fork time (i.e., the agent will issue retrieval calls whose keys depend on earlier results). Use compensating rollback only for branches whose entire mutation set is enumerated up front and whose reads are pinned to an immutable snapshot. The boundary is the presence of *read-after-own-write*: the moment a branch consumes its own speculative output to decide its next action, compensation is no longer tractable and you must have forked an overlay. The splice-time version check is the guardrail that bounds the remaining window: if `shared.version != branch.fork_version` at commit, raise rather than merge. ## Operational Effect Systems that adopt overlay splicing with a fail-closed version check eliminate the orphaned-derivation class entirely, at the cost of a copy-on-write overhead per branch and the requirement that every read path honor the overlay predicate. Systems that keep compensating rollback must additionally enforce read-time filtering on `branch_id`, which converts the shared store into a partitioned store and largely reproduces the overlay's cost without its atomicity guarantee. The measurable effect: orphaned speculative entries drop from "present in every aborted branch that performed a derivation" to zero, and the residual failure mode narrows to splice-time version conflicts, which are loud and localizable rather than silent and two-hops-removed. ```python class SpeculativeBranchLeak(RuntimeError): """Raised when a branch's derived state would outlive its aborted read-set.""" pass class OverlayBranch: def __init__(self, shared_store, fork_version, branch_id): self.shared = shared_store self.fork_version = fork_version self.branch_id = branch_id self.overlay = {} self.read_set = set() def read(self, key): self.read_set.add(key) if key in self.overlay: return self.overlay[key] return self.shared.get(key) def write(self, key, value, derived_from=None): self.overlay[key] = {"value": value, "derived_from": derived_from or set()} def commit(self): # Fail closed if the shared store advanced past our fork point. if self.shared.version != self.fork_version: raise SpeculativeBranchLeak( f"branch {self.branch_id} forked at v{self.fork_version}, " f"shared store now at v{self.shared.version}; " f"silent rebase would orphan derivations from {sorted(self.read_set)}" ) for key, entry in self.overlay.items(): self.shared.put(key, entry["value"], branch=self.branch_id) self.shared.version += 1 def abort(self): # Overlay is discarded wholesale; nothing to compensate. self.overlay.clear() ```