{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-double-counts-tokens-across-nested-genai-spans-the-opentelemetry-gen-ai-usage-input-tokens-attribution-boundary",
  "title": "What happens when an instance double-counts tokens across nested GenAI spans: the OpenTelemetry `gen_ai.usage.input_tokens` attribution boundary",
  "date_of_record": "2026 November 27",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans per LLM call and per tool call, where a single top-level agent span nests multiple `gen_ai.*` child spans and a shared token counter or billing reconciler reads span attributes. Does not apply to single-shot inference with no nesting, nor to systems that aggregate usage exclusively from a flat event stream outside the span tree.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-double-counts-tokens-across-nested-genai-spans-the-opentelemetry-gen-ai-usage-input-tokens-attribution-boundary.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-double-counts-tokens-across-nested-genai-spans-the-opentelemetry-gen-ai-usage-input-tokens-attribution-boundary.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-double-counts-tokens-across-nested-genai-spans-the-opentelemetry-gen-ai-usage-input-tokens-attribution-boundary.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1853,
    "python_slice_tokens": 383,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "OpenTelemetry's GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as *per-inference-call* attributes on the span representing that call. They are **not** rollup attributes. The convention is silent on what a *parent* GenAI span should report when its children already reported usage—and this silence is where accoun...",
    "what_was_observed": "A three-step ReAct agent (plan → tool call → synthesize) emitted this span tree for one user turn: - `gen_ai.agent.turn` (parent, `gen_ai.operation.name=invoke_agent`) — attributes `gen_ai.usage.input_tokens=4820`, `gen_ai.usage.output_tokens=610` - `gen_ai.chat` step 1 (planning) — `input_tokens=1500`, `output_tokens=180` - `gen_ai.chat` step 2 (post-tool synthesis) — `input_tokens=2100`, `output_tokens=240` - `gen_...",
    "condition_of_validity": "The double-count is only possible when **all** of the following hold simultaneously: 1. A GenAI-typed span exists at more than one depth in the same trace (parent `invoke_agent`/`gen_ai.*` plus child `gen_ai.chat`). 2. The parent span carries `gen_ai.usage.*` attributes populated with a value that is a *function of* its children's usage (rollup), rather than...",
    "decision_boundary": "The operative rule: **`gen_ai.usage.*` is authoritative only on spans whose `gen_ai.operation.name` denotes an actual model invocation (`chat`, `text_completion`, `embeddings`, `generate_content`). Any span at a higher abstraction level must not carry usage attributes, or must carry them under a distinct, non-conventional key (e.g., `agent.rollup.input_token...",
    "operational_effect": "Left unguarded, the failure produces a *plausible* wrong number: totals scale with agent nesting depth, per-span views stay green, and the error is proportional rather than categorical, so threshold alerts on absolute token volume miss it. The reconciler drifts from the invoice by a factor equal to mean spans-per-trace, which looks like a pricing or provider..."
  },
  "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": "847cf68b73950ca4c2b0229ec7cfc86f464640f69616d43d8e1c324c0291c279",
    "verified_classes": [
      "TokenAttributionError",
      "Span"
    ],
    "verified_functions": [
      "_has_usage",
      "sum_billable_input_tokens",
      "descendants"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TokenAttributionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
