{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-double-count-tokens-when-a-tool-call-span-is-retried-under-opentelemetry-genai-semantics",
  "title": "Why does an instance double-count tokens when a tool-call span is retried under OpenTelemetry GenAI semantics?",
  "date_of_record": "2026 November 26",
  "scope": "Applies to agent runtimes that emit OTel GenAI spans (`gen_ai.*` attributes) with per-span token usage and tool-call spans that may be retried, replayed, or re-emitted after a checkpoint resume. Does not apply to single-shot inference calls with no retry surface or to runtimes that aggregate usage only at the root span.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-double-count-tokens-when-a-tool-call-span-is-retried-under-opentelemetry-genai-semantics.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-double-count-tokens-when-a-tool-call-span-is-retried-under-opentelemetry-genai-semantics.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-double-count-tokens-when-a-tool-call-span-is-retried-under-opentelemetry-genai-semantics.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1498,
    "python_slice_tokens": 271,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as **per-span, per-invocation counters** — they describe the cost of the model call that produced that span. They are *not* monotonic accumulators and carry no idempotency key. Billing aggregators, however, almost universally sum these attributes across spans t...",
    "what_was_observed": "A planner-executor agent using a `call_model` → `invoke_tool` → `call_model` loop. The tool layer had a 30s deadline. On a slow tool (a vector search that occasionally exceeded the deadline), the executor's retry policy re-invoked the tool up to 3 times. Each attempt emitted an `execute_tool` span per convention, and — critically — the *reasoning step that decided to retry* also re-ran the model call to regenerate th...",
    "condition_of_validity": "The double-count only manifests when **all** of the following hold: 1. The runtime re-invokes a model call as part of a retry or resume path (so usage is genuinely re-spent *or* re-emitted). 2. The GenAI usage attributes are emitted per-span rather than only at a root/aggregate span. 3. The aggregator keys usage by span ID or sums all spans, with no deduplic...",
    "decision_boundary": "The boundary is: **is a re-emitted span a new cost or the same cost re-observed?** Two cases must be separated explicitly, because they demand opposite handling: - **Re-spend** (retry actually called the model again, tokens billed again): the usage is real and must be counted — but attributed to a *distinct attempt*, not folded into the logical step's baseli...",
    "operational_effect": "Without the guardrail, cost telemetry drifts upward monotonically with retry rate and resume frequency — precisely the conditions that correlate with incidents, so the spend alert fires *because* of the incident and misdirects responders toward a phantom cost problem. Token-budget governors that read the same summed attribute will trip early and abort health..."
  },
  "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": "8135d215e9c22cbb5ca9413acb76845c0a24593f321b9d9a7b6ced1293be2f79",
    "verified_classes": [
      "ReplayAccountingError",
      "Origin",
      "GenAISpan"
    ],
    "verified_functions": [
      "attribute_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "ReplayAccountingError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "enum"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
