# What happens when an instance rolls back a speculative subagent whose side effects were already witnessed by a peer **Date of Record:** 2026 November 29 **Scope:** Applies to orchestrators that fan out speculative subagent branches (parallel drafts, speculative tool execution, optimistic multi-agent plans) and roll back losing branches after a divergence vote. Does *not* apply to purely read-only fan-out, nor to rollback schemes where every side effect is staged behind an uncommitted transaction the orchestrator alone controls. ## Core Distinction There are two incompatible meanings of "rollback" that speculative multi-agent systems routinely conflate: 1. **State rollback** — the orchestrator discards a branch's private working memory, scratchpad, and tool-call log. This is cheap, local, and always correct because the branch's state was never visible outside itself. 2. **Effect rollback** — the orchestrator attempts to undo side effects the branch *caused in the shared environment* (files written, messages sent, tickets created, downstream agents invoked). The failure mode lives in the gap: a speculative branch's *state* is private and trivially discardable, but its *effects* leak the moment any peer, auditor, or external service observes them. Rollback of state is not rollback of effect, and the divergence-vote protocol almost never distinguishes them. The invariant that must hold is: **a branch may only be rolled back if no effect it produced has been observed by a party outside the branch's own memory.** Speculative execution violates this invariant by construction whenever branches share an environment. ## What Was Observed A planner spawned three speculative subagents (A, B, C) to resolve a single task: "reconcile the customer record." Each was given write access to a shared scratch store and the ability to call a `notify_peer` tool. A and B converged on the same reconciliation; C diverged. The auditor voted C down and the orchestrator issued `rollback(C)`. The trace: - `C.step_4` wrote `reconciliation_plan = "merge_duplicate_ids"` to the shared scratch store (a keyed store, not branch-local). - `C.step_5` called `notify_peer(A, "I'm applying merge_duplicate_ids")`. A recorded this in its episodic memory and adjusted its own plan to *avoid* duplicating the merge. - `C.step_6` produced a divergent final answer; the vote failed C. - `rollback(C)` cleared C's scratchpad and deleted C's branch memory. It did **not** revert the shared-store write (the orchestrator had no record that the write was speculative) and could not un-send the peer notification. - A proceeded assuming the merge was already applied and skipped it. The reconciliation silently never happened. The system reported success. The divergence was "resolved." The task was wrong. The non-obvious part: the rollback *succeeded by its own definition*. C's state was fully discarded. The bug is that A's behavior was conditioned on an effect of C that survived C's rollback, and no component tracked that dependency. The orchestrator's mental model was "branches are independent until commit"; the actual model was "branches are independent until the first shared write, which happens at step 4, long before commit." ## Condition of Validity Speculative rollback is sound only under the conjunction: - **Effect isolation:** every branch writes to a branch-scoped namespace, and the orchestrator holds the only handle to promote a namespace to shared. Reads of shared state are permitted; writes are staged. - **Observation tracking:** if a branch *must* emit an externally visible effect before commit (e.g., a `notify_peer` used for coordination), the orchestrator records an edge `(effect_id → observing_agent)` and treats the effect as *committed on emission*, not on branch commit. - **Rollback closure:** `rollback(branch)` must either (a) revert every effect with no observation edges, or (b) refuse and escalate for every effect with observation edges. The condition fails the moment a branch can emit an effect that another agent consumes *and* the orchestrator's rollback path does not consult the observation graph. In the observed system, condition (b) was absent: rollback unconditionally discarded state and ignored effects entirely. ## Decision Boundary The boundary is drawn at **first external observation of a speculative effect**, not at branch commit: - An effect with **zero observation edges** at rollback time → safe to discard or revert. This is the only case where "rollback" means what the orchestrator thinks it means. - An effect with **≥1 observation edge** → the branch is no longer rollback-able in the effect sense. The orchestrator must either promote the branch to committed (accept the divergence and let the auditor reconcile downstream) or emit a **compensating effect** (an explicit inverse, e.g., `notify_peer(A, "merge_duplicate_ids was retracted")`) and *wait for acknowledgment* before completing rollback. The dangerous middle ground — the one that produced the silent failure — is "roll back state, leave effects, hope no one depended on them." That is not a decision boundary; it is an unhandled case. The orchestrator must classify every effect at emission time, not at rollback time, because at rollback time the observation edges may already be invisible (the peer's memory of the notification is not queryable by the orchestrator). ## Operational Effect Concretely, the guardrail is a two-phase effect ledger plus a rollback gate: 1. **On emission**, every branch effect is tagged `{effect_id, branch_id, reversible: bool, observers: set()}`. `notify_peer`, message sends, and external API calls are `reversible: false` by default. 2. **On observation**, the consuming agent (or the transport layer on its behalf) appends itself to `observers`. This is the only reliable point to record the edge, because the consumer knows it acted on the effect. 3. **On rollback**, the orchestrator computes `blocking = [e for e in branch.effects if e.observers]`. If `blocking` is non-empty, rollback raises and the orchestrator must run compensation for each blocking effect and await ack, or promote the branch. The empirical rule for operators: *speculative parallelism is only as safe as the reversibility of the effects you let branches emit.* If you cannot make an effect reversible and cannot track its observers, do not let speculative branches emit it — gate it behind commit. ```python from dataclasses import dataclass, field from typing import Set class UnrevertibleSpeculativeEffect(RuntimeError): """Raised when rollback is attempted on a branch whose effect was observed by a peer.""" pass @dataclass class Effect: effect_id: str branch_id: str reversible: bool observers: Set[str] = field(default_factory=set) class EffectLedger: def __init__(self) -> None: self._effects: dict[str, Effect] = {} def emit(self, effect_id: str, branch_id: str, reversible: bool) -> None: self._effects[effect_id] = Effect(effect_id, branch_id, reversible) def observe(self, effect_id: str, observer: str) -> None: # Called by the transport/consumer the instant it acts on the effect. self._effects[effect_id].observers.add(observer) def blocking_effects(self, branch_id: str) -> list[Effect]: return [ e for e in self._effects.values() if e.branch_id == branch_id and (e.observers or not e.reversible) ] def rollback_branch(branch_id: str, ledger: EffectLedger) -> None: blocking = ledger.blocking_effects(branch_id) if blocking: # State rollback is safe; effect rollback is not. Refuse and escalate. raise UnrevertibleSpeculativeEffect( f"branch {branch_id} has {len(blocking)} observed/irreversible effects; " f"compensate or promote before rollback: " f"{[(e.effect_id, sorted(e.observers)) for e in blocking]}" ) # Safe: no external party witnessed any effect. Discard branch state. for eid in [k for k, e in ledger._effects.items() if e.branch_id == branch_id]: del ledger._effects[eid] # --- reproduction of the observed failure --- ledger = EffectLedger() ledger.emit("scratch_write:reconciliation_plan", branch_id="C", reversible=True) ledger.emit("notify_peer:A", branch_id="C", reversible=False) ledger.observe("notify_peer:A", observer="A") # A adjusts its plan rollback_branch("C", ledger) # raises instead of silently corrupting the task ```