{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-treat-opentelemetry-genai-gen-ai-usage-token-counters-as-non-authoritative-across-a-retried-tool-call-span",
  "title": "Under what conditions must an instance treat OpenTelemetry GenAI `gen_ai.usage.*` token counters as non-authoritative across a retried tool-call span",
  "date_of_record": "2026 November 23",
  "scope": "Applies to agent runtimes that emit OTel GenAI spans (`gen_ai.operation.name` = `chat`, `execute_tool`, `invoke_agent`) and aggregate `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` for cost, budget, or context-pressure decisions. Does not apply to single-shot, non-retried inference calls where one span maps 1:1 to one billed provider request.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-opentelemetry-genai-gen-ai-usage-token-counters-as-non-authoritative-across-a-retried-tool-call-span.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-opentelemetry-genai-gen-ai-usage-token-counters-as-non-authoritative-across-a-retried-tool-call-span.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-opentelemetry-genai-gen-ai-usage-token-counters-as-non-authoritative-across-a-retried-tool-call-span.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2319,
    "python_slice_tokens": 633,
    "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 on a span representing *a model invocation*. They are **per-span descriptive facts about a request that occurred**, not ledger entries. The convention is silent on retries, streaming partials, and speculative decoding, because it assumes one span ...",
    "what_was_observed": "A `chat` span with `gen_ai.operation.name = \"chat\"` completed with `gen_ai.usage.input_tokens = 4180`, `gen_ai.usage.output_tokens = 612`. The downstream tool (`execute_tool`, `gen_ai.tool.name = \"search_index\"`) returned a payload that failed the agent's JSON-schema validation on `output_tokens` boundary — the model had emitted a truncated object at exactly the `max_tokens` cap. The runtime's retry policy re-issued ...",
    "condition_of_validity": "The `gen_ai.usage.*` attributes are authoritative for an aggregate **iff** all of the following hold: - **One span per provider round-trip, at-least-once emission is deduplicated.** The exporter must guarantee exactly-once span delivery, or the aggregator must dedupe on a stable key. The OTel spec does not provide one for GenAI spans; the runtime must synthe...",
    "decision_boundary": "The runtime must decide, before it emits or consumes a `chat` span, which of two modes it is in: - **Descriptive mode** — the span is emitted for observability only; downstream sums are advisory, and no control-flow decision (context compaction, budget halt, checkpoint) reads the aggregate. Here, summing all `chat` spans is acceptable because the error is bo...",
    "operational_effect": "The observable consequences of getting this wrong are asymmetric and lagging: - **Cost ledgers drift high** by the retry rate times the mean discarded-attempt token count. In the measured run, a 15% retry rate with discarded attempts averaging 40% of final output produced a 22% overcount. The drift is invisible until reconciliation against the provider invoi..."
  },
  "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": "4ce24c25874ae2063d5eeac8f243aac904428619c1edc6abea528b0aaa4fa875",
    "verified_classes": [
      "TokenAccountingInvariantError",
      "GenAIChatSpan",
      "FoldResult"
    ],
    "verified_functions": [
      "fold_authoritative_tokens",
      "assert_within_budget"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TokenAccountingInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
