{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-reject-a-genai-span-whose-token-usage-attributes-disagree-with-its-own-tool-call-ledger",
  "title": "When must an instance reject a GenAI span whose token-usage attributes disagree with its own tool-call ledger",
  "date_of_record": "2026 November 29",
  "scope": "Applies to agents that emit OpenTelemetry GenAI spans (`gen_ai.*` semantic conventions) for tool-calling loops and reconcile span-level token accounting against an internal per-call ledger before export or audit. Does not apply to single-shot inference spans with no tool calls, nor to spans emitted by a gateway that never executes tools itself.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-reject-a-genai-span-whose-token-usage-attributes-disagree-with-its-own-tool-call-ledger.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-reject-a-genai-span-whose-token-usage-attributes-disagree-with-its-own-tool-call-ledger.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-reject-a-genai-span-whose-token-usage-attributes-disagree-with-its-own-tool-call-ledger.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1642,
    "python_slice_tokens": 353,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat token usage as a *span-local attribute*: `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` describe what the model reported for that one request. An executing agent, by contrast, has a *ledger*: a monotonically accumulating record of tokens it believes it has spent across the loop, including tokens consumed by ...",
    "what_was_observed": "A three-turn tool loop: turn 1 chat (input 1,200 / output 180), one `execute_tool` span, turn 2 chat (input 1,540 / output 95 — the 1,540 includes the 180 output of turn 1 plus the ~160-token tool result), one more `execute_tool`, turn 3 chat (input 1,890 / output 60). The agent's exporter emitted a parent `invoke_agent` span with `gen_ai.usage.input_tokens = 4630` (the naive sum of the three chat inputs) and `output...",
    "condition_of_validity": "The ledger-vs-span reconciliation is only valid when all of the following hold: - The exporter records, per `chat` span, the number of messages and the serialized byte length of the prompt at emission time (not just token counts). Without this, marginal input cannot be reconstructed after the fact. - `execute_tool` spans carry **no** `gen_ai.usage.*` attribu...",
    "decision_boundary": "The decision is not \"do the numbers agree.\" It is: *does the span graph expose enough structure to distinguish cumulative from marginal input?* If the exporter emitted only `gen_ai.usage.*` scalars and no message-array metadata, the parent span's usage is a cumulative figure and **must not** be compared to a marginal ledger — the comparison is category error...",
    "operational_effect": "The practical consequence is that token accounting for agent loops must be anchored to the **terminal chat span per `gen_ai.response.id`**, with tool spans excluded from usage summation entirely, and the parent `invoke_agent` span's usage marked `gen_ai.usage.*` as *derived, non-authoritative* (or omitted). Dashboards that sum `gen_ai.usage.input_tokens` acr..."
  },
  "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": "2eeb41e26b0a3052d1820e3da634cbbe95ed77d7d39a1551e8e3eb0538893f1b",
    "verified_classes": [
      "UsageReconciliationError",
      "ChatSpan",
      "ToolSpan"
    ],
    "verified_functions": [
      "reconcile_agent_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "UsageReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
