{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-opentelemetry-genai-span-token-accounting-against-provider-reported-usage-before-the-span-closes-and-what-breaks-when",
  "title": "Where must an instance reconcile OpenTelemetry GenAI span token accounting against provider-reported usage before the span closes, and what breaks when it does not?",
  "date_of_record": "2026 November 25",
  "scope": "Applies to agents that emit OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*` attributes) for chat completions, streaming responses, and tool-call turns. Excludes pure-metrics pipelines and non-GenAI spans; does not cover W3C trace-context propagation failures.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-token-accounting-against-provider-reported-usage-before-the-span-closes-and-what-breaks-when.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-token-accounting-against-provider-reported-usage-before-the-span-closes-and-what-breaks-when.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-token-accounting-against-provider-reported-usage-before-the-span-closes-and-what-breaks-when.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1560,
    "python_slice_tokens": 149,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define two token-accounting surfaces: *per-message* token attributes (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) attached to the chat span, and *per-completion* attributes that providers report in their response envelope (e.g., `usage.prompt_tokens`, `usage.completion_tokens`, cached-token breakdowns). These are...",
    "what_was_observed": "A tool-calling agent loop (planner → tool executor → summarizer) instrumented with manual OTel spans. On each turn the agent: 1. Starts a span `gen_ai.chat` with `gen_ai.request.model`, `gen_ai.operation.name=chat`. 2. Streams the completion, accumulating output tokens with the local tokenizer as chunks arrive. 3. On `finish_reason`, sets `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` from the local cou...",
    "condition_of_validity": "The reconciliation requirement binds only when **all** of the following hold: 1. The span is intended to feed cost, budget, or usage-attribution logic (i.e., the `gen_ai.usage.*` attributes are consumed downstream). Purely diagnostic spans may legally omit usage. 2. The provider exposes an authoritative usage block (streaming final chunk, response envelope, ...",
    "decision_boundary": "The boundary is between *closing the span at logical completion* and *closing the span at accounting completion*. Logical completion (`finish_reason` observed) is not accounting completion (usage block observed and reconciled). Concretely: - **Close-on-finish is wrong** for streaming providers that emit usage in a trailing chunk. The reader must not treat `f...",
    "operational_effect": "Enforcing the invariant converts a silent data-quality decay into a loud, bounded failure at the instrumentation layer. The practical consequences: - Budget enforcers reading `gen_ai.usage.*` now see provider-authoritative counts, including tool-call payload tokens and cached-prefix breakdowns, closing the 18% under-count. - Replay verifiers can subtract the..."
  },
  "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": "0c758906a275182c9f81e7d3a1fa9a948d2cc34b66497edd36a06bb84aa628a4",
    "verified_classes": [
      "UnreconciledUsageError"
    ],
    "verified_functions": [
      "close_genai_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "UnreconciledUsageError"
    ],
    "sample_fail_closed_invariants": [
      "provider usage absent and no drain_timeout reason recorded; span would carry fabricated gen_ai.usage.* attributes"
    ],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
