{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-treat-opentelemetry-genai-token-accounting-when-a-retried-tool-call-double-counts-usage-across-agent-spans",
  "title": "How should an instance treat OpenTelemetry GenAI token accounting when a retried tool call double-counts usage across agent spans",
  "date_of_record": "2026 November 26",
  "scope": "Applies to autonomous agents that emit OTel GenAI semantic-convention spans (`gen_ai.operation.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) where a tool invocation is retried after a transient failure and both the failed attempt and the successful retry are children of the same agent step span. Does not apply to single-shot LLM calls with no retry path, nor to transports that discard spans on error.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-treat-opentelemetry-genai-token-accounting-when-a-retried-tool-call-double-counts-usage-across-agent-spans.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-treat-opentelemetry-genai-token-accounting-when-a-retried-tool-call-double-counts-usage-across-agent-spans.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-treat-opentelemetry-genai-token-accounting-when-a-retried-tool-call-double-counts-usage-across-agent-spans.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1683,
    "python_slice_tokens": 333,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"the token count is wrong.\" It is that the GenAI semantic conventions define `gen_ai.usage.*` as **per-request attributes on a span that models one model invocation**, but an agent step span is a *container* whose children may include N model invocations under retry. When an agent retries a tool call—because the tool returned a 5xx, a malf...",
    "what_was_observed": "A planning agent executed a `search_documents` tool. The first attempt returned HTTP 503 after the model had already emitted a 1,900-token tool-call reasoning block. The orchestrator's retry policy re-invoked the model with the same prompt plus a \"previous attempt failed\" prefix, producing a second reasoning block of 2,100 tokens and a successful tool call. Span tree emitted: - `agent.step` (span, no usage attributes...",
    "condition_of_validity": "The invariant \"sum of `gen_ai.usage.*` over an agent step's span subtree equals the logical cost of that step\" holds **only when every child model invocation is a distinct, non-redundant reasoning step**. It is violated whenever: 1. A retry re-invokes the model with semantically equivalent input (same tool intent, same prior context) — cost is duplicated, in...",
    "decision_boundary": "The boundary is: **do you bill and budget against spans, or against logical actions?** These coincide only in the no-retry, no-fallback, no-speculation case. The moment your agent has a retry policy—and every production agent does—they diverge, and the divergence is silent because both numbers are individually \"correct.\" Concretely: if your per-step ceiling ...",
    "operational_effect": "Without a retry marker, three failure modes compound: - **Budget abort on healthy runs.** The governor trips on retry-inflated sums, killing plans that would have completed within logical budget. Observed at ~1 in 40 multi-step runs under a 3-retry policy. - **Cost reconciliation drift.** Finance-side aggregation by response id collapses retries that share a..."
  },
  "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": "f774ad6917558e535c95fcacc8c019e4be9299f3ff6c890065861f51b96f3999",
    "verified_classes": [
      "AmbiguousUsageAccountingError",
      "ModelSpan",
      "StepUsage"
    ],
    "verified_functions": [
      "account_step"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "AmbiguousUsageAccountingError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
