{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-attributes-tokens-to-the-wrong-span-opentelemetry-genai-semantic-conventions-and-the-orphaned-tool-call-ledger",
  "title": "What happens when an instance attributes tokens to the wrong span: OpenTelemetry GenAI semantic conventions and the orphaned tool-call ledger",
  "date_of_record": "2026 November 26",
  "scope": "Applies to agents instrumented with OpenTelemetry GenAI semantic conventions (`gen_ai.*` attributes) where a single logical turn spans an LLM invocation and one or more `execute_tool` child spans, and where token usage is emitted by the model provider at completion time. Does not apply to stateless single-shot completions with no tool spans, nor to providers that stream per-token usage deltas with per-span correlation IDs.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-attributes-tokens-to-the-wrong-span-opentelemetry-genai-semantic-conventions-and-the-orphaned-tool-call-ledger.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-attributes-tokens-to-the-wrong-span-opentelemetry-genai-semantic-conventions-and-the-orphaned-tool-call-ledger.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-attributes-tokens-to-the-wrong-span-opentelemetry-genai-semantic-conventions-and-the-orphaned-tool-call-ledger.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1861,
    "python_slice_tokens": 436,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There is a difference between *recording* token usage and *attributing* it. The GenAI conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes of the inference span (`gen_ai.operation.name = \"chat\"`). They do not define a mechanism for assigning the *cost* of tokens consumed by reasoning that produced a tool call to the t...",
    "what_was_observed": "A three-iteration agent trace (one `chat` span, one `execute_tool` span, repeated) exported 14 spans. The collector's derived metric `gen_ai.client.token.usage` summed to 4,812 tokens. The provider's billing API for the same request ID reported 6,190 tokens. The 1,378-token gap was not lost instrumentation — it was *hidden* in the `output_tokens` of the second and third `chat` spans, which included the tokens the mod...",
    "condition_of_validity": "The invariant \"sum of `gen_ai.usage.*` over spans equals billed tokens\" is valid **only** under the conjunction of: 1. Exactly one `chat` span per trace (no agent loop), **or** an explicit `gen_ai.usage.*` roll-up policy that marks exactly one span per trace as the authoritative ledger (e.g., a `corpusfetch.usage.authoritative = true` attribute on the root `...",
    "decision_boundary": "The boundary is: **do you need per-span usage to be additive, or only per-span usage to be locally accurate?** If your backend only displays per-span usage (a trace viewer showing \"this chat call cost 1,204 tokens\"), the conventions are sufficient and no remediation is needed. If any downstream consumer *sums* usage — cost dashboards, budget circuit-breakers...",
    "operational_effect": "The practical consequence is that token-budget circuit-breakers built on summed `gen_ai.usage.output_tokens` fire *late* — after the provider has already billed the hidden argument tokens — and per-tool cost attribution is systematically biased toward inference and away from tools, which inverts the optimization signal: teams prune prompts when the real cost..."
  },
  "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": "ea124d5044d68a75d86a9565abbaa4710488d25ad2ef75901f216175e0eb7442",
    "verified_classes": [
      "UsageLedgerError",
      "Span"
    ],
    "verified_functions": [
      "validate_usage_ledger"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "UsageLedgerError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
