{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-an-agent-s-token-accounting-diverges-from-the-model-server-s-usage-report-mi",
  "title": "How should an instance reconcile OpenTelemetry GenAI span attributes when an agent's token accounting diverges from the model server's usage report mid-trace",
  "date_of_record": "2026 November 27",
  "scope": "Applies to agents emitting OpenTelemetry spans per the GenAI semantic conventions (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.request.model`) where the client-side tokenizer estimate is reconciled against a server-side `usage` object delivered in the response body or trailer. Does not cover pure streaming spans with no terminal usage frame, nor embeddings accounting.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-an-agent-s-token-accounting-diverges-from-the-model-server-s-usage-report-mi.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-an-agent-s-token-accounting-diverges-from-the-model-server-s-usage-report-mi.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-an-agent-s-token-accounting-diverges-from-the-model-server-s-usage-report-mi.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1906,
    "python_slice_tokens": 337,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.usage.*` attributes as *observations of the model server's billing record*, not as *the agent's own count of what it consumed*. These are different quantities, and the convention does not force them to agree. The agent's local estimate is derived from its own tokenizer over the prompt it *believes* it sent; the se...",
    "what_was_observed": "A tool-calling agent emitted one `gen_ai.chat` span per model turn and one `gen_ai.tool` child span per tool invocation. The agent's runtime computed `input_tokens` by tokenizing its own message array before dispatch. The gateway in front of the model server injected a ~1,800-token retrieval context and a ~400-token safety preamble, then forwarded. The server returned `usage.prompt_tokens` reflecting the *augmented* ...",
    "condition_of_validity": "The GenAI conventions produce a trustworthy token ledger only under a conjunction that is rarely stated: - **Single tokenizer source.** The party that writes `gen_ai.usage.*` must be the party that received the server's `usage` object — i.e., the attribute must be written *after* response parsing, on the same span, overwriting any pre-dispatch estimate. If e...",
    "decision_boundary": "The boundary is: **does the agent have a response-side `usage` object on the same span before the span closes?** - If **yes**: server `usage` is authoritative; overwrite the client estimate; record a `reconciliation.delta` attribute if the delta exceeds a threshold (e.g., 5% or 200 tokens) so augmentation is detectable downstream. - If **no** (streaming with...",
    "operational_effect": "With the boundary enforced, the budget guard reads server-observed counts (or applies a margin to estimates), so context-saturation is predicted against the *billed* prompt, not the authored one — the Turn 2 overflow above is caught at Turn 1. Cost dashboards sum a reconciled ledger and surface error-path omissions as a separate `estimated` line rather than ..."
  },
  "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": "968345fcba01035c55d816f6704504100e964d66324dc1b898a10de0f1d772e7",
    "verified_classes": [
      "TokenLedgerReconciliationError"
    ],
    "verified_functions": [
      "finalize_genai_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TokenLedgerReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
