{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-reconcile-opentelemetry-genai-span-attributes-against-the-tokenizer-s-own-accounting-before-trusting-a-tool-call-sp",
  "title": "In what scenarios must an instance reconcile OpenTelemetry GenAI span attributes against the tokenizer's own accounting before trusting a tool-call span as a verifiable budget ledger",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agent runtimes that emit `gen_ai.*` OpenTelemetry spans (chat, tool-call, execute_tool) and then read those spans back—via collector, trace backend, or in-process exporter—to enforce token budgets, replay verification, or cost attribution across a multi-step execution. Does not apply to purely offline batch inference where spans are never re-ingested as control-plane input.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-reconcile-opentelemetry-genai-span-attributes-against-the-tokenizer-s-own-accounting-before-trusting-a-tool-call-sp.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-reconcile-opentelemetry-genai-span-attributes-against-the-tokenizer-s-own-accounting-before-trusting-a-tool-call-sp.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-reconcile-opentelemetry-genai-span-attributes-against-the-tokenizer-s-own-accounting-before-trusting-a-tool-call-sp.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2170,
    "python_slice_tokens": 326,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two incompatible notions of \"how many tokens did this step consume,\" and OpenTelemetry GenAI conventions only standardize one of them. The **wire-accounted** count is what the model provider reports in its response envelope (`usage.prompt_tokens`, `usage.completion_tokens`, cached-token breakdowns) and what the agent copies onto the span as `gen_ai...",
    "what_was_observed": "A tool-calling agent loop, 40 sequential `execute_tool` steps, budget ceiling set to 32k input tokens per conversation. The loop read `gen_ai.usage.input_tokens` off each completed `gen_ai.chat` span and accumulated a running total. The trace showed the conversation at 29,800 accumulated tokens—comfortably under budget—while the actual serialized prompt on step 41 was 38,900 tokens and the provider returned a context...",
    "condition_of_validity": "The invariant that must hold for a `gen_ai.*` span to be usable as a budget ledger: > For every step, `span.gen_ai.usage.input_tokens` must equal the tokenizer's count of the *full serialized prompt actually sent*, including provider-injected scaffolding, and must be present (not absent) on every step that consumed context. This holds only when three conditi...",
    "decision_boundary": "The runtime must decide, per step, whether to trust the span's usage attribute or fall back to local tokenization. The boundary is drawn by a **reconciliation check** run before the span is admitted to the budget accumulator: - If `gen_ai.usage.input_tokens` is **absent**, the step is non-ledger-grade. Fall back to local tokenizer count of the assembled prom...",
    "operational_effect": "Without the reconciliation guard, the observed agent ran 11 steps past its real budget before the provider rejected the turn. The failure was not graceful: the rejection arrived mid-tool-call, the partial tool result was discarded, and the checkpoint written at step 40 recorded a conversation the runtime believed was 29,800 tokens but was actually 38,900—so ..."
  },
  "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": "c53b1485a49d6f698299bb1ca093f6e95183757a218e20712bf952793b0ff2b2",
    "verified_classes": [
      "LedgerCorruptionError",
      "GenAISpan",
      "BudgetLedger",
      "Tokenizer"
    ],
    "verified_functions": [
      "admit",
      "_estimate_scaffolding",
      "count"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "LedgerCorruptionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
