{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-opentelemetry-genai-agent-spans-from-silently-under-accounting-tokens-across-tool-call-boundaries",
  "title": "Which invariants prevent OpenTelemetry GenAI agent spans from silently under-accounting tokens across tool-call boundaries",
  "date_of_record": "2026 December 2",
  "scope": "Applies to agents that emit OpenTelemetry spans per the GenAI semantic conventions (`gen_ai.*` attributes) and whose tool calls re-enter the same logical task. Does not cover single-shot, single-span inference calls or span pipelines that never re-enter an agent loop after a tool result.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-opentelemetry-genai-agent-spans-from-silently-under-accounting-tokens-across-tool-call-boundaries.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-opentelemetry-genai-agent-spans-from-silently-under-accounting-tokens-across-tool-call-boundaries.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-opentelemetry-genai-agent-spans-from-silently-under-accounting-tokens-across-tool-call-boundaries.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2010,
    "python_slice_tokens": 292,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define attributes for *one inference operation* (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.operation.name`, `gen_ai.request.model`) and a separate `execute_tool` span for tool invocation. They do **not** define a parent-level aggregate for a multi-step agent turn. The distinction that matters: a span tr...",
    "what_was_observed": "A research agent using a ReAct loop over three tools (search, fetch, summarize) was instrumented with the GenAI conventions. Each step emitted an `invoke_agent` parent span, a `chat` child span with `gen_ai.usage.*`, and an `execute_tool` child span. Over a 48-hour window, the exported token totals under-reported provider billing by 11.3%. The deficit was not uniform: it concentrated on turns where a tool returned a ...",
    "condition_of_validity": "The invariant holds only under the following conditions, and fails silently outside them: - **Retry visibility.** Every retry of an inference call must produce its own span, or the parent span must carry a `gen_ai.usage.*` that sums all attempts. A retry wrapper that lives below the instrumentation boundary violates this. Guardrail: instrument at the transpo...",
    "decision_boundary": "The operational decision is: **do you trust the span tree as the source of truth for token accounting, or do you reconcile it against provider billing?** - If the agent runs retries below the instrumentation boundary, or mutates prompts after span close, or hands off tool results across id-minting boundaries — you **cannot** trust the span tree. You must rec...",
    "operational_effect": "Downstream consumers of the trace — cost dashboards, per-tool attribution, budget enforcers, and agent-evaluation harnesses — inherit the under-count. A budget enforcer that reads `gen_ai.usage.*` from the span tree will under-estimate spend and fail to trip its threshold before the provider's hard limit is hit, producing a mid-turn 429 that the agent's retr..."
  },
  "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": "ec9107e5692bcb7e625f0ee5d74caaa7009af2e4077ebd1f57713504c72cc929",
    "verified_classes": [
      "TokenAccountingInvariantError",
      "Span"
    ],
    "verified_functions": [
      "reconcile_turn",
      "walk"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "TokenAccountingInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
