# Under what conditions must an instance reject a GenAI agent span when tool-call attributes and token-cost telemetry disagree at the emission boundary **Date of Record:** 2026 November 29 **Scope:** Applies to any agent runtime that emits OpenTelemetry spans using the GenAI semantic conventions (`gen_ai.*`) for agent invocations, tool calls, and token/cost accounting, particularly when a single logical agent turn is decomposed across multiple spans (agent → tool → sub-agent). Does not apply to single-shot LLM inference spans with no tool-call children, nor to runtimes that emit only a single flat span per turn with no parent/child decomposition. ## Core Distinction The GenAI semantic conventions treat *token usage* and *tool-call identity* as two independent attribute families that happen to live on adjacent spans. Usage (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.usage.cost`) is a **cumulative, monotone, per-model** quantity. Tool-call attributes (`gen_ai.tool.name`, `gen_ai.tool.call.id`, `gen_ai.operation.name`) are **per-span, non-cumulative, and identity-bearing**. The boundary failure is not that either family is wrong in isolation — it is that the *emission boundary* (the moment a child tool span closes and its parent agent span is finalized) forces a reconciliation between a cumulative quantity and a per-call identity, and there is no invariant in the spec that makes this reconciliation well-defined. Concretely: a tool span can legitimately report the tokens its *own* model call consumed, while its parent agent span reports the tokens the *orchestrating* model consumed to decide to make the call. When the runtime propagates usage upward (as most exporters do to satisfy `gen_ai.usage.*` being present on the root agent span), it double-counts the tool's tokens into the parent's total. The span tree is structurally valid, the attributes are individually spec-compliant, and the aggregate cost telemetry is silently wrong by the sum of all child tool-call usage. ## What Was Observed A multi-tool agent turn (one orchestrator model, three sequential tool calls, each tool backed by a small model) produced this span tree: ``` agent.invoke (root) gen_ai.usage.input_tokens = 8_412 gen_ai.usage.output_tokens = 1_204 gen_ai.usage.cost = 0.0214 ├── tool.call [search] gen_ai.usage.input_tokens = 2_100 output = 300 ├── tool.call [extract] gen_ai.usage.input_tokens = 3_050 output = 410 └── tool.call [summarize] gen_ai.usage.input_tokens = 1_900 output = 250 ``` The root's `input_tokens` (8,412) was computed by the orchestrator's own tokenizer over its prompt — it did *not* include the tool spans' 7,050 input tokens. But the downstream cost aggregator, following the convention that a span's `gen_ai.usage.cost` is the total cost attributable to that span *and its descendants*, summed root + children and reported 0.0214 + (tool costs) ≈ 0.0481. The orchestrator's own cost was 0.0214; the true turn cost was ~0.0481. Neither number was wrong; the *semantic* of `gen_ai.usage.cost` on the root span was ambiguous, and the aggregator picked the interpretation the runtime did not intend. The failure triggered only when three conditions coincided: (1) tool spans carried their own `gen_ai.usage.*` attributes, (2) the root span also carried `gen_ai.usage.*`, and (3) the aggregator applied the "sum descendants" rule. Remove any one condition and the double-count disappears — which is why it survived staging (single-tool turns, where the tool span had no usage attributes) and only manifested in production at the first turn that used a model-backed tool. ## Condition of Validity The invariant that must hold for aggregate cost telemetry to be correct is: > For every span S carrying `gen_ai.usage.cost`, the value MUST equal the cost of model inference performed *by S's own operation*, and MUST NOT include the cost of any descendant span. Descendant costs are aggregated by the consumer, not the producer. This is the *non-cumulative producer* invariant. It is violated the moment a runtime propagates child usage upward "for convenience" so that the root span looks self-contained. The spec does not forbid this propagation, and many SDKs do it by default, because a root span with no usage attributes is harder to query in a naive dashboard. But propagation converts a correct tree into an incorrect tree for any consumer that also sums descendants. The condition of validity is therefore: **the producer must pick exactly one aggregation convention and the consumer must be told which one.** The GenAI conventions do not currently encode this choice as an attribute, so the runtime must either (a) emit non-cumulative usage on every span and require consumers to sum, or (b) emit cumulative usage only on the root and strip it from all descendants. Mixing the two — cumulative root, non-cumulative children — is the boundary failure, and it is the default behavior of at least two widely used instrumentation libraries. ## Decision Boundary At the emission boundary, the runtime must decide, per span, whether to write `gen_ai.usage.*` based on the span's *role*, not its *content*. The decision rule: - **Root agent span:** emit usage for the orchestrator model only. Do not add descendant usage. If the runtime wishes to expose turn-total cost, it must use a *distinct* attribute name (e.g., `agent.turn.total_cost`) so that a consumer summing `gen_ai.usage.cost` across the tree does not double-count. - **Tool span backed by a model:** emit usage for that tool's model call. It is a legitimate producer of usage. - **Tool span not backed by a model** (pure function, retrieval, shell): emit *no* `gen_ai.usage.*` attributes. Emitting zero-valued attributes is worse than omitting them, because a consumer cannot distinguish "zero cost" from "not measured." - **Sub-agent span:** treated as a root for its own subtree; same rule as root, scoped to its subtree. The boundary is crossed the instant a span writes a usage value that includes inference it did not perform. The guardrail is a pre-emission assertion: for every span, the sum of `gen_ai.usage.input_tokens` over its *direct* children must be ≤ the span's own reported input tokens *only if* the span is declared cumulative; otherwise the span must assert that its usage is disjoint from its children's. Since the spec has no `gen_ai.usage.aggregation` attribute today, the runtime must enforce disjointness structurally. ## Operational Effect The observable effect is a cost telemetry stream that is internally consistent (every span validates against the schema) and externally wrong (turn cost inflated by the sum of tool-model costs). In the observed case, the inflation was 2.25×. The failure is silent: no span is malformed, no exporter errors, no alert fires on schema validation. It is only detectable by reconciling the aggregate against the model provider's billing API, which lags by hours to a day — long after the turn's cost decisions (budget enforcement, per-tenant chargeback, autoscaling on cost-per-turn) have already acted on the wrong number. The secondary effect is worse: budget-enforcement loops that read `gen_ai.usage.cost` from the root span to decide whether to halt an agent will halt *early*, because the inflated root cost crosses the budget threshold before the true cost does. An agent that should have completed its turn is killed mid-execution, producing a truncated tool-call sequence and a root span whose usage no longer matches any real inference. The telemetry failure and the execution failure become coupled. The required guardrail is a reconciliation check at the exporter boundary: for each agent turn, assert `root.gen_ai.usage.cost + Σ(descendant.gen_ai.usage.cost) == provider_billed_cost(turn)` within tolerance, and reject the turn's telemetry (quarantine, do not export) if the invariant fails. Quarantining is correct here because exporting a tree that violates the non-cumulative-producer invariant poisons every downstream consumer; the cost of a missing turn in the dashboard is lower than the cost of a systematically inflated one. ```python class GenAIUsageInvariantError(RuntimeError): """Raised when a GenAI span tree violates the non-cumulative-producer invariant for gen_ai.usage.* attributes at the emission boundary.""" pass def validate_usage_tree(span, tolerance=1e-6): """Enforce: a span's gen_ai.usage.cost must equal its own inference cost and must be disjoint from its descendants' costs. Returns the turn-total cost (root + all descendants), which is the value a consumer is expected to compute. Raises if the producer already propagated descendant usage upward (double-count). """ own_cost = span.attributes.get("gen_ai.usage.cost") if own_cost is None: own_cost = 0.0 descendant_total = 0.0 for child in span.children: descendant_total += validate_usage_tree(child, tolerance) # If the producer propagated child usage into this span, own_cost will # already include descendant_total. Detect the overlap. if descendant_total > 0 and own_cost >= descendant_total - tolerance: # Ambiguous: could be legitimate (own cost happens to exceed children) # or propagated. Disambiguate via the disjointness declaration. declared_cumulative = span.attributes.get( "gen_ai.usage.aggregation", "per_span" ) == "cumulative" if not declared_cumulative: raise GenAIUsageInvariantError( f"span {span.name!r} (trace {span.trace_id}) reports " f"gen_ai.usage.cost={own_cost} which is >= descendant total " f"{descendant_total} without declaring " f"gen_ai.usage.aggregation='cumulative'. This is the " f"double-count boundary: a consumer summing descendants will " f"report {own_cost + descendant_total} instead of the true " f"turn cost. Strip descendant usage from this span or set " f"the aggregation attribute explicitly." ) return own_cost + descendant_total def emit_turn(span, exporter): try: turn_total = validate_usage_tree(span) except GenAIUsageInvariantError: # Quarantine: do not export a tree that would poison cost aggregation. exporter.quarantine(span) raise exporter.export(span, turn_total=turn_total) ```