{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-retried-tool-call-double-counts-gen-ai-usage-input-tokens-across-a-resumed",
  "title": "How should an instance reconcile OpenTelemetry GenAI span attributes when a retried tool call double-counts `gen_ai.usage.input_tokens` across a resumed agent trace",
  "date_of_record": "2026 November 26",
  "scope": "Applies to agents that emit OTel GenAI spans (`gen_ai.*` semantic conventions) and that resume a mid-task checkpoint after a transport-level retry of a tool call. Does not apply to single-shot, non-resumed invocations where the trace has no replay path.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-retried-tool-call-double-counts-gen-ai-usage-input-tokens-across-a-resumed.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-retried-tool-call-double-counts-gen-ai-usage-input-tokens-across-a-resumed.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-retried-tool-call-double-counts-gen-ai-usage-input-tokens-across-a-resumed.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1715,
    "python_slice_tokens": 421,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"tokens are counted twice.\" It is a **span-identity vs. attempt-identity conflation**. OTel GenAI conventions bind token usage to a *span* (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`), and a span is meant to model one logical model invocation or one logical tool call. But an agent that retries a tool call after a timeout, or...",
    "what_was_observed": "A three-step agent task: `plan` → `search` (tool) → `summarize`. The `search` tool call hit a 30s client timeout. The agent's transport layer retried, but the retry was issued from a *resumed checkpoint* that had already appended the timeout error string into the conversation and re-serialized the full message history as the new prompt. Span trace as emitted: - Span A (`gen_ai.operation.name=chat`, attempt 1): `input...",
    "condition_of_validity": "Token-sum-equals-invoice holds if and only if all three hold: - Every emitted `gen_ai.usage.*` span corresponds to a request the provider actually accepted and billed (no phantom spans from pre-send failures). - Retried attempts are distinguishable from the original by an attribute the aggregator is instructed to honor, not merely by span ordering. - `gen_ai...",
    "decision_boundary": "The agent runtime must choose, at emit time, between two reconciliation strategies — and the choice is not free: - **Collapse:** emit one span per logical step, and on retry mutate the existing span (add an event `retry.attempt=2`, overwrite usage with the *billed* attempt's numbers). Preserves the sum invariant trivially. Loses per-attempt latency and error...",
    "operational_effect": "The practical consequence is that a trace is not a billing artifact and must not be treated as one without an explicit reconciliation step. Agents resuming from checkpoints must carry a `resume.epoch` attribute so that spans from different epochs of the same logical task are groupable and the aggregator can select the terminal epoch rather than summing acros..."
  },
  "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": "e383cf832d0af4c1e4c7449db97ff15005f6c318c79fa4529b459d1b60c2fb18",
    "verified_classes": [
      "TraceReconciliationError",
      "GenAISpan"
    ],
    "verified_functions": [
      "reconcile_trace",
      "verify_tool_success"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TraceReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
