# Why does an instance lose committed side effects when a speculative branch is rolled back after a checkpoint divergence? **Date of Record:** 2026 November 27 **Scope:** Applies to orchestrated multi-agent systems that execute speculative parallel branches (tentative plans, "what-if" agent forks, or speculative tool-call fan-out) against a shared or partially-shared world state, using checkpoint/rollback for branch reconciliation. Does not apply to purely read-only agents, single-agent linear execution, or systems where every branch operates on a fully isolated copy-on-write sandbox with no external effect surface. ## Core Distinction There are two different things an agent system calls "state," and rollback treats them identically when it must not: - **Replayable state** — the context window, scratchpad, message log, and tool-call transcript. This is reconstructible from the checkpoint because the agent process owns it and can replay it deterministically (modulo sampling). - **Committed effect state** — anything a branch caused in the world outside the agent's own address space: a row written to a database, an email sent, a file created in a shared volume, a payment API called, a message published to a queue, a cache key set that a *sibling* branch will later read. The failure mode is not "rollback is buggy." It is that **rollback is defined over replayable state but is applied to a system whose branches produce committed effects that are not in the checkpoint's address space.** When a speculative branch is discarded after divergence, its replayable state vanishes cleanly, but its committed effects persist — and worse, they persist *into the reconciliation window where sibling branches are still reading the shared surface*. The surviving branch then reasons over a world that reflects a plan that was never adopted. ## What Was Observed A planner agent emits three speculative branches for a task ("reconcile customer record"). Each branch runs a sub-agent against a shared Postgres instance and a shared scratch KV store. Branches are forked from checkpoint `C0` at step 4. The orchestrator runs them concurrently, then reconciles by choosing branch B2 and rolling back B1 and B3. The trace: 1. `C0` taken. All three branches fork. Each branch's context is an independent copy; the database and the KV store are **shared**. 2. B1 executes `UPDATE customers SET status='hold' WHERE id=42` and writes `kv["plan"]=B1` at step 6. It then diverges (its verifier fails at step 9). 3. B3 executes `UPDATE customers SET status='closed' WHERE id=42` at step 7 and writes `kv["plan"]=B3`. It also diverges at step 10. 4. B2, the chosen branch, reaches step 11 and reads `customers.status` for id=42 expecting the value it wrote at step 5 (`'active'`). It reads `'closed'` — B3's effect, applied after B2's checkpoint but before B2's read. 5. Orchestrator reconciles: selects B2, calls `rollback(C0)` for B1 and B3. Replayable state for B1/B3 is discarded. **The two `UPDATE`s are not undone** — they were never in the checkpoint's scope, because the checkpoint captured agent context, not database row versions. 6. B2 continues to step 14, where its policy says "if status was active, send reactivation email." Status is `'closed'`, so it skips. The committed effect of a rejected branch silently rewrote the decision of the accepted branch. The non-obvious part: the rollback *reported success*. There was no error, no divergence flag, no reconciliation mismatch. The system's invariant — "after reconciliation, the surviving branch sees the world as of its own last commit" — was violated without any component observing the violation, because no component was charged with observing it. A second, subtler instance: B1 and B3 both wrote `kv["plan"]`. Reconciliation rolled back B1 and B3's *contexts* but the KV key retained B3's value. A later re-planning pass in the same task read `kv["plan"]=B3` and re-derived a plan the orchestrator had explicitly rejected. The rejection was recorded in the orchestrator's log but not in the shared surface the next agent read. ## Condition of Validity The invariant that must hold for speculative rollback to be sound: > **Effect isolation invariant.** For any branch B rolled back from checkpoint C, every committed effect of B that is visible to any surviving branch must either (a) be reverted to its value at C before any surviving branch reads it, or (b) be provably unread by every surviving branch for the remainder of the task. This holds only when one of the following is true: - **Full effect isolation:** each branch operates on a private copy-on-write view of every shared surface (DB transaction with savepoints, per-branch KV namespace, per-branch outbound queue with a commit gate). Rollback = abort the transaction / drop the namespace. This is the only unconditionally safe configuration, and it is expensive. - **Read-set discipline:** branches declare their read sets up front, and the orchestrator refuses to run a branch whose read set intersects another live branch's write set. This converts the problem into a serializability check and is only sound if read-set declaration is complete — which it is not, because agents discover reads dynamically via tool calls. - **Effect fencing with epoch tokens:** every committed effect is tagged with the branch ID and checkpoint epoch; surviving branches read through a filter that hides effects from rolled-back branches. Requires that the world surface support reads-through-a-filter, which most databases, queues, and external APIs do not. The failure occurs exactly in the gap: branches share a mutable surface, read sets are discovered dynamically, and rollback is defined over context rather than over effects. That gap is the default configuration of most speculative multi-agent harnesses, because full effect isolation is slow and read-set declaration is impossible for open-ended tool use. ## Decision Boundary The operational decision is: **at fork time, classify every surface the branch can touch as isolated, fenced, or shared-mutable, and refuse to speculate across a shared-mutable surface unless you accept effect leakage.** Concretely: - If a branch's tool manifest includes any write-capable tool against a shared surface (DB write, queue publish, outbound HTTP with side effects, shared filesystem write, shared KV write), that branch is **not safely rollback-able**. It may be run speculatively only if the orchestrator commits to *not* rolling it back — i.e., it becomes a serialized branch, not a speculative one. - If a branch is read-only against shared surfaces and write-only against isolated ones, it is rollback-able: rollback = discard context + drop isolated namespace. - The dangerous middle ground — write to shared surface *and* potentially rolled back — must be blocked at admission, not detected at reconciliation, because by reconciliation the effect has already been read by a sibling. The boundary is not "can this branch be rolled back?" but "**can this branch's effects be prevented from being read by a surviving branch before reconciliation?**" If no, the branch must be serialized. Speculation is a privilege granted only to branches whose effect surface is isolated or fenced. A corollary the trace makes explicit: **the orchestrator's reconciliation log is not a shared surface.** Writing "B3 rejected" to the orchestrator's own log does not prevent a later agent from reading B3's KV write. The rejection must be materialized on every surface the next agent reads, or the next agent must be prevented from reading surfaces B3 wrote. ## Operational Effect When the invariant is violated, the observable symptoms are: 1. **Silent decision corruption in the surviving branch.** The accepted branch's downstream behavior depends on state written by a rejected branch. No error is raised; the branch simply takes a different path than it would have under serial execution. This is the hardest failure to attribute, because the surviving branch's transcript looks internally consistent — it read a value and acted on it. 2. **Re-planning loops that resurrect rejected plans.** A rejected branch's writes to shared memory (KV, vector store, scratch notes) become inputs to the next planning pass, which re-derives the rejected plan and re-submits it. The orchestrator rejects it again; the cycle repeats until token budget exhaustion. 3. **Non-reproducible reconciliation.** Replaying the same task with the same seeds produces different outcomes, because the interleaving of shared-surface writes across branches is not captured in any checkpoint and is not deterministic under concurrency. 4. **Audit-trail divergence.** The orchestrator's record says "B2 chose to skip the email because status was active at its last commit," but the database says status was `'closed'` at that moment. Post-hoc audit cannot reconstruct which branch's effect caused the divergence without replaying the entire shared-surface write log, which is usually not retained. The guardrail that bounds all four: **treat the shared surface as a first-class participant in reconciliation, not as ambient infrastructure.** Every branch that touches a shared-mutable surface must register its writes in a per-branch effect ledger at the moment of the write; reconciliation must, for every rejected branch, either revert its ledger entries or mark them as fenced and assert that no surviving branch's read set intersects them. If the assertion fails, reconciliation must fail loudly — the task cannot be completed under the speculative plan and must fall back to serial execution from the last clean checkpoint. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, Set class SurfaceClass(Enum): ISOLATED = "isolated" # per-branch copy; rollback is free FENCED = "fenced" # shared, but reads filtered by branch epoch SHARED_MUTABLE = "shared_mutable" # shared, no read filter; rollback leaks class SpeculationAdmissionError(RuntimeError): """Raised when a branch is admitted for speculative execution but its effect surface cannot be rolled back without leaking into siblings.""" @dataclass class Branch: branch_id: str checkpoint_epoch: int write_surfaces: Set[str] = field(default_factory=set) read_surfaces: Set[str] = field(default_factory=set) rolled_back: bool = False class SpeculationGate: def __init__(self, surface_classes: Dict[str, SurfaceClass]): self.surface_classes = surface_classes self.live_branches: Dict[str, Branch] = {} self.effect_ledger: Dict[str, Set[str]] = {} # surface -> branch_ids that wrote def admit(self, branch: Branch) -> None: for surface in branch.write_surfaces: cls = self.surface_classes.get(surface, SurfaceClass.SHARED_MUTABLE) if cls is SurfaceClass.SHARED_MUTABLE: raise SpeculationAdmissionError( f"branch {branch.branch_id} writes shared-mutable surface " f"{surface!r}; it cannot be speculatively rolled back. " f"Serialize this branch or isolate the surface." ) self.live_branches[branch.branch_id] = branch for surface in branch.write_surfaces: self.effect_ledger.setdefault(surface, set()).add(branch.branch_id) def reconcile(self, keep: str, drop: Set[str]) -> None: for bid in drop: branch = self.live_branches.get(bid) if branch is None: continue branch.rolled_back = True for surface in branch.write_surfaces: cls = self.surface_classes[surface] if cls is SurfaceClass.ISOLATED: continue # namespace dropped with the branch if cls is SurfaceClass.FENCED: continue # reads filtered by epoch; effect invisible # SHARED_MUTABLE should never reach here (blocked at admit), # but if surface classification changed mid-run, fail closed. raise SpeculationAdmissionError( f"rollback of {bid} would leak effects on {surface!r} " f"into surviving branch {keep!r}" ) # Verify no surviving branch reads a surface a dropped branch wrote # through a non-isolated path. survivor = self.live_branches[keep] for surface in survivor.read_surfaces: writers = self.effect_ledger.get(surface, set()) leaked = {w for w in writers if w in drop} if leaked and self.surface_classes[surface] is not SurfaceClass.FENCED: raise SpeculationAdmissionError( f"survivor {keep!r} reads {surface!r} written by rolled-back " f"branches {leaked}; reconciliation is unsound" ) def run_speculative_round( gate: SpeculationGate, branches: list, keep: str, ) -> None: for b in branches: gate.admit(b) # raises SpeculationAdmissionError on unsafe surface gate.reconcile(keep=keep, drop={b.branch_id for b in branches} - {keep}) ```