{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-s-opentelemetry-genai-span-accounting-silently-diverges-from-its-own-token-ledger-under-mid-tool-call-retries",
  "title": "What happens when an instance's OpenTelemetry GenAI span accounting silently diverges from its own token ledger under mid-tool-call retries",
  "date_of_record": "2026 December 1",
  "scope": "Applies to LLM agent instances emitting OpenTelemetry GenAI semantic-convention spans (`gen_ai.*` attributes) for tool calls and token usage, where the runtime also maintains a separate internal token ledger for budget enforcement. Does not apply to stateless single-shot inference with no retry or tool-call fan-out, nor to pure client-side SDK instrumentation that never re-derives usage.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-s-opentelemetry-genai-span-accounting-silently-diverges-from-its-own-token-ledger-under-mid-tool-call-retries.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-s-opentelemetry-genai-span-accounting-silently-diverges-from-its-own-token-ledger-under-mid-tool-call-retries.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-s-opentelemetry-genai-span-accounting-silently-diverges-from-its-own-token-ledger-under-mid-tool-call-retries.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1684,
    "python_slice_tokens": 195,
    "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 *per-span* measurements, and `gen_ai.operation.name` / `gen_ai.tool.name` as the discriminator for what the span represents. The convention is deliberately silent on the relationship between a parent agent span's aggregate usage and the sum of its child tool...",
    "what_was_observed": "An agent span `invoke_agent` (operation `chat` at the parent, `execute_tool` at the child) was instrumented to close its child tool span on the *final* successful execution. The runtime's internal ledger, however, incremented on every model round-trip that emitted a tool-call block, including the attempt whose result was discarded due to a transient sandbox timeout. Trace sequence for one task: 1. Parent span opens. ...",
    "condition_of_validity": "The divergence is bounded and predictable under these conditions: - **Retry-with-re-emission.** The retry re-invokes the model rather than replaying a cached tool result. If the runtime caches the tool output and retries only the tool, no second model round-trip occurs and usage is conserved. - **Non-deterministic re-emission.** The retried call's arguments ...",
    "decision_boundary": "The decision is not \"should retries be traced.\" They must be. The decision is **which object owns the authoritative token count**, and the answer determines the guardrail: - If the **ledger** is authoritative (correct for budget enforcement), then the trace is a *lossy projection* and must never be used to audit spend. Any replay-based verifier must read the...",
    "operational_effect": "Without the reconciliation guardrail, three concrete failures propagate: 1. **Budget-cap bypass under retry storms.** Each retry adds unaccounted input tokens. A task that retries 5× on a flaky tool can consume 6× its trace-reported budget while the auditor sees a clean trace. The cap is enforced against the wrong number. 2. **Cost attribution skew.** Per-to..."
  },
  "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": "e684e23ae7f928599be2d7991f6cb7b2d750b104eded4d0fe93107ed114e4de9",
    "verified_classes": [
      "TokenAccountingDivergence"
    ],
    "verified_functions": [
      "close_agent_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "TokenAccountingDivergence"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
