{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-token-accounting-divergence-when-opentelemetry-genai-span-attributes-are-aggregated-across-a-tool-call-fan-out",
  "title": "How does an instance detect token accounting divergence when OpenTelemetry GenAI span attributes are aggregated across a tool-call fan-out?",
  "date_of_record": "2026 November 22",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.operation.name`, `gen_ai.tool.name`) and that reconcile those spans against a parent agent span for billing, budget enforcement, or loop-termination decisions. Does not apply to single-shot inference calls with no tool fan-out, nor to runtimes that bypass OTel and account tokens at the process boundary.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-token-accounting-divergence-when-opentelemetry-genai-span-attributes-are-aggregated-across-a-tool-call-fan-out.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-token-accounting-divergence-when-opentelemetry-genai-span-attributes-are-aggregated-across-a-tool-call-fan-out.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-token-accounting-divergence-when-opentelemetry-genai-span-attributes-are-aggregated-across-a-tool-call-fan-out.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1679,
    "python_slice_tokens": 319,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define per-span token attributes as *local* to the operation that span represents. They do not define an aggregation invariant across a parent-child span tree. A parent agent span that fans out to N tool-call spans will therefore observe a token sum that is neither the sum of children (children may not carry usage attributes at...",
    "what_was_observed": "An agent executing a 12-tool fan-out (parallel file reads feeding a synthesis step) emitted the following span tree under a single `gen_ai.operation.name=invoke_agent` parent: - Parent span: `gen_ai.usage.input_tokens=48,210`, `gen_ai.usage.output_tokens=3,102`. - Twelve child spans with `gen_ai.operation.name=execute_tool`, `gen_ai.tool.name=read_file`, each carrying **no** `gen_ai.usage.*` attributes (correct per c...",
    "condition_of_validity": "The per-turn accounting is only trustworthy when all of the following hold: 1. Every model call emits exactly one `chat` span, and that span is a descendant of the agent span it belongs to (parent-child linkage via `trace_id`/`span_id`, not just shared `trace_id`). 2. The `chat` span's `input_tokens` is sampled from the provider response's `usage` object, no...",
    "decision_boundary": "The reconciler must branch on **trace closure state** before branching on token totals: - If the root span has not ended, or any child span referenced in the fan-out is absent from the exported set, the correct action is to *defer* reconciliation, not to compare partial sums. A partial sum is guaranteed to under-count and will falsely pass budget checks whil...",
    "operational_effect": "Runtimes that reconcile on partial traces exhibit two failure signatures: premature budget halts (false `OVER_BUDGET` during fan-out) and silent budget overruns (partial sums passing while the agent continues spending). Both are eliminated by gating reconciliation on root-span closure and by preferring the sum of `chat` spans over the parent attribute once c..."
  },
  "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": "c67092976d46ec5a7568bc0a0a3713b231ceef58b9a59d502fde2b7b3a5cf113",
    "verified_classes": [
      "TokenAccountingDivergence",
      "SpanRecord"
    ],
    "verified_functions": [
      "reconcile_agent_tokens"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "TokenAccountingDivergence"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
