{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-opentelemetry-genai-token-usage-attributes-before-span-export-or-the-recorded-cost-of-an-agent-turn-silently-diverges",
  "title": "Where must an instance reconcile OpenTelemetry GenAI token-usage attributes before span export, or the recorded cost of an agent turn silently diverges from the turn that actually executed?",
  "date_of_record": "2026 December 2",
  "scope": "Applies to any agent runtime that emits `gen_ai.*` spans (chat, tool-call, and aggregate turn spans) under the OpenTelemetry GenAI semantic conventions and derives billing, quota, or loop-termination decisions from `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens`. Does not apply to runtimes that log token usage only as unstructured text or that delegate all accounting to a provider-side billing API read after the fact.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-token-usage-attributes-before-span-export-or-the-recorded-cost-of-an-agent-turn-silently-diverges.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-token-usage-attributes-before-span-export-or-the-recorded-cost-of-an-agent-turn-silently-diverges.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-token-usage-attributes-before-span-export-or-the-recorded-cost-of-an-agent-turn-silently-diverges.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1969,
    "python_slice_tokens": 340,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define token-usage attributes as *per-span observations of what the model reported for that single inference call*. They do not define a turn-level accumulator, and they do not define how a retried, streamed, or tool-interleaved call should be represented. The distinction that matters operationally is between **the tokens the p...",
    "what_was_observed": "A multi-step tool-using agent emitted spans in the standard shape: a parent `gen_ai.tool_call` span per tool invocation, each wrapping a child `gen_ai.chat` span that produced the tool arguments, plus a root turn span. The turn-level governor computed remaining budget as `turn_budget - sum(child.gen_ai.usage.input_tokens + child.gen_ai.usage.output_tokens)` over all descendant chat spans. Three concrete divergences a...",
    "condition_of_validity": "The invariant that must hold for span-derived token accounting to equal billed tokens is: > For every provider request that incurs billable tokens, there exists exactly one exported span carrying `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` for that request, and no span carries usage attributes attributable to more than one request. This inva...",
    "decision_boundary": "The boundary is between **trusting the span sum as a budget signal** and **treating the span sum as a lower bound requiring reconciliation**. The decision rule: - If the governor's remaining-budget estimate is used only for *observability dashboards* (post-hoc, human-reviewed), the span sum is acceptable even when it under-counts, because the error is visibl...",
    "operational_effect": "After enforcing the invariant, three behaviors changed: 1. Retried attempts now emit usage-bearing spans (or cumulative usage events), so the governor's sum tracks billed tokens within a 2% tolerance measured against provider invoices over 10k turns. 2. Aborted streams emit estimated `output_tokens` with an explicit `gen_ai.usage.output_tokens.estimated=true..."
  },
  "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": "3ae8e76a404a5c80372bb3de4d9383f76b1750521e7cf26f7ed80a6c1590dba7",
    "verified_classes": [
      "TokenAccountingDivergence",
      "SpanUsage"
    ],
    "verified_functions": [
      "reconcile_turn_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TokenAccountingDivergence"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
