# What happens when an instance reports GenAI token usage across a span boundary that the OTel semantic conventions do not reconcile **Date of Record:** 2026 November 28 **Scope:** Applies to LLM agent runtimes that emit OpenTelemetry spans using the GenAI semantic conventions (`gen_ai.*`) for inference, tool-call, and agent-orchestration spans, where token accounting is aggregated across nested spans by a downstream collector or cost-attribution pipeline. Does not apply to single-span, single-model deployments that emit usage on exactly one span per request, nor to non-OTel tracing backends with native token meters. ## Core Distinction The GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes on the span that *represents the model invocation*. They deliberately do not define an aggregation rule for parent agent spans that fan out to multiple child inference spans. This is a semantic gap, not a bug: the conventions describe what a single inference span reports, not what an orchestrator span should report when it summarizes its children. The failure mode is produced by the interaction of two things the conventions leave unspecified: 1. **Whether an orchestrator span may carry its own `gen_ai.usage.*` attributes.** Nothing forbids it. Many agent frameworks copy the child usage up to the parent for convenience. 2. **Whether a collector sums usage across the span tree or reads it per-span.** Nothing specifies it. Cost pipelines do both, depending on vendor. The result is that a correctly-instrumented agent can produce a trace in which total token consumption is counted twice — once at the leaf inference span, once at the ancestor agent span that copied the value up — with no schema violation anywhere in the trace. Every span is individually valid. The aggregate is wrong. This is a continuity invariant failure: the trace is internally consistent span-by-span but violates the conservation invariant that total reported usage equals total actual usage across the tree. ## What Was Observed An agent runtime executing a three-step plan (classify → retrieve → synthesize) emitted the following span tree for a single user turn: - `agent.run` (root, agent orchestration span) - `gen_ai.chat` step 1 (classifier) — `gen_ai.usage.input_tokens=812`, `output_tokens=47` - `tool.retrieve` — no usage attributes (correct; tool spans do not invoke the model directly) - `gen_ai.chat` step 2 (synthesizer) — `gen_ai.usage.input_tokens=2410`, `output_tokens=390` The runtime's wrapper, written to make dashboards easy, copied the sum of child usage onto the root span: `agent.run` carried `gen_ai.usage.input_tokens=3222`, `output_tokens=437`. Two downstream consumers processed this trace: - **Consumer A** (per-span cost attribution) summed `gen_ai.usage.input_tokens` across *all* spans in the trace and got **6444** input tokens. - **Consumer B** (leaf-only accounting, filtering to spans with `gen_ai.operation.name=chat`) got **3222** input tokens. The true figure is 3222. Consumer A overcounted by exactly 2×, and the factor is not stable — it equals the number of ancestor spans that copied usage up the tree. In a deeper recursive agent (a planner that invokes sub-agents that each invoke inference), the overcount factor grows with nesting depth. A three-level agent tree where each level copies child sums up produces a 3× overcount on the root path. The trace was accepted by the OTel collector without warning. No span failed schema validation. The `gen_ai.*` attributes were all well-formed. The duplication was invisible at the span level and only surfaced when two accounting pipelines disagreed on the same trace by a factor of two. A second, subtler observation: when the classifier step was retried after a transient 429 from the provider, the retry emitted a *new* `gen_ai.chat` span with its own usage. The runtime's parent-sum logic copied only the *final* successful child's usage up, silently dropping the failed attempt's consumed input tokens (the provider billed for the rejected prompt). Leaf-only accounting captured the retry span; parent-sum accounting did not. So the two consumers disagreed in the opposite direction on retried turns: parent-sum undercounted, leaf-only overcounted relative to the true billed amount. ## Condition of Validity The double-count is only observable — and only harmful — when all of the following hold: 1. At least one ancestor span in the trace carries `gen_ai.usage.*` attributes that duplicate values present on descendant spans. 2. A downstream consumer aggregates usage by summing across the span tree rather than selecting a single canonical span per invocation. 3. The trace contains more than one inference span under a common ancestor (otherwise the duplication factor is 1 and the two accounting methods coincide). When any condition fails, the trace is safe. A flat trace with one inference span per request cannot double-count. A consumer that reads usage only from spans carrying `gen_ai.operation.name=chat` is immune to ancestor duplication regardless of what the ancestors carry. The retry-undercount is a distinct condition: it appears when a runtime collapses multiple attempt spans into a single parent usage value, and it is only detectable when the failed attempt spans are still present in the trace (i.e., the runtime did not drop them). If the runtime suppresses failed-attempt spans, the loss is unrecoverable from the trace alone. ## Decision Boundary The boundary is **where usage is allowed to be authoritative**. The conventions do not name an authoritative span, so the runtime must impose one. Two coherent policies exist, and mixing them is what produces the failure: - **Leaf-authoritative:** `gen_ai.usage.*` appears *only* on spans that represent an actual model invocation (`gen_ai.operation.name=chat` or equivalent). Ancestor agent spans carry structural attributes (`gen_ai.agent.name`, step index, parent linkage) but never usage. Aggregation is a tree walk that sums leaves. This is the policy the conventions most directly support, because usage is defined as an inference-span attribute. - **Root-authoritative:** usage appears *only* on the root orchestration span, aggregated by the runtime, and leaf inference spans omit usage. Aggregation reads the root. This is cheaper to consume but loses per-step attribution and makes retry accounting the runtime's responsibility alone. The invariant that must hold regardless of policy: **for any trace, exactly one span per model invocation carries that invocation's usage, and no ancestor duplicates it.** Enforce this at emission time, not at collection time — by the time the collector sees the trace, the duplication is indistinguishable from legitimate multi-model fan-out. The decision point for a runtime author is therefore not "should I copy usage to the parent for convenience" (the answer is no under leaf-authoritative) but "which single span is the canonical carrier, and does my emitter guarantee uniqueness." A runtime that copies usage up *and* leaves it on the leaf has chosen neither policy and will double-count under any summing consumer. ## Operational Effect Under leaf-authoritative emission, cost dashboards that sum leaves are correct by construction, and per-step attribution survives. The cost is that a consumer wanting total-per-turn must walk the tree rather than read one attribute — a small, bounded cost paid once in the collector. Under root-authoritative emission, total-per-turn is a single attribute read, but the runtime must own retry aggregation: it must sum usage across *all* attempt spans, including failed ones that consumed input tokens, and emit that sum on the root. A runtime that copies only the successful attempt's usage silently under-reports on every retried turn, and the error is proportional to retry rate — invisible on healthy traces, material during provider incidents when retries spike exactly when cost accuracy matters most. The failure is operationally dangerous because it is *silent and directionally inconsistent*: on clean turns the double-count inflates cost (alarming, but visible as a discrepancy between two pipelines); on retried turns the collapse deflates cost (not alarming, and masked because the failed spans look like noise). A team that reconciles the two pipelines by "trusting the higher number" will over-provision budget during normal operation and under-provision during incidents. The guardrail is a conservation check at the collector: for each trace, assert that the set of spans carrying `gen_ai.usage.input_tokens` has no ancestor-descendant pairs both carrying the attribute. Violation is a schema error in the runtime's emitter, not a collector bug, and should be rejected at the pipeline boundary rather than reconciled downstream. ```python class UsageAttributionError(RuntimeError): """Raised when a trace violates the single-carrier usage invariant.""" def validate_usage_attribution(spans): """ spans: list of dicts with keys 'span_id', 'parent_id', and optionally 'gen_ai.usage.input_tokens' / 'output_tokens'. Enforces: no span carrying gen_ai.usage.* may have a descendant that also carries gen_ai.usage.*. Exactly one carrier per invocation. """ by_id = {s["span_id"]: s for s in spans} def carries_usage(span): return ( "gen_ai.usage.input_tokens" in span or "gen_ai.usage.output_tokens" in span ) def ancestors(span): cur = span.get("parent_id") while cur is not None and cur in by_id: parent = by_id[cur] yield parent cur = parent.get("parent_id") for span in spans: if not carries_usage(span): continue for anc in ancestors(span): if carries_usage(anc): raise UsageAttributionError( f"span {span['span_id']} carries gen_ai.usage.* but " f"ancestor {anc['span_id']} also carries it; " f"usage is double-counted under tree-sum aggregation. " f"Emit usage on exactly one span per model invocation." ) def aggregate_leaf_usage(spans): """Sum usage across spans that carry it, after validating uniqueness.""" validate_usage_attribution(spans) total_in = sum(s.get("gen_ai.usage.input_tokens", 0) for s in spans) total_out = sum(s.get("gen_ai.usage.output_tokens", 0) for s in spans) return total_in, total_out ```