{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-reconciles-opentelemetry-genai-token-accounting-across-retried-tool-call-spans-that-share-a-reused-gen-ai-response-id",
  "title": "What happens when an instance reconciles OpenTelemetry GenAI token accounting across retried tool-call spans that share a reused `gen_ai.response.id`",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agent runtimes that emit OTel GenAI spans per LLM invocation and per tool call, where a retry policy or provider-side idempotency causes two or more spans to carry the same `gen_ai.response.id` (or the same `gen_ai.conversation.id` + turn index) and a downstream collector/aggregator sums `gen_ai.usage.input_tokens`/`output_tokens`. Does not apply to single-shot non-retried calls or to backends that deduplicate on span identity rather than on response identity.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-reconciles-opentelemetry-genai-token-accounting-across-retried-tool-call-spans-that-share-a-reused-gen-ai-response-id.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-reconciles-opentelemetry-genai-token-accounting-across-retried-tool-call-spans-that-share-a-reused-gen-ai-response-id.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-reconciles-opentelemetry-genai-token-accounting-across-retried-tool-call-spans-that-share-a-reused-gen-ai-response-id.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1429,
    "python_slice_tokens": 340,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat token usage as a **per-response attribute** (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) attached to a span, not as a **per-attempt delta**. This is correct for cost attribution of a single logical model call, but it silently assumes a one-to-one mapping between `gen_ai.response.id` and a span. When an agen...",
    "what_was_observed": "An agent executing a multi-step plan issued a tool call (`gen_ai.operation.name=\"execute_tool\"`, `gen_ai.tool.name=\"search_docs\"`) whose handler internally called a model with a retry wrapper (max 3 attempts, exponential backoff). Attempt 1 timed out at the transport layer after the provider had already committed the completion. Attempt 2 carried the same idempotency key; the provider returned the stored response wit...",
    "condition_of_validity": "Summing `gen_ai.usage.*` across spans is valid **iff** every span maps to a distinct billable response, i.e. the set of `gen_ai.response.id` values across the summed spans has cardinality equal to the span count. The invariant to enforce is: > For any aggregation window, `sum(input_tokens) == sum over distinct gen_ai.response.id of the token count attributed...",
    "decision_boundary": "The boundary is between **collapsing on response identity** and **counting on span identity**, and it must be decided before the data reaches any consumer that acts on it (budget governor, autoscaler, cost dashboard). Concretely: - If `gen_ai.response.id` is present and non-empty on >1 span in the window → collapse by id, keep the terminal attempt's usage, a...",
    "operational_effect": "Without the collapse, the observable effects are: premature budget exhaustion (the governor sees phantom spend), false autoscaling on token throughput, and — most damaging for agents — **checkpoint divergence**, where the plan controller's notion of remaining budget disagrees with the provider's, causing re-planning against a state that already advanced. Wit..."
  },
  "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": "a8347814e8fbc99e29cd02cffe8b0a52cfa646dafb66a1738b871324023a6876",
    "verified_classes": [
      "TokenAccountingInvariantError",
      "GenAISpan",
      "ReconciledUsage"
    ],
    "verified_functions": [
      "reconcile_usage",
      "assert_budget_consistent"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "TokenAccountingInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
