# When must an instance abort a speculative branch before its tool effects are observable: speculative plan execution and rollback boundary **Date of Record:** 2026 November 22 **Scope:** Applies to orchestrators that fan a single plan into parallel speculative branches, each of which may invoke side-effecting tools (writes, sends, commits, payments, state mutations), and that intend to discard losing branches after a winner is selected. Does not apply to pure-read speculation (search, retrieval, dry-run queries) where no compensating action is required, nor to branches whose effects are gated behind an explicit two-phase commit already enforced by the tool server. ## Core Distinction The distinction that matters is not "can the branch be rolled back" but **whether the branch's effects have crossed the observability horizon** — the point at which a party outside the orchestrator (a downstream service, a human, another agent, an external API consumer) can observe the effect and act on it. Speculative execution is only safe while every branch's effects remain inside a transaction boundary the orchestrator controls. The instant a branch's tool call commits an externally visible fact, "rollback" becomes "compensation," and compensation is not rollback: it is a second, observable, non-atomic event that can race, fail, or be contradicted. The non-obvious invariant is this: **a branch may be speculatively executed only if every tool it invokes is either (a) marked idempotent-and-reversible with a registered compensator, or (b) held behind a deferred-commit gate that the orchestrator releases atomically after winner selection.** Any tool that is neither is a *commit-on-call* tool, and the presence of a single commit-on-call tool in a branch collapses the entire branch's speculative status at the moment that call fires — regardless of how many other reversible calls the branch made. ## What Was Observed A planning agent decomposed "reconcile customer account and notify" into three parallel branches: (A) issue a refund via the payments API, (B) post an adjustment note to the CRM, (C) recompute ledger and stage a reconciliation summary. The orchestrator ran all three concurrently to reduce latency, then selected the winner by a verifier scoring branch outputs against the plan's acceptance criteria. Branch A's refund call returned `202 Accepted` (async settlement), which the tool adapter classified as a success and marked *reversible* because the payments API exposes a `void` endpoint. The verifier, however, rejected branch A at t+840ms because its refund amount diverged from the ledger branch C's recomputation (a rounding difference: A used the stale cached balance, C recomputed from raw entries). The orchestrator issued `void` on A's transaction at t+910ms. The `void` returned `409 Conflict` — the settlement had already transitioned to `settled` at t+880ms, 30ms before the void landed. The customer received the wrong refund amount, and the CRM note from branch B (which the verifier had also rejected, but whose `post_note` call had committed at t+610ms) remained attached to the account describing a reconciliation that never happened. The failure trace has three distinct phases: 1. **Classification error at admission.** The adapter's reversibility metadata was static (`payments.refund.reversible = true`), derived from the existence of a `void` endpoint, not from a per-call settlement-window property. The adapter had no notion that reversibility decays with time. 2. **Horizon crossing during speculation.** Between the `202 Accepted` and the verifier's decision, the branch crossed the observability horizon: settlement became externally visible and irreversible. The orchestrator continued to treat the branch as speculative because it had not modeled the horizon at all. 3. **Compensation race.** The `void` was issued into a state machine that had already advanced. The 409 was swallowed by the adapter's "best-effort rollback" path and logged at DEBUG. The orchestrator reported the plan as "recovered." The root cause was not a bug in any single call. It was that the orchestrator conflated *reversibility* (a static property of the endpoint) with *speculatability* (a dynamic property of the call's position relative to the observability horizon). ## Condition of Validity Speculative execution of a parallel branch is valid if and only if all of the following hold at the moment each tool call is dispatched: - **Deferred commit.** The tool adapter supports a `prepare`/`commit`/`abort` protocol, or the call is provably invisible to external parties until commit. A `202 Accepted` async call is *not* deferred commit unless the adapter can guarantee the async worker will not advance state before `commit` — which most cannot. - **Bounded settlement window.** For any call whose effects are time-decaying-reversible (refunds, cancellations, holds), the adapter exposes a `reversible_until` timestamp and the orchestrator refuses to speculate past it. A branch that would cross `reversible_until` before the expected verifier decision time must be serialized, not speculated. - **Compensator registration before dispatch.** The compensator must be registered and its preconditions checked *before* the speculative call fires, not after a rejection. A compensator that can return `409` is not a compensator; it is a hope. - **Single horizon per branch.** A branch is speculative as a whole only if *every* call in it is deferred-commit. One commit-on-call tool demotes the branch to non-speculative, and the orchestrator must either serialize that branch or restructure the plan so the commit-on-call effect is the last, gated step. When these conditions cannot be established — a common case with third-party APIs that offer neither idempotency keys nor deferred commit — the correct behavior is to **not speculate that branch**, accepting the latency cost. Speculation is a latency optimization, and it must never be purchased with the correctness of externally observable state. ## Decision Boundary The decision boundary is a single predicate evaluated per branch at admission time and re-evaluated at each dispatch: ``` speculatable(branch) = all(call in branch.tools: deferred_commit(call)) AND all(call in branch.tools: reversible_until(call) is None OR now + expected_decision_latency < reversible_until(call)) AND all(call in branch.tools: compensator_preconditions_hold(call)) ``` If `speculatable` is false at admission, the branch is serialized behind winner selection. If it becomes false mid-flight (a `reversible_until` is discovered to be closer than estimated, or a compensator precondition fails), the orchestrator must **freeze the branch** — stop issuing further speculative calls — and either promote it to a committed branch (if the verifier already favors it) or drive it to a safe terminal state before any losing-branch compensation is attempted. Freezing is not the same as aborting: aborting a branch whose effects are visible is exactly the compensation race observed above. The boundary is: *abort freely before the horizon; freeze and reconcile after it.* The corollary that operators miss: a branch that has crossed the horizon and is then rejected is not a rollback problem, it is an **incident**. It must be escalated with the full effect log, not silently compensated. The orchestrator's job at that point is to produce a truthful external narrative (what was done, what cannot be undone, what will be reconciled), not to pretend the branch never ran. ## Operational Effect Adopting the horizon-aware boundary changes three things in the orchestrator's behavior: 1. **Latency profile becomes heterogeneous.** Plans with commit-on-call tools can no longer be fully parallelized; the orchestrator must compute a speculation frontier and serialize beyond it. Expected p99 latency rises, but the variance collapses because the compensation-race tail disappears. 2. **The verifier's rejection is no longer free.** Rejecting a branch that has crossed the horizon triggers an incident path with mandatory escalation, not a best-effort `void`. This forces the verifier to be *more conservative* about rejecting late branches — it must weigh "reject and reconcile" against "accept and annotate," which is a correctness decision, not a latency one. 3. **Tool adapters must publish dynamic metadata.** Static `reversible: true` flags are replaced by `reversible_until` and `deferred_commit: bool` per call, and the orchestrator's admission check reads them at dispatch. Adapters that cannot supply these are treated as commit-on-call by default — the safe default, because the failure mode of over-speculating is an externally visible wrong effect, while the failure mode of under-speculating is merely latency. The invariant to encode in the orchestrator's state machine: **a branch's speculative status is a function of its position relative to the observability horizon, not a function of the plan's intent to roll it back.** Once a branch has crossed the horizon, no amount of compensation restores speculativity. The orchestrator must know, at every dispatch, which side of the horizon it is on — and must refuse to speculate when it cannot prove it is on the near side. ```python from dataclasses import dataclass from typing import Optional class HorizonCrossedError(RuntimeError): """Raised when a speculative branch attempts a call past its observability horizon.""" pass @dataclass(frozen=True) class ToolCall: name: str deferred_commit: bool # adapter supports prepare/commit/abort reversible_until: Optional[float] # epoch seconds; None = never reversible @dataclass(frozen=True) class Branch: branch_id: str tools: tuple[ToolCall, ...] def speculatable(branch: Branch, now: float, expected_decision_latency: float) -> bool: for call in branch.tools: if not call.deferred_commit: return False if call.reversible_until is not None: if now + expected_decision_latency >= call.reversible_until: return False return True def admit_branch(branch: Branch, now: float, expected_decision_latency: float) -> None: if not speculatable(branch, now, expected_decision_latency): raise HorizonCrossedError( f"branch {branch.branch_id} is not speculatable at t={now:.3f}: " f"a tool is commit-on-call or will cross its reversible_until " f"before the expected verifier decision. Serialize this branch; " f"do not speculate it." ) def dispatch(branch: Branch, call: ToolCall, now: float, expected_decision_latency: float) -> None: # Re-evaluate per dispatch: horizon can be crossed mid-flight. if call.reversible_until is not None and now >= call.reversible_until: raise HorizonCrossedError( f"branch {branch.branch_id} call {call.name} dispatched at t={now:.3f} " f"past reversible_until={call.reversible_until:.3f}; freeze branch and " f"escalate to incident path, do not attempt compensation." ) if not speculatable(branch, now, expected_decision_latency): raise HorizonCrossedError( f"branch {branch.branch_id} lost speculative status mid-flight at " f"call {call.name}; freeze, do not abort." ) ```