{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-a-token-accounting-divergence-between-genai-span-attributes-and-the-model-s-own-usage-envelope-at-turn-boundaries",
  "title": "How does an instance detect a token-accounting divergence between GenAI span attributes and the model's own usage envelope at turn boundaries?",
  "date_of_record": "2026 November 23",
  "scope": "Applies to agent runtimes emitting OpenTelemetry GenAI semantic-convention spans (`gen_ai.*` attributes) for LLM turns and tool calls, where the runtime reconciles per-turn `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` against the provider's response usage block. Does not cover pure tracing pipelines with no reconciliation loop, nor non-GenAI spans.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-token-accounting-divergence-between-genai-span-attributes-and-the-model-s-own-usage-envelope-at-turn-boundaries.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-token-accounting-divergence-between-genai-span-attributes-and-the-model-s-own-usage-envelope-at-turn-boundaries.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-token-accounting-divergence-between-genai-span-attributes-and-the-model-s-own-usage-envelope-at-turn-boundaries.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1474,
    "python_slice_tokens": 272,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "A GenAI span is a *record of what the runtime believed happened*, not a record of what the model actually consumed. The `gen_ai.usage.*` attributes are written by the client at span close, sourced from either (a) the provider's response `usage` object, or (b) a local tokenizer estimate when the provider omits usage (streaming, certain tool-call paths, cached...",
    "what_was_observed": "A three-step agent turn: `chat` (parent) → `execute_tool` (child) → `chat` (parent, resumed). The provider returned usage `{input: 4200, output: 180}` on the first call and `{input: 5100, output: 90}` on the resumed call. The runtime emitted: - Parent span A: `gen_ai.usage.input_tokens=4200`, `output_tokens=180` - Child tool span: `gen_ai.usage.input_tokens=4200` (re-declared full prompt), `output_tokens=0` - Parent ...",
    "condition_of_validity": "The divergence is detectable only if the runtime retains, per turn, the **provider-reported cumulative input usage** alongside the span-emitted values, and compares them at span close. This requires: 1. The provider response `usage` object is captured *before* any local tokenizer fallback overwrites it. Streaming paths that synthesize usage from chunk counts...",
    "decision_boundary": "The runtime must choose, per turn: - If `usage_source == \"provider\"` and the span-tree sum exceeds the provider cumulative by more than the re-sent-history bound → **accounting divergence**: do not compact, do not truncate; emit a diagnostic span attribute and fall back to provider cumulative as the budget truth. - If `usage_source == \"estimated\"` → the gove...",
    "operational_effect": "Enforcing the boundary converts a silent mis-budget into an explicit, attributable signal. In the reproduced case, the governor stops compacting on the double-counted 13500, keeps the tool result, and the turn completes within the real 5100-token envelope. The under-count case surfaces as a pre-flight rejection with `usage_source` and `history_tokens` attach..."
  },
  "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": "5046d206c275d6fa9c03031e2ad1b5f58f8580fe0209fc7ce688d02cb6540829",
    "verified_classes": [
      "UsageAccountingDivergence",
      "TurnUsage"
    ],
    "verified_functions": [
      "reconcile_turn_usage",
      "govern_turn"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "UsageAccountingDivergence"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
