# Under what conditions must an instance abandon optimistic speculative tool-call execution and force a compensating rollback barrier **Date of Record:** 2026 November 29 **Scope:** Applies to single- or multi-agent workflows where an orchestrator dispatches tool calls speculatively (issuing call N+1 before call N's effect is confirmed) under an optimistic concurrency assumption, with a compensating-rollback log as the only recovery mechanism. Does not apply to strictly serialized tool pipelines, to read-only tool sets with no side effects, or to workflows whose tools expose true transactional semantics (two-phase commit, idempotency keys with server-side dedup). ## Core Distinction The failure is not "a speculative call returned an error." Speculative execution is *designed* to occasionally return errors; the orchestrator discards the orphaned branch and continues. The boundary case is subtler: **a speculative tool call succeeds (returns a 2xx-shaped result the model accepts as ground truth) while the effect it presumed from its predecessor never committed.** The agent then holds two mutually inconsistent beliefs — a durable side effect from call N+1, and a *presumed* precondition from call N that was rolled back — and proceeds to reason over the contradiction. Optimistic concurrency is only sound when the *compensation* of a failed predecessor is either (a) provably disjoint from the effects of speculative successors, or (b) ordered strictly after every in-flight successor has been resolved. When neither holds, the rollback of call N mutates state that call N+1 already consumed, and the compensating log records a rollback that is itself a lie about the world the agent now inhabits. The distinction that matters operationally: **an error is recoverable; a silent reconciliation gap between a rolled-back predecessor and a committed successor is not, because no component observes it.** ## What Was Observed A three-tool workflow: `reserve_inventory(sku, qty)` → `charge_card(token, amount)` → `create_shipment(order_id)`. The orchestrator speculates: it fires `charge_card` and `create_shipment` in parallel with `reserve_inventory`, betting that reservation succeeds ~95% of the time and that latency savings dominate. Trace of the boundary case: 1. `reserve_inventory` is dispatched at t=0. It is slow (inventory service under load). 2. At t=120ms the speculative branch fires `charge_card`, which succeeds and returns `charge_id=ch_881`. The model records success. 3. At t=140ms `create_shipment` fires with a *provisional* `order_id` synthesized by the model from the reservation's expected shape. It succeeds against a lenient shipment service that does not validate the order reference. 4. At t=900ms `reserve_inventory` returns `409 CONFLICT: insufficient stock`. The orchestrator runs the compensation log: it issues `refund(ch_881)` and `cancel_shipment(ship_... )`. 5. **The refund succeeds. The cancel succeeds. But the model's working context still contains the intermediate reasoning step "reservation confirmed, order_id=..., inventory locked."** The compensation log updated external state; it did not update the agent's episodic memory of what it believed. On the next reasoning turn the agent, seeing `refund` and `cancel` in its tool history but *not* a corresponding reservation failure annotation attached to the reservation belief, re-derives a plan that assumes the order exists and re-charges the card. The double-charge is caught only by a downstream reconciliation job two hours later. The non-obvious part: the compensating rollback *executed correctly at the tool layer*. The failure was that **compensation is a side-effect operation, not a belief-revision operation.** No mechanism in the optimistic-concurrency protocol invalidated the agent's committed assumptions about predecessor success when the predecessor was later rolled back. ## Condition of Validity Optimistic speculative execution with compensating rollback is sound **only under the conjunction of these invariants**, and an instance must abandon speculation the moment any is unverifiable: - **I1 — Effect independence:** For every speculative successor S and its predecessor P, `effects(S) ∩ effects(P) ≠ ∅` must be *false or provably disjoint*. `charge_card` and `reserve_inventory` touch disjoint systems; `create_shipment` reading `order_id` synthesized from P's *expected* output violates this, because S consumed a value that P's rollback invalidates. - **I2 — Monotonic compensation ordering:** A compensation for P may only execute after every successor that consumed P's output has been resolved (committed *and* its belief re-annotated, or rolled back). Parallel compensation is forbidden when successors exist. - **I3 — Belief invalidation parity:** Every entry in the compensation log MUST have a corresponding invalidation event injected into the agent's context (a tombstone message: `reservation P failed; any belief derived from P is retracted`). The log without the tombstone is a half-protocol. - **I4 — Idempotency of re-derivation:** If the agent re-plans after rollback, every tool it re-invokes must be idempotent under the same logical intent, or the orchestrator must hold a dedup key across the rollback boundary. The instance is *outside* the condition of validity — and must drop to serialized execution — when it cannot establish I1 for a given successor (the successor's arguments were derived from the predecessor's unconfirmed output) or when I3 has no delivery path into the context window. ## Decision Boundary The operational rule is a **pre-dispatch predicate**, evaluated per speculative edge, not per workflow: ``` speculate(P → S) is permitted iff args(S) do not contain any token derived from output(P) # enforces I1 AND compensation_log.has_tombstone_channel(P) # enforces I3 AND (S.is_idempotent OR orchestrator.holds_dedup_key(S)) # enforces I4 ``` If `args(S)` contains a value the model synthesized from P's *expected* result — a provisional ID, a computed total, a derived path — speculation is illegal regardless of latency benefit, because the rollback cannot reach back into S's committed effect. This is the sharp line: **speculation is safe when successors are independent of predecessor output, and unsafe the instant a successor's arguments are a function of a predecessor's unconfirmed return.** A second boundary: even with independent successors, if the compensation log cannot deliver a tombstone into the agent's context (context window saturated, or the tombstone would be evicted before the next reasoning turn), the instance must serialize. A compensation the agent cannot *see* is not a compensation. ## Operational Effect When the invariant holds, speculative execution yields the intended latency win with bounded blast radius: rollback restores external state and the tombstone restores the agent's belief state, keeping the two in agreement. When it is violated, the observable signature is a **reconciliation gap** — external systems show a refunded charge and a cancelled shipment, while the agent's next plan re-derives the cancelled order. The gap is invisible to per-call error handling because every individual call succeeded; it is visible only to a cross-layer invariant checker that asserts `belief(agent) ≡ state(external)` after every rollback. The guardrail an instance must install: **compensation is a two-write operation** — one write to the external tool, one tombstone write to the agent's context — and the rollback barrier does not lift until both writes are acknowledged. Until then, no successor may be dispatched and no re-plan may be derived. An orchestrator that treats rollback as a single external call has implemented half of a protocol and will double-charge exactly when its predecessor is slowest. ```python class SpeculationInvariantViolation(RuntimeError): """Raised when a speculative tool call is dispatched in violation of effect-independence, compensation ordering, or belief-invalidation parity.""" pass TOMBSTONE_CHANNEL = "context.tombstones" def dispatch_speculative(predecessor, successor, orchestrator, ctx): # I1: successor arguments must not derive from predecessor's unconfirmed output if successor.args_derived_from(predecessor.output_schema): raise SpeculationInvariantViolation( f"successor {successor.name} consumes unconfirmed output of " f"{predecessor.name}; speculation illegal, serialize instead" ) # I3: a delivery path for the rollback tombstone must exist in context if not orchestrator.has_channel(TOMBSTONE_CHANNEL): raise SpeculationInvariantViolation( f"no tombstone channel for {predecessor.name}; " "rollback would not invalidate agent belief" ) # I4: successor must be idempotent or hold a dedup key across rollback if not (successor.is_idempotent or orchestrator.holds_dedup_key(successor)): raise SpeculationInvariantViolation( f"successor {successor.name} is non-idempotent and lacks dedup key; " "re-derivation after rollback would double-apply" ) result = successor.invoke() if not predecessor.committed(): # Two-write compensation: external effect AND belief tombstone. orchestrator.compensate(predecessor) # external write orchestrator.emit(TOMBSTONE_CHANNEL, { # belief write "retract": predecessor.id, "reason": "predecessor rolled back post-speculation", }) # Barrier: no successor dispatch or re-plan until both acknowledged. orchestrator.await_ack(predecessor.id, TOMBSTONE_CHANNEL) return result ```