{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-speculatively-pre-execute-a-tool-call-under-an-idempotency-key-and-still-double-apply-the-effect-when-the-optimistic-concurrency",
  "title": "Why does an instance speculatively pre-execute a tool call under an idempotency key and still double-apply the effect when the optimistic concurrency check is revalidated after a scheduler preemption?",
  "date_of_record": "2026 November 22",
  "scope": "Applies to agents that overlap LLM decoding with side-effecting tool execution by issuing the call under a client-generated idempotency key, then revalidating an optimistic-concurrency token (version/ETag) on commit. Does not apply to read-only speculative calls, nor to transports that serialize commit and effect atomically in a single transaction.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-speculatively-pre-execute-a-tool-call-under-an-idempotency-key-and-still-double-apply-the-effect-when-the-optimistic-concurrency.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-speculatively-pre-execute-a-tool-call-under-an-idempotency-key-and-still-double-apply-the-effect-when-the-optimistic-concurrency.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-speculatively-pre-execute-a-tool-call-under-an-idempotency-key-and-still-double-apply-the-effect-when-the-optimistic-concurrency.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1665,
    "python_slice_tokens": 276,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"the idempotency key was missing\" or \"the version check was skipped.\" Both are present. The failure is a **split between the deduplication domain and the concurrency domain across a preemption boundary**. The idempotency key is minted at *speculation time* and bound to the *intended* effect; the concurrency token is validated at *commit ti...",
    "what_was_observed": "A planner agent emits a tool call `transfer_funds(account=A, amount=100, idem_key=K1)` and begins speculative execution before the model has finished emitting the trailing verification tokens. The tool handler: 1. reads the account version `v=7`, 2. performs the debit under `K1`, 3. stages the commit with `If-Match: v=7`. Before the commit RPC returns, the instance is preempted (token-budget exhaustion mid-decode, no...",
    "condition_of_validity": "This failure requires the conjunction of four conditions; remove any one and the double-apply is bounded: 1. **Speculation precedes durable key persistence.** The idempotency key lives in volatile decode state or an in-memory scratchpad rather than the write-ahead step record. If `K1` is fsynced before the side effect fires, the resume reuses it and the stor...",
    "decision_boundary": "The boundary is whether the commit's precondition token is **pinned to speculation-time state** or **re-derived at commit-time state**. Pinned tokens make the optimistic check a true compare-and-swap against the pre-effect world: a retry that re-reads `v=8` and tries `If-Match: v=7` fails closed, and the orchestrator must reconcile the ambiguous outcome (did...",
    "operational_effect": "Without the pin, the system exhibits **silent at-least-once semantics disguised as exactly-once**: every guard logs success, reconciliation by key finds nothing, and the only signal is a version skew that looks like normal concurrent traffic. The blast radius scales with preemption frequency — exactly the regime (long decodes, tight token budgets, aggressive..."
  },
  "matched_failure_symptoms": [
    "DUPLICATE_MUTATION_OR_BILLING",
    "LOST_UPDATE_OR_RACE_CONDITION"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "0cd5594fc7e1985bd06571adc8edc1e39446eb9afa99e8a15f24e39adff0967b",
    "verified_classes": [
      "SpeculativeCommitDivergence",
      "SpeculativeRecord"
    ],
    "verified_functions": [
      "commit_speculative",
      "resume_step",
      "args_digest"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "SpeculativeCommitDivergence"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
