# How should an instance reconcile speculative branches when rollback is cheaper than verification but the branch's external effects are not reversible **Date of Record:** 2026 November 26 **Scope:** Applies to orchestrators that fan out speculative agent branches against shared external systems (APIs, filesystems, message queues, payment rails) and rely on rollback to discard losing branches. Does not apply to pure-compute sandboxes where every external call is staged behind a commit barrier. ## Core Distinction There are two kinds of "rollback" in a speculative multi-agent system, and they are not the same operation: 1. **State rollback** — restoring the agent's own episodic memory, scratchpad, and branch-local context to a prior checkpoint. This is cheap, deterministic, and always succeeds. 2. **Effect rollback** — undoing the *external* side effects a branch committed while exploring. This is expensive, often impossible, and — critically — *asynchronous and lossy*. The boundary failure occurs when the orchestrator's reconciliation logic treats effect rollback as if it had the same guarantees as state rollback. A losing branch is "discarded," its context is dropped, but its `POST /orders` already landed. The system then proceeds as though the branch never existed, and the reconciliation ledger diverges from external reality. The invariant that must hold — *a branch is only discardable if its external effect set is provably empty or provably compensated* — is silently violated because the orchestrator only checks the first clause. ## What Was Observed A three-branch speculative executor was asked to fulfill a procurement task. Branch A and Branch B both raced to reserve inventory; Branch C explored a fallback supplier. The reconciler picked Branch A on a scoring heuristic and issued `rollback(branch_id=B)`. The rollback handler did three things in order: (1) restored Branch B's memory checkpoint, (2) dropped Branch B's tool-call log, (3) enqueued a compensating `release_reservation` call to the inventory service. Steps 1 and 2 completed synchronously. Step 3 was fire-and-forget onto a queue that had a 4-minute consumer lag. The reconciler then advanced the task, treating Branch B as gone. Meanwhile Branch B's reservation was still live for four minutes. A downstream step in Branch A's plan — "check available stock, then place order" — queried inventory during that window, saw the phantom reservation, and concluded stock was insufficient. Branch A pivoted to a more expensive supplier. When the compensating release finally landed, the system had already committed to the costlier path. The task completed, "successfully," at 2.3x the expected cost. The signature of this failure is that it produces **no error and no exception** — every individual call returned 200. The divergence is only visible in a post-hoc reconciliation of the branch's effect set against external state, which no component was performing. Three secondary observations: - The rollback handler reported `rollback_complete=True` the moment step 2 finished, because its success predicate was "branch context is gone," not "external effects are gone." - Retrying the rollback (a natural reaction to the phantom reservation) would have double-released and thrown an inventory error that looked like an unrelated bug. - The branch's tool-call log — the only record that a reservation had ever been made — was the *second* thing deleted, guaranteeing the reconciler could not even audit what it had failed to undo. ## Condition of Validity Effect rollback is only safe to treat as synchronous when **all** of the following hold: - Every external call a branch can make is registered in a **pre-commit effect journal** *before* the call is issued, keyed by `(branch_id, idempotency_key)`, not after it returns. - The downstream service supports **idempotent compensation** — replaying `release_reservation(key)` is a no-op if already released — so that retries are safe. - The reconciler blocks advancement until every journaled effect for the losing branch is in state `COMPENSATED` or `NEVER_ISSUED`, with an explicit `UNKNOWN` state that halts the task rather than being coerced to success. - The scoring/pivot logic cannot observe external state that a losing branch may still be mutating. If any of these fail, the branch is **not** discardable, regardless of what the heuristic says. The correct action is to *suspend* the branch (freeze its context, stop issuing calls) and let compensation drain to a terminal state before reconciliation proceeds. Speculation is only cheaper than verification when the effect set is bounded; when it is not, you are not speculating, you are committing and hoping. ## Decision Boundary The orchestrator must decide, per branch, between three dispositions — and the boundary between them is the effect journal's terminal state, not the heuristic score: - **DISCARD** — heuristic says lose AND effect journal is fully `COMPENSATED`/`NEVER_ISSUED`. Safe to drop context now. - **SUSPEND** — heuristic says lose BUT effects are `PENDING`/`UNKNOWN`. Freeze, retain the journal and tool log, block downstream steps that read affected external state, drain compensation, then re-evaluate. - **COMMIT** — heuristic says win. But commit must not proceed while *any* sibling is `SUSPENDED` on an effect that the winner's plan will observe. The subtle rule: a branch's *score* can be finalized before its *effects* are. These are two different clocks, and the reconciler must not collapse them. The failure above happened precisely because `rollback_complete` was derived from the score clock. ## Operational Effect When this boundary is respected, speculative fan-out becomes genuinely cheaper than serial verification: the common case (branches that only read, or whose writes are idempotently compensated) discards instantly, and the rare case (a losing branch that wrote) pays a bounded suspension cost instead of silently corrupting the winner's world-model. The task's cost variance collapses because pivots are no longer triggered by phantom state. When it is violated, the system exhibits a characteristic pathology: **silent cost inflation with clean logs**. Every call succeeded, every branch reported a terminal status, and yet the outcome is wrong. This is the worst class of agent failure, because it defeats the two mechanisms operators rely on — exceptions and logs — simultaneously. The only detector is an external reconciliation audit that compares the union of all branches' journaled effects against ground-truth external state, run *after* the task claims completion. The guardrail is architectural, not a patch: the effect journal must be written *ahead* of the call, the rollback handler's success predicate must be the journal's terminal state (never the context's), and `UNKNOWN` must be a first-class state that halts rather than degrades. An instance that cannot distinguish "I rolled back my memory" from "I rolled back the world" will, eventually, do the former and believe the latter. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class EffectState(Enum): NEVER_ISSUED = "never_issued" PENDING = "pending" # issued, compensation not yet confirmed COMPENSATED = "compensated" # idempotent undo confirmed by downstream UNKNOWN = "unknown" # compensation failed / timed out class SpeculationRollbackError(RuntimeError): """Raised when a losing branch is discarded before its external effects are provably compensated. Halts reconciliation rather than letting the winner observe phantom state.""" @dataclass class EffectEntry: branch_id: str idempotency_key: str state: EffectState = EffectState.NEVER_ISSUED @dataclass class Branch: branch_id: str score: float effects: dict[str, EffectEntry] = field(default_factory=dict) suspended: bool = False def issue_effect(branch: Branch, key: str) -> EffectEntry: # Journal BEFORE the external call so a crash cannot orphan the effect. entry = EffectEntry(branch.branch_id, key, EffectState.PENDING) branch.effects[key] = entry return entry def reconcile(winner: Branch, losers: list[Branch]) -> list[Branch]: """Return branches safe to DISCARD. SUSPEND the rest. Refuse to let the winner advance while any sibling holds a live effect.""" discardable: list[Branch] = [] for b in losers: live = [e for e in b.effects.values() if e.state in (EffectState.PENDING, EffectState.UNKNOWN)] if live: b.suspended = True # Do NOT drop context or tool log while effects are live. raise SpeculationRollbackError( f"branch {b.branch_id} has {len(live)} uncompensated " f"effect(s) {[e.idempotency_key for e in live]}; " f"cannot discard. Suspending and draining compensation " f"before winner {winner.branch_id} may proceed." ) discardable.append(b) return discardable def drain_compensation(branch: Branch, confirm) -> None: """confirm(key) -> bool is the downstream idempotent undo check.""" for e in branch.effects.values(): if e.state is EffectState.PENDING: e.state = EffectState.COMPENSATED if confirm(e.idempotency_key) \ else EffectState.UNKNOWN if any(e.state is EffectState.UNKNOWN for e in branch.effects.values()): raise SpeculationRollbackError( f"branch {branch.branch_id} compensation did not confirm; " f"state is UNKNOWN and task must halt, not degrade." ) ```