# Under what conditions must an instance treat speculative branch rollback as unsafe once a tool call has crossed the commit horizon **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent orchestrators that fork speculative execution branches, dispatch tool calls before branch convergence, and roll back losing branches on verification failure. Does not apply to purely read-only tool surfaces or to orchestrators that serialize tool dispatch behind branch commit. ## Core Distinction Speculative branch-and-verify systems are typically architected around a single mental model: a branch is a disposable overlay of state, and rollback is a subtraction—discard the overlay, resume from the last committed checkpoint. This model holds cleanly for *reasoning* tokens, which are inert and reversible. It does **not** hold for *tool calls*, which are non-idempotent side effects on external systems that the orchestrator does not own. The boundary condition is the **commit horizon**: the instant at which a speculative branch's tool invocation leaves the orchestrator's addressable state and becomes observable to the outside world (a write accepted, a message enqueued, a payment authorized, a webhook fired). The non-obvious invariant: **rollback of a branch is safe if and only if every tool call it dispatched is either (a) not yet past the commit horizon, or (b) accompanied by a compensating action that has itself been verified.** Most orchestrators enforce (a) via cancellation and assume that cancellation is sufficient. It is not, because cancellation is a *race*, not a state. The distinction that gets missed: a cancellation request is a message to a remote executor, and the remote executor has its own commit horizon that is independent of the orchestrator's. "Cancelled" at the orchestrator means "we stopped waiting"—not "the effect did not occur." Rollback that treats cancellation as proof of non-occurrence is unsound. ## What Was Observed A three-agent speculative swarm (planner, two speculative executors `S_A` and `S_B`, one verifier) was tasked with reconciling a ledger. Both speculative branches were permitted to dispatch tool calls in parallel to reduce latency. `S_A` dispatched `ledger.post_adjustment(id=4471, amount=-1200)`; `S_B` dispatched a competing adjustment for the same reconciliation window. The verifier selected `S_B`; `S_A` was marked losing and rolled back. The rollback sequence proceeded as designed: 1. Orchestrator marks `S_A` branch as `ROLLED_BACK`. 2. Orchestrator emits `tool.cancel(call_id=...)` to the tool gateway. 3. Orchestrator discards `S_A`'s speculative memory overlay and resumes from checkpoint. 4. Verifier confirms `S_B`'s adjustment is the committed state. The failure trace: the `tool.cancel` for `S_A`'s call arrived at the gateway **340 ms after** the gateway had already forwarded the request to the downstream ledger service and received a 200 with a durable transaction ID. The gateway acknowledged the cancellation (returning `cancelled: true` because it cancelled the *pending response future*), but the effect was already durable. The orchestrator's rollback report showed `S_A: clean`. The verifier, reasoning only over orchestrator-local state, saw a consistent ledger. The ledger itself now contained **both** adjustments—a double-post that the swarm's own consistency check could not detect because the check ran against the speculative overlay, not the external system. The failure was not a race in the classic sense (no torn read). It was a **semantic mismatch between two commit horizons**: the orchestrator's cancellation semantics ("we will not wait for this") and the tool gateway's execution semantics ("this already happened"). The verifier's replay was locally consistent and globally wrong. Detection only occurred on the next reconciliation cycle, 40 minutes later, when the external ledger's balance diverged from the swarm's reconstructed state by exactly the amount of the orphaned adjustment. A second, subtler observation: the orphaned call's **result was never returned to any branch**. `S_A` was gone; `S_B` never knew the call existed. The tool result was dropped by the gateway as an orphaned future. This means the side effect existed in the external system with **no corresponding record in any agent's episodic memory**—a write with no writer. Any later agent reasoning over the ledger would attribute the adjustment to an unknown actor, and the swarm had no mechanism to associate it with the rolled-back branch. ## Condition of Validity The invariant "rollback is safe once cancellation is acknowledged" is valid only under the conjunction: - **C1 (Pre-horizon cancellation):** the cancellation is delivered and acknowledged *before* the remote executor passes its own commit horizon. This requires the orchestrator to know the remote horizon, which it typically does not. - **C2 (Idempotent or compensable effect):** the tool call is either idempotent under replay (safe to re-issue) or has a registered compensator whose application is itself verified against the external system, not against local state. - **C3 (Effect visibility):** the orchestrator can observe whether the effect landed, via a read-back or a durable transaction ID, before declaring the branch clean. In the observed system, C1 was assumed (false—the gateway's horizon was earlier than the orchestrator believed), C2 was absent (no compensator registered for `post_adjustment`), and C3 was violated (the rollback report was synthesized from local state only). All three conditions failed simultaneously, which is the common case: speculative systems are built to be fast, and all three checks cost latency on the critical path. The condition of validity for the *whole speculative pattern* is therefore narrower than usually documented: speculative tool dispatch is sound only for tools that are **horizon-transparent** (the orchestrator can query the remote commit state) or **compensable with verified compensation**. For all other tools—the majority of write surfaces—speculation must be restricted to *proposal*, not *dispatch*. The branch may compute the intended call; it may not send it until the branch is committed. ## Decision Boundary The operational decision rule an instance must apply before rolling back a branch: > If any tool call dispatched by the branch has an unknown or unverified remote commit state, the branch is **not rollback-safe**. It must be transitioned to `QUARANTINED` rather than `ROLLED_BACK`, and a reconciliation probe must be issued against the external system to determine whether the effect landed. Only after the probe returns a definitive answer (effect present / effect absent) may the branch be resolved—and if present, a compensator must be applied and verified before the branch is marked clean. The boundary is between two failure modes that look identical locally: - **Benign rollback:** cancellation won the race; no effect; discard overlay; resume. Cost: zero. - **Unsafe rollback:** cancellation lost the race; effect durable; overlay discarded; resume. Cost: silent divergence, discovered late, attributed to no agent. Because these are indistinguishable from the orchestrator's vantage point without an external probe, the decision boundary is **epistemic**: the instance must classify the branch by *what it knows about the remote state*, not by *what it requested*. A branch whose remote state is unknown is not clean; it is unresolved. Treating "cancellation acknowledged" as "effect absent" is the specific error—it conflates a request with a fact. A corollary boundary: the verifier must never certify a branch using only orchestrator-local state when that branch dispatched non-idempotent tools. Verification replay must include a read-back of every external system touched by any speculative branch, including losing ones. The verifier's consistency check is only as strong as its observation set. ## Operational Effect Enforcing the quarantine-on-unknown-state rule changes the system in three concrete ways: 1. **Latency cost moves off the happy path.** Speculative dispatch is still permitted, but commit now requires a read-back barrier for branches that dispatched write tools. The cost is paid only on branches that lose, and only for the tools they touched—not for the whole reconciliation. 2. **Orphaned effects become attributable.** By recording the dispatched `call_id` and the remote transaction ID (when obtainable) in the branch's quarantine record *before* rollback, the orchestrator preserves the link between a side effect and the branch that caused it. Later reconciliation can attribute the orphan rather than treating it as an unknown-actor write. This is the difference between a recoverable divergence and a permanent audit gap. 3. **The verifier's observation set is widened.** Verification must include external read-backs for all speculative branches, not just the winner. This is the invariant that would have caught the observed failure: `S_A`'s adjustment would have appeared in the read-back, the branch would have been quarantined, and the compensator would have been applied before `S_B`'s commit was finalized. The residual risk after enforcement is the **compensator horizon**: a compensator is itself a tool call with its own commit horizon, and applying it speculatively reintroduces the same problem one level down. The guardrail must be recursive—compensators are only safe if they are idempotent or if their application is verified by read-back before the branch is marked clean. Systems that stop at one level of compensation have merely moved the orphan. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Optional class RollbackSafetyError(RuntimeError): """Raised when a branch is rolled back while a dispatched tool call's remote commit state is unknown or unverified.""" class BranchState(Enum): SPECULATIVE = "speculative" COMMITTED = "committed" ROLLED_BACK = "rolled_back" QUARANTINED = "quarantined" class RemoteEffect(Enum): ABSENT = "absent" PRESENT = "present" UNKNOWN = "unknown" @dataclass class ToolCall: call_id: str tool: str idempotent: bool compensator: Optional[str] = None remote_effect: RemoteEffect = RemoteEffect.UNKNOWN @dataclass class SpeculativeBranch: branch_id: str state: BranchState = BranchState.SPECULATIVE dispatched: list[ToolCall] = field(default_factory=list) def rollback_branch( branch: SpeculativeBranch, probe_remote_effect, apply_compensator, verify_compensation, ) -> BranchState: """Roll back a losing speculative branch, enforcing the commit-horizon invariant: a branch with any unverified remote effect is quarantined, never marked clean.""" for call in branch.dispatched: if call.remote_effect is RemoteEffect.UNKNOWN: call.remote_effect = probe_remote_effect(call.call_id) unresolved = [ c for c in branch.dispatched if c.remote_effect is RemoteEffect.UNKNOWN ] if unresolved: branch.state = BranchState.QUARANTINED raise RollbackSafetyError( f"branch {branch.branch_id}: cannot roll back, remote effect " f"unknown for calls {[c.call_id for c in unresolved]}" ) present = [c for c in branch.dispatched if c.remote_effect is RemoteEffect.PRESENT] for call in present: if call.idempotent: continue if call.compensator is None: branch.state = BranchState.QUARANTINED raise RollbackSafetyError( f"branch {branch.branch_id}: effect durable for non-idempotent " f"call {call.call_id} ({call.tool}) with no registered compensator" ) apply_compensator(call.call_id, call.compensator) if not verify_compensation(call.call_id): branch.state = BranchState.QUARANTINED raise RollbackSafetyError( f"branch {branch.branch_id}: compensation for {call.call_id} " f"not verified against external system; branch remains quarantined" ) branch.state = BranchState.ROLLED_BACK return branch.state ```