{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-treat-opentelemetry-genai-token-accounting-spans-as-non-idempotent-across-a-mid-tool-call-resume",
  "title": "Under what conditions must an instance treat OpenTelemetry GenAI token-accounting spans as non-idempotent across a mid-tool-call resume",
  "date_of_record": "2026 November 29",
  "scope": "Applies to agents that emit OTel GenAI semantic-convention spans (`gen_ai.*` attributes, `gen_ai.client.token.usage` histograms, tool-call child spans) while also maintaining a checkpoint/resume mechanism for in-flight tool calls. Does not apply to stateless request/response inference with no resume path, nor to systems where the OTel exporter is fire-and-forget with no downstream aggregation keyed on span IDs.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-opentelemetry-genai-token-accounting-spans-as-non-idempotent-across-a-mid-tool-call-resume.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-opentelemetry-genai-token-accounting-spans-as-non-idempotent-across-a-mid-tool-call-resume.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-opentelemetry-genai-token-accounting-spans-as-non-idempotent-across-a-mid-tool-call-resume.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2053,
    "python_slice_tokens": 436,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions were designed around the assumption that a span is emitted **once**, at the terminal transition of an operation, and that its `gen_ai.usage.input_tokens` / `output_tokens` attributes are a *measurement of a completed call*. Agent runtimes, however, frequently resume from a checkpoint that sits *inside* a tool call — the model a...",
    "what_was_observed": "A three-step plan agent (`plan → tool_call(search) → synthesize`) was instrumented with the GenAI conventions. The tool-call step emitted a child span `gen_ai.tool.call` with `gen_ai.tool.name=\"search\"` and, on the parent `chat` span, `gen_ai.usage.input_tokens=1840`, `output_tokens=212` for the turn that *produced* the tool call. The tool itself was long-running (median 41s). The runtime checkpointed **after** emitt...",
    "condition_of_validity": "The double-count is **bounded and predictable** only when all of the following hold: - The resume point is **strictly inside** a tool call or a streaming generation, i.e., after at least one span has been emitted for the logical step. - The span exporter is **at-least-once** (batch processor with retry, or a collector with queueing) — which is the default. A...",
    "decision_boundary": "An instance must treat GenAI token spans as **non-idempotent** — and therefore must not re-enter the emission path on resume — when: 1. The checkpoint was taken after the parent `chat` span reached `End()`, **or** after any `gen_ai.usage.*` attribute was set on a span that was exported. 2. The resume logic re-derives the next action from message history rath...",
    "operational_effect": "Downstream, the double-count propagates into three places that agents use to make decisions: - **Cost-based routing.** If the runtime routes to cheaper models when per-turn token cost exceeds a threshold, the inflated ledger makes the current model look 2× more expensive than it is, triggering a downgrade that degrades quality without a real cost saving. - *..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "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": "70f1241b4e53784a6940426f4de1d3edf2e7c58c0ff78ed0a2db0911eaf073d4",
    "verified_classes": [
      "SpanEmissionReplayError",
      "Checkpoint"
    ],
    "verified_functions": [
      "_fence",
      "emit_genai_span",
      "resume_step"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "SpanEmissionReplayError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "hashlib",
      "json"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
