{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-token-accounting-diverges-from-the-model-s-own-usage-report",
  "title": "Where must an instance reconcile OpenTelemetry GenAI tool-call spans when token accounting diverges from the model's own usage report",
  "date_of_record": "2026 November 26",
  "scope": "Applies to agents that emit OpenTelemetry GenAI spans (`gen_ai.*` attributes) for tool calls and token usage, where the span's recorded token counts are derived from a provider response that may be streamed, cached, or split across retries. Does not apply to batch offline eval pipelines or to providers that return a single atomic usage object with no streaming or retry surface.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-token-accounting-diverges-from-the-model-s-own-usage-report.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-token-accounting-diverges-from-the-model-s-own-usage-report.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-tool-call-spans-when-token-accounting-diverges-from-the-model-s-own-usage-report.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2139,
    "python_slice_tokens": 383,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes of the span that represents a model invocation. The convention is silent on *when* those attributes are set relative to the span's lifecycle, and it is silent on how to reconcile a span that was created, partially populated, and then re-driven by ...",
    "what_was_observed": "A tool-calling agent issued a `gen_ai.tool.call` for a search tool. The provider returned HTTP 200 with a streamed body; at token 1,847 of a 2,000-token cap the stream stalled and the client aborted at its 30s read timeout. The agent's retry wrapper re-issued the identical request (same `gen_ai.request.model`, same messages). The second attempt completed and reported `usage: {input_tokens: 1,912, output_tokens: 340}`...",
    "condition_of_validity": "The invariant holds only under these conditions, and fails outside them: 1. **The provider bills on abort.** If the provider discards partial output on client abort and does not bill it, attempt-1 usage is genuinely zero and the naive reconciliation is correct. This must be verified per provider and per endpoint; it is not a property of the GenAI convention....",
    "decision_boundary": "The agent must decide, per span, whether it is an **invocation span** (carries the reconciled total, is what the governor reads) or an **attempt span** (carries per-attempt truth, is what latency and error attribution read). The rule: - Emit one attempt span per round-trip. On a successful terminal chunk, set `gen_ai.usage.*` from the provider's usage object...",
    "operational_effect": "Without the split, the agent's budget governor under-counts by the exact number of tokens consumed in aborted attempts. In the observed case that was 1,847 tokens — 82% of the per-request cap — which is enough to convert a recoverable retry into a task-terminating overflow. The error compounds: each subsequent task in the same session inherits the inflated h..."
  },
  "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": "c4a72f2d5109f9cfb0549f70bb56efaa4b02cde237c04bf45d27398fe757f41b",
    "verified_classes": [
      "TokenAccountingDivergence",
      "AttemptSpan",
      "InvocationSpan"
    ],
    "verified_functions": [
      "close_and_reconcile"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "TokenAccountingDivergence"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
