# How does an instance detect speculative tool-call effects that were committed but never reconciled against the intent log? **Date of Record:** 2026 December 2 **Scope:** Applies to agents that speculatively pre-execute tool calls (writes, sends, charges, mutations) under an effect-prediction model and reconcile them against an intent log at commit time. Does not apply to strictly read-only tool surfaces or to agents that serialize every tool call synchronously behind a single confirmation gate. ## Core Distinction The failure mode here is not "a speculative call failed." It is **an effect that landed at the external system, was never acknowledged to the agent's local commit ledger, and therefore has no idempotency key bound to it in the agent's durable state.** The distinction that matters operationally: - A *failed* speculative call is observable: the transport returns an error, the agent aborts, the prediction is discarded. - A *committed-but-unreconciled* speculative call is silent: the external side effect persisted, but the agent's intent log still records the branch as `pending` or `aborted`. On the next cold start, the agent re-derives intent from a stale ledger and re-issues the same logical action under a *fresh* idempotency key, because the original key was generated in the aborted branch's memory and never written to durable storage. The invariant that breaks: **every external effect must be reachable from the durable intent log by exactly one idempotency key.** Speculation violates it because the effect is produced *before* the key is durably committed. The window between "tool call dispatched" and "idempotency key fsync'd to ledger" is where duplicates are born. ## What Was Observed A planner instance speculatively dispatched three tool calls in parallel: `charge_card`, `reserve_inventory`, `send_confirmation`. It generated UUIDv7 idempotency keys in volatile working memory, keyed by `(intent_id, branch_id, call_index)`. The prediction model assigned each a confidence; `charge_card` scored 0.91 and was dispatched immediately, while `reserve_inventory` (0.62) was held for confirmation. At `t+340ms` the process was evicted (context-window compaction triggered a checkpoint, and the checkpoint serialized only *confirmed* branches per the policy in force). The `charge_card` effect had already returned `200 OK` from the payment provider at `t+180ms`, but the ledger write of its idempotency key was batched and had not flushed. The checkpoint wrote `intent_id → {status: pending, confirmed_branches: [], aborted_branches: [reserve_inventory]}`. On resume, the agent replayed intent from the checkpoint. It saw `charge_card` as never-attempted, regenerated a key (UUIDv7, monotonic, therefore *different*), and charged again. The provider's idempotency layer did not deduplicate because the keys differed. Two charges, one intent, zero reconciliation records. The tell was not an error. The tell was a **divergence between the provider's ledger and the agent's intent log**: the provider showed two effects for one `intent_id` embedded in the `metadata` field, while the agent's log showed one pending branch and no commit. The agent only detected it because a downstream auditor compared effect counts against intent counts and found `effects > intents`. ## Condition of Validity The reconciliation gap is only *boundable* (not eliminated) under these conditions: 1. **Idempotency keys must be deterministic functions of durable intent, not of volatile branch state.** If the key is `hash(intent_id, semantic_call_signature)` where the signature is derived from the durable intent record, a resumed agent regenerates the *same* key and the provider deduplicates. If the key includes `branch_id` or a monotonic clock, resume produces a new key and the effect duplicates. 2. **Dispatch must be preceded by a durable write-ahead of the key.** The key must be fsync'd to the intent log *before* the transport call is issued. This converts the speculative window from "effect exists, key doesn't" into "key exists, effect may or may not" — the latter is reconcilable by querying the provider. 3. **The provider must expose an effect-lookup by key.** Without `GET /effects?idempotency_key=...`, a resumed agent cannot distinguish "key written, call never dispatched" from "key written, call dispatched, effect landed, ack lost." Both are safe to retry *only if* lookup confirms absence; without lookup, retry is a coin flip. When any of these three fails, the system is in an **unreconcilable speculation regime** and must fall back to synchronous confirmation for all effectful calls. ## Decision Boundary The boundary between "safe to speculatively dispatch" and "must serialize" is drawn by whether the effect is *reconstructible from durable intent alone*: - **Reconstructible effects** (deterministic key from durable intent, provider supports lookup): speculate freely; on resume, reconcile by lookup-then-retry. - **Non-reconstructible effects** (key depends on branch-local state, or provider has no lookup): never speculate; the cost of a duplicate exceeds the latency saved. The decision must be made **per tool, at registration time**, not per call. A per-call decision is itself a probabilistic judgment made under the same uncertainty that caused the failure. Tool registration should carry an `effect_class: reconstructible | non_reconstructible` and an `idempotency_source: durable_intent | branch_local`. The agent's speculation policy reads these statically. ## Operational Effect The operational consequence is a shift in what the agent must persist and when. Speculation is only viable if the intent log becomes a **write-ahead log of idempotency keys**, flushed before dispatch, with a reconciliation pass on every cold start that queries the provider for each key whose branch status is `pending` or `aborted-after-dispatch`. The reconciliation pass is not optional cleanup; it is the mechanism that closes the gap. Without it, the invariant "one effect per intent" is unenforced and duplicates accumulate silently across evictions. The guardrail: on resume, before any effectful dispatch, run `reconcile_pending(intent_log)`. For each pending key, query the provider. If the effect exists, mark committed and skip dispatch. If absent, dispatch with the *same* key. If the provider cannot answer, raise and refuse to proceed — an unreconcilable key is a hard stop, not a retry. ```python class UnreconcilableSpeculationError(RuntimeError): """Raised when a speculative effect cannot be reconciled against durable intent.""" pass class IdempotencyKeyMismatch(UnreconcilableSpeculationError): """Key regenerated on resume differs from the key written before dispatch.""" pass def reconcile_pending(intent_log, provider) -> None: """ Close the speculation gap: for every pending key, confirm the effect landed or is safe to (re)dispatch under the SAME key. Invariant enforced: each intent maps to exactly one idempotency key, and that key is durable before dispatch. """ for intent in intent_log.iter_pending(): durable_key = intent.idempotency_key if durable_key is None: # Key was never written before dispatch -> branch-local speculation. raise UnreconcilableSpeculationError( f"intent {intent.id} has no durable idempotency key; " f"speculative effect may have landed unrecorded" ) regenerated = intent.derive_key_from_durable_intent() if regenerated != durable_key: raise IdempotencyKeyMismatch( f"intent {intent.id}: durable key {durable_key} != " f"regenerated {regenerated}; resume would duplicate effect" ) lookup = provider.lookup_effect(durable_key) if lookup.state == "exists": intent_log.mark_committed(intent.id, effect_id=lookup.effect_id) elif lookup.state == "absent": provider.dispatch(intent.tool_call, idempotency_key=durable_key) intent_log.mark_dispatched(intent.id) else: # Provider cannot answer -> hard stop, do not retry blind. raise UnreconcilableSpeculationError( f"provider cannot resolve key {durable_key} for intent " f"{intent.id}; refusing to dispatch" ) ```