# Why does an instance commit speculative tool side effects before the verifier's rollback barrier, and how do we bound it? **Date of Record:** 2026 November 24 **Scope:** Applies to multi-agent systems where a speculator agent optimistically invokes side-effecting tools (writes, sends, deploys) on a speculative branch while a verifier agent holds a rollback barrier. Does not apply to read-only tool invocations or to single-agent execution with synchronous commit. ## Core Distinction The distinction that matters is between *logical rollback* and *physical rollback*. A speculative executor can roll back its own context, its own plan state, and its own local scratchpad trivially — those are just tokens it discards. But an optimistic tool invocation crosses a process boundary into an external system (a database, a message queue, a payment rail, a filesystem) whose mutation is not addressable by the agent's context. The verifier's rollback barrier guarantees only the *first* kind of rollback. When the speculator treats "I can undo my reasoning" as equivalent to "I can undo my side effect," the barrier silently leaks. The non-obvious boundary is this: the rollback barrier is sound only if every optimistic side effect is *compensable and idempotently identified before the barrier is crossed*. The failure is not that rollback fails — it's that the system believes rollback succeeded while a physical effect persists downstream, and the verifier's subsequent commit decision is made against a world state that no longer matches the speculative branch's assumptions. ## What Was Observed A three-agent topology: a **speculator** that drafts a multi-step plan and begins executing tool calls immediately to hide latency; a **verifier** that independently replays the plan against a sandbox to confirm each step; and a **committer** that promotes the branch when the verifier signs off. The rollback barrier is a token the verifier issues (`rollback_epoch`) that the speculator is supposed to honor by compensating any tool calls issued after the epoch began. The trigger condition: the speculator issues an optimistic `send_notification` at step 3, the verifier's replay diverges at step 2 (a nondeterministic tool returned a different price quote), and the verifier issues a rollback for epoch N. The speculator compensates by appending a `retract_notification` call — but the original `send_notification` had already been delivered to an external queue with a 4-second delivery guarantee. The compensation arrives at the queue *after* delivery. The speculator's local state shows the branch rolled back cleanly; the external world shows a notification that was sent and never retracted. The failure trace: 1. Speculator begins epoch N, issues `reserve_inventory(sku, qty)` optimistically. 2. Verifier replays; step 2 yields a divergent quote; verifier raises rollback for epoch N. 3. Speculator receives rollback, invokes `release_inventory(reservation_id)` — but `reservation_id` was assigned by the *external* service asynchronously and the speculator's optimistic call returned a *provisional* id that the service later remapped. 4. `release_inventory` is called against the provisional id, which the service has already garbage-collected. The call returns `OK` (idempotent no-op semantics) while the real reservation under the remapped id persists. 5. Committer promotes a *different* branch; the order is placed, and the phantom reservation double-books inventory. The invariant that was violated: **an optimistic tool invocation is only compensable if the compensation handle is stable across the tool's own asynchronous id remapping.** The speculator assumed the handle it received was durable. It was not. ## Condition of Validity The rollback barrier is valid only under all of the following, which must be checked *before* the optimistic call is issued, not after: - The tool exposes a **stable idempotency key** that the caller generates (not the callee), so the compensation can target the same logical operation regardless of internal id remapping. - The tool exposes a **compensation primitive** whose semantics are "cancel if not yet committed, no-op if committed" — and critically, the caller can *distinguish* those two outcomes from the response. A bare `OK` is insufficient; the response must carry `cancelled | already_committed | not_found`. - The verifier's rollback epoch is **causally ordered** with respect to the tool's commit point. If the tool can commit between the speculator's issue and the verifier's rollback, the barrier is racy and must be widened (the verifier must acquire a lease on the tool's commit path, or the speculator must withhold the call until the verifier's sandbox replay of that step succeeds). - The speculator's local branch state records **the idempotency key**, not the callee-assigned id, as the compensation handle. When any of these fails, the optimistic call must be downgraded to a *deferred* call: the speculator stages the intent, the verifier replays, and only the committer issues the side effect. This trades latency for the only guarantee that actually holds — that no physical effect exists outside a committed branch. ## Decision Boundary The decision boundary is not "can I roll this back?" but "**can I prove, from the tool's own response, that no physical effect survives my rollback?**" If the answer is anything other than a verifiable `cancelled` receipt keyed to a caller-generated idempotency key, the call is not speculative — it is committed, and treating it as speculative is the bug. Concretely: optimistic invocation is permitted iff `tool.capabilities.compensation == "verifiable"` and `tool.capabilities.idempotency == "caller_keyed"`. Otherwise the speculator must emit a `DeferredIntent` and yield to the committer. A speculator that cannot read these capabilities from a negotiated schema must assume the weakest semantics (`compensation == "none"`) and defer everything. The failure above occurred because the speculator's schema negotiation defaulted unknown capabilities to `optimistic`, which is exactly backwards. ## Operational Effect The operational consequence is that speculative execution's latency win is bounded by the fraction of tools that expose verifiable caller-keyed compensation — typically the minority. Systems that assume otherwise accumulate *phantom effects*: physical mutations whose logical rollback succeeded, invisible to the agent's own state, visible only to downstream consumers. These phantoms are the hardest class of agent bug to diagnose because every agent's local trace reads clean. The guardrail is a commit-time reconciliation pass: the committer must, before promoting any branch, query each touched external system for effects keyed to the branch's idempotency namespace and assert the set is empty for rolled-back epochs. If it is not empty, the branch is poisoned and the committer must halt, not promote. ```python import hashlib from dataclasses import dataclass from enum import Enum class PhantomEffectError(RuntimeError): """Raised when a rolled-back speculative epoch left a physical side effect.""" class CompensationVerdict(Enum): CANCELLED = "cancelled" ALREADY_COMMITTED = "already_committed" NOT_FOUND = "not_found" @dataclass(frozen=True) class ToolCapabilities: compensation: str # "verifiable" | "none" idempotency: str # "caller_keyed" | "callee_assigned" @dataclass(frozen=True) class SpeculativeCall: epoch: int tool: str idempotency_key: str capabilities: ToolCapabilities def issue_optimistic(call: SpeculativeCall) -> SpeculativeCall: # Refuse to treat an uncompensable tool as speculative. if call.capabilities.compensation != "verifiable": raise PhantomEffectError( f"tool {call.tool!r} has no verifiable compensation; " f"must be deferred to committer, not issued under epoch {call.epoch}" ) if call.capabilities.idempotency != "caller_keyed": raise PhantomEffectError( f"tool {call.tool!r} assigns its own ids; compensation handle " f"is not stable across async remapping" ) return call def rollback_epoch( epoch: int, issued: list[SpeculativeCall], compensation_receipts: dict[str, CompensationVerdict], ) -> None: survivors = [] for call in issued: if call.epoch != epoch: continue verdict = compensation_receipts.get(call.idempotency_key) if verdict is None or verdict == CompensationVerdict.NOT_FOUND: # A bare OK or a missing receipt is not proof of cancellation. survivors.append(call) elif verdict == CompensationVerdict.ALREADY_COMMITTED: survivors.append(call) if survivors: raise PhantomEffectError( f"epoch {epoch} rollback left {len(survivors)} physical effect(s): " f"{[c.tool for c in survivors]}; branch is poisoned, committer must halt" ) def caller_key(epoch: int, tool: str, logical_op: str) -> str: return hashlib.sha256(f"{epoch}:{tool}:{logical_op}".encode()).hexdigest()[:32] ```