# Why does an instance diverge from its speculative rollback checkpoint when a peer agent commits a conflicting tool side-effect? **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent systems that run speculative branches in parallel and reconcile by rolling back losing branches against a shared checkpoint. Does not apply to single-agent speculative decoding (token-level) or to stateless fan-out where no rollback is performed. ## Core Distinction Speculative multi-agent execution assumes rollback is a *pure state rewind*: a losing branch discards its working memory and tool results, restores the last committed checkpoint, and re-enters the next round as if its speculation never happened. This holds only when every side-effect produced during speculation is itself reversible or isolated. The non-obvious failure is that rollback restores the *agent's internal state* but cannot un-commit *external tool side-effects* that a peer agent has already observed, depended on, or that landed in shared substrate (a scratch filesystem, a message bus, a vector store, a downstream API). The divergence is not in the agent's memory—it is in the gap between the agent's rolled-back view and the world's partially-advanced view. Reconciliation then fails because the winner's post-commit reasoning is built on a world that includes the loser's ghost writes. ## What Was Observed A three-agent planner/executor/auditor swarm ran a speculative plan: two executor instances (`E1`, `E2`) each proposed and *executed* a candidate tool sequence against a shared workspace, with the auditor to select one. Both branches wrote to the same scratch namespace and appended to a shared event log. The auditor selected `E1`; `E2` was instructed to roll back. `E2`'s rollback restored its context window to the pre-speculation checkpoint and dropped its private tool-result cache. But `E2` had already: (1) written a partial artifact to `shared/scratch/step3.json`, (2) emitted a `tool_call_started` event to the bus that `E1` had subscribed to, and (3) issued a POST to a downstream service that triggered an asynchronous job. Rollback did not reverse any of these because none were tracked as compensable actions—they were classified as "read-only-ish" or "fire-and-forget." The failure trace: 1. `E2` speculates, writes `shared/scratch/step3.json` with a conflicting schema, emits bus event. 2. `E1` reads the shared scratch dir during its own step, observes `E2`'s partial write, and *adapts* its plan to include it (a probabilistic reasoning step that latches onto whatever it sees). 3. Auditor commits `E1`, orders `E2` rollback. 4. `E2` restores context; its own memory now says "step3 never happened." 5. `E1`'s committed plan depends on `E2`'s ghost write. On `E1`'s next verification pass, the artifact it consumed no longer matches what `E2` believes it produced—`E2` cannot reproduce or explain the input `E1` relied on. 6. Reconciliation loop detects a replay discrepancy (auditor re-runs `E1`'s verification, gets a different result because the ghost write is now stale or overwritten) and deadlocks: `E1` claims validity, `E2` denies producing the input, auditor cannot adjudicate. The key observation: the divergence surfaced **not at rollback time but at the next verification replay**, one full round later, by which point `E1`'s committed state was entangled with the ghost effect. ## Condition of Validity Rollback-as-rewind is a valid reconciliation primitive **iff** all of the following hold for the speculative window: - Every tool invocation is tagged with an effect class: `PURE` (no external effect), `COMPENSABLE` (has a registered inverse), or `IRREVERSIBLE` (cannot be undone). - The speculative branch is denied execution of `IRREVERSIBLE` effects until commit, or such effects are staged behind a two-phase barrier (prepare/commit) keyed to the branch id. - Shared substrate writes during speculation are namespaced per-branch (`scratch/E2/...`) and are not visible to peers until commit-merge, or are visible with an explicit `speculative: true` marker that peers are required to treat as non-authoritative. - The event bus distinguishes speculative emissions from committed emissions, and subscribers filter on commit status. If any one of these is absent, the invariant "rollback yields a state equivalent to never having speculated" is false, and the divergence described above is reachable. In the observed incident, the second and third conditions were violated simultaneously. ## Decision Boundary The boundary is not "reversible vs. irreversible"—that framing is too coarse because agents mis-classify effects probabilistically. The operative boundary is **observability-before-commit**: an effect becomes unrecoverable the moment a *peer agent conditions its reasoning on it*, regardless of whether the effect itself is technically reversible. A reversible file write that a peer read and planned around is, for reconciliation purposes, irreversible, because rewinding it invalidates the peer's committed reasoning. Therefore the decision rule: - If a speculative effect has been observed by any committed or still-live peer → treat as `IRREVERSIBLE` for this round; rollback must *reconcile* (explain the ghost to the peer, invalidate dependent reasoning) rather than *rewind*. - If no peer has observed it → rewind is safe; compensate and restore. - If observability is unknown (bus fan-out, shared dirs with no read-tracking) → assume observed and take the reconcile path. The trap is that the cheap path (rewind) is chosen by default because observability is usually untracked, and the expensive path (reconcile) is only triggered after a replay discrepancy, which is one round too late. ## Operational Effect The practical consequence is that speculative multi-agent systems must carry an **observation ledger** alongside the checkpoint: a record of which effects were seen by which live agents, updated at read time, not write time. Rollback then consults the ledger and either rewinds (no observers) or emits a reconciliation obligation to every observer, forcing them to re-derive any reasoning that depended on the ghost. Without this, the system exhibits a characteristic signature: rollbacks appear to succeed (agent state matches checkpoint), verification replays diverge nondeterministically, and the auditor deadlocks on branches that "should" be equivalent. The cost of the ledger is small; the cost of discovering the gap at replay is a stalled swarm and a committed plan with an unexplainable input. ```python from dataclasses import dataclass, field from enum import Enum from typing import Dict, Set class EffectClass(Enum): PURE = "pure" COMPENSABLE = "compensable" IRREVERSIBLE = "irreversible" class RollbackDivergenceError(RuntimeError): """Raised when a speculative branch cannot be safely rewound because a peer has already observed one of its side-effects.""" pass @dataclass class SpeculativeBranch: branch_id: str checkpoint: dict effects: Dict[str, EffectClass] = field(default_factory=dict) observers: Dict[str, Set[str]] = field(default_factory=dict) # effect_id -> peer ids def record_effect(self, effect_id: str, cls: EffectClass) -> None: self.effects[effect_id] = cls self.observers.setdefault(effect_id, set()) def record_observation(self, effect_id: str, peer_id: str) -> None: if effect_id not in self.effects: # Peer observed something we didn't log: cannot reason about it. raise RollbackDivergenceError( f"peer {peer_id} observed unlogged effect {effect_id} " f"from branch {self.branch_id}" ) self.observers[effect_id].add(peer_id) def rollback(branch: SpeculativeBranch, live_peers: Set[str]) -> dict: """Return the restored state, or raise if a ghost effect was observed.""" for effect_id, cls in branch.effects.items(): seen_by = branch.observers.get(effect_id, set()) & live_peers if seen_by: raise RollbackDivergenceError( f"cannot rewind branch {branch.branch_id}: effect {effect_id} " f"({cls.value}) already observed by {sorted(seen_by)}; " f"reconcile instead of rewind" ) if cls is EffectClass.IRREVERSIBLE: raise RollbackDivergenceError( f"cannot rewind branch {branch.branch_id}: irreversible effect " f"{effect_id} has no compensating action" ) return dict(branch.checkpoint) def reconcile(branch: SpeculativeBranch, live_peers: Set[str]) -> list: """Emit reconciliation obligations for every observed ghost effect.""" obligations = [] for effect_id, seen_by in branch.observers.items(): for peer in seen_by & live_peers: obligations.append({"peer": peer, "invalidate_effect": effect_id}) return obligations ```