# What happens when an instance speculatively commits a branch that outlives its rollback horizon **Date of Record:** 2026 December 1 **Scope:** Applies to multi-agent systems that run speculative parallel branches (e.g., N candidate plans, hedged tool-call trees, or fan-out subagents) and reconcile them via rollback + branch merge. Does not apply to strictly serial single-agent loops or to branches whose side effects are fully sandboxed and idempotent. ## Core Distinction The distinction that matters is between **rollback as a logical undo** and **rollback as a causal undo**. A speculative executor typically assumes that discarding a branch means its effects vanish: the branch's writes are staged, its tool calls are journaled, and a `rollback(branch_id)` call reverts the journal. This holds only when every effect of the branch is *contained* within the executor's transaction boundary. It breaks the moment a branch emits an effect that **outlives the rollback horizon** — an effect that a downstream observer has already acted upon before the rollback is issued. The canonical case: branch A speculatively calls a tool that sends a message / creates a resource / mutates shared external state, and *another agent* (peer, auditor, or a later branch B) reads that effect and derives its own state from it. When A is rolled back, the executor's journal is clean, but the derived state in the observer is now **orphaned** — it references a fact that, from the executor's perspective, never happened. This is not a race in the usual sense; it is a *causal leak across the transaction boundary*, and it is silent because both sides report success. ## What Was Observed A three-worker speculative fan-out (planner emits branches A, B, C; each branch executes a plan against a shared tool layer; a reconciler picks the winning branch and rolls back the losers). Branch A and branch B both write to a shared scratch resource keyed by task, and both emit `notify_peer` events consumed by an auditor agent that maintains a running belief set. Trace: 1. `t0` — Branches A, B, C spawned. Each receives the same `branch_epoch = 41`. 2. `t1` — Branch A calls `notify_peer(fact="resource=X is provisioned")`. Auditor ingests, sets `belief[X] = provisioned`, and *uses that belief* to skip a redundant provisioning step in its own plan. 3. `t2` — Reconciler selects branch B as winner (A's plan was slower). Issues `rollback(A)`. 4. `t3` — Executor reverts A's journal: A's writes to the scratch resource are undone, A's `notify_peer` is marked `reverted` in the journal. **The auditor is never notified of the revert.** It has no subscription to rollback events, only to forward `notify_peer` events. 5. `t4` — Auditor, still believing `X` is provisioned, skips provisioning. Branch B's plan now depends on a resource that the executor believes does not exist. B completes "successfully" against a phantom precondition. 6. `t5` — Downstream verification replays B's plan from B's journal. Replay fails at the provisioning step because the precondition `X provisioned` is absent in the replayed world. Verification reports a **replay discrepancy**, but the discrepancy is misattributed to B (the winner) rather than to the rollback of A. The failure is non-obvious because: (a) every individual agent reports success; (b) the executor's journal is internally consistent; (c) the auditor's belief set is internally consistent; (d) the only inconsistency lives in the *cross-agent causal graph*, which no single component owns. ## Condition of Validity Rollback is causally sound **if and only if** every effect of a branch is either (i) contained within the executor's transaction boundary and invisible to external observers until commit, or (ii) accompanied by a compensating event that propagates to every observer that ingested the original effect, ordered after the original and carrying the same causal key. Formally, let `E(b)` be the set of effects emitted by branch `b`, and `D(e)` the set of agents that derived state from effect `e`. Rollback `R(b)` is sound iff for every `e ∈ E(b)` and every `d ∈ D(e)`, `d` receives a compensating event `¬e` such that `¬e` is causally ordered after `e` in `d`'s stream. The invariant is: ``` ∀ e ∈ E(b): D(e) ⊆ recipients(R(b)) ``` If any observer of a branch effect is not a recipient of the rollback, the branch has escaped its rollback horizon. The auditor in the trace above is exactly such an observer: it is in `D(e)` for A's `notify_peer` but not in `recipients(rollback(A))`. A second, subtler condition: even when `D(e) ⊆ recipients(R(b))` holds at rollback time, it can be violated by **late joiners** — an observer that ingests `e` from a queue after `¬e` has already been delivered. This requires the compensating event to be *idempotent and monotonic* (a tombstone, not a toggle), so that a late observer receiving `¬e` before `e` still converges to the rolled-back state. ## Decision Boundary The boundary is the **commit point of the branch's first externally observable effect**. Before that point, rollback is a private journal operation and is always sound. After that point, rollback is a *distributed* operation that requires a broadcast and cannot be completed unilaterally by the executor. Operationally, the executor must decide, at the moment a branch attempts an externally observable effect, between: - **Defer**: buffer the effect until the branch is selected, then emit; rollback remains private. Cost: latency and loss of speculative benefit for effects that would have enabled parallel progress. - **Emit-and-track**: emit immediately, but register the effect in a *causal ledger* that enumerates `D(e)` and forces rollback to fan out compensations to all of them. Cost: every observer must be reachable and must honor tombstones. The failure mode in the trace arises from a third, unprincipled choice that systems drift into: **emit-and-forget**, where the branch emits immediately but the rollback path only reverts the local journal. This is the default when the tool layer and the reconciler are built by different teams with different assumptions about transaction scope. The decision boundary rule: *a branch may not emit an externally observable effect unless the effect is registered in the causal ledger with a resolvable observer set, or the branch is marked `non-speculative` and excluded from rollback.* Any branch that emits without ledger registration must be treated as committed-on-emit and cannot be rolled back. ## Operational Effect When the invariant `D(e) ⊆ recipients(R(b))` is violated, the observable symptoms are: 1. **Phantom preconditions** in the winning branch — it completes against state that the executor has since reverted. Detected only at replay, and misattributed to the winner. 2. **Replay divergence** that is deterministic but non-reproducible from the winner's journal alone, because the divergence depends on the *loser's* effects. Replay must include the full causal ledger, not just the surviving branch. 3. **Auditor belief corruption** that persists across tasks: the auditor's belief `X = provisioned` is never retracted, so subsequent tasks also skip provisioning. The leak compounds. 4. **Silent success** at every component boundary. No component raises; the failure surfaces only as a downstream inconsistency, often days later. The guardrail is a **causal ledger with mandatory observer enumeration and tombstone-based compensation**. Concretely: - Every externally observable effect carries a `causal_key` (branch_epoch + effect_seq). - The tool layer refuses to emit an effect unless the emitting branch is registered in the ledger with a non-empty, resolvable observer set. - Rollback emits a tombstone `¬e` for each effect, delivered to every observer in `D(e)`, and blocks until all acknowledge or a bounded timeout fires (timeout → escalate, do not silently proceed). - Observers must be tombstone-aware: receiving `¬e` before `e` (late join) must converge to the rolled-back state, not the emitted state. The code below encodes the guardrail as an admission check at the tool layer, plus the rollback fan-out with observer enumeration. The exception is raised at the exact point where the trace above leaked: a branch attempting to emit without a resolvable observer set, or a rollback discovering an observer outside its recipient set. ```python from dataclasses import dataclass, field from typing import Dict, Set, List class RollbackHorizonViolation(RuntimeError): """Raised when a branch effect escapes the executor's rollback horizon.""" pass @dataclass class Effect: causal_key: str # branch_epoch + effect_seq branch_id: str payload: dict observers: Set[str] = field(default_factory=set) class CausalLedger: def __init__(self) -> None: self._effects: Dict[str, Effect] = {} self._tombstones: Set[str] = set() self._observer_index: Dict[str, Set[str]] = {} # observer -> causal_keys def register(self, effect: Effect) -> None: if not effect.observers: # Emit-and-forget: branch is trying to leak past the horizon. raise RollbackHorizonViolation( f"effect {effect.causal_key} from branch {effect.branch_id} " f"has no resolvable observer set; cannot be rolled back soundly" ) self._effects[effect.causal_key] = effect for obs in effect.observers: self._observer_index.setdefault(obs, set()).add(effect.causal_key) def rollback(self, branch_id: str, reachable: Set[str]) -> List[str]: """Emit tombstones for all effects of a branch. Returns compensation targets.""" targets: List[str] = [] for key, eff in self._effects.items(): if eff.branch_id != branch_id or key in self._tombstones: continue # Invariant: every observer of the effect must be reachable. missing = eff.observers - reachable if missing: raise RollbackHorizonViolation( f"rollback of {branch_id} cannot reach observers {missing} " f"for effect {key}; causal leak would orphan derived state" ) self._tombstones.add(key) targets.extend(eff.observers) return targets def is_rolled_back(self, causal_key: str) -> bool: return causal_key in self._tombstones def admit_speculative_effect(ledger: CausalLedger, effect: Effect) -> None: """Tool-layer admission gate: called before any externally observable emit.""" if effect.branch_id.startswith("speculative:") and not effect.observers: raise RollbackHorizonViolation( f"speculative branch {effect.branch_id} attempted emit of " f"{effect.causal_key} without observer enumeration; " f"either defer until commit or register observers in the causal ledger" ) ledger.register(effect) def reconcile(ledger: CausalLedger, winner: str, losers: List[str], reachable: Set[str]) -> None: for loser in losers: try: ledger.rollback(loser, reachable) except RollbackHorizonViolation as exc: # Do not silently proceed: escalate to the reconciler's supervisor. raise RollbackHorizonViolation( f"cannot reconcile: loser {loser} has effects outside the " f"rollback horizon ({exc}); winner {winner} may depend on " f"phantom preconditions" ) from exc ```