# When must an instance refuse to inherit a parent span's token accounting across a federated agent trace **Date of Record:** 2026 November 30 **Scope:** Applies to multi-agent systems where OpenTelemetry GenAI spans (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.operation.name`) are stitched across process boundaries via W3C `traceparent` propagation and merged into a single trace for cost/latency attribution. Does not apply to single-process, single-agent instrumentation where span parentage is unambiguous. ## Core Distinction The failure is not "missing spans" or "clock skew." It is the **silent double-counting of token usage when a child agent re-emits its own `gen_ai.usage.*` attributes onto a span whose parent already declared the same consumption**, because the child was invoked by a router that had *pre-charged* the parent span with an estimated budget rather than actuals. The distinction that matters: a span's `gen_ai.usage.*` is an **observation of consumption**, not a **reservation of capacity**. When a federation merges traces, aggregators that `sum()` usage across the span tree cannot tell the two apart, and the invariant "sum of leaf usage = root usage" is silently violated by a factor of two on every routed call. ## What Was Observed A three-tier agent topology: an orchestrator (A) delegates to a router (B), which fans out to worker instances (C1..Cn). Instrumentation was added at A to emit a `gen_ai.chat` span with `gen_ai.usage.input_tokens` set to the *prompt budget estimate* (e.g., 8192) before the call, then updated on completion. B, receiving the `traceparent`, created child spans and — correctly — emitted its own actual `gen_ai.usage.*` from the worker responses. C workers, being stateless and cheap, emitted their own actuals too. The federated collector merged all three tiers into one trace. The cost dashboard reported ~2.3× the invoice from the model provider. Root cause: A's span carried `gen_ai.usage.input_tokens = 8192` (the estimate), B's child spans carried the *actual* routed tokens (e.g., 2100 + 1900 + 2400 = 6400), and the aggregator's `sum_over_spans` counted both. The estimate on A was never zeroed after the child spans reported actuals, because there is no spec-level rule requiring a parent to relinquish its provisional usage when a child asserts it. The latency attribution failure was subtler and more damaging: A's span duration (wall clock of the whole routed call) was attributed to A's "own" latency, while B's child spans overlapped it. P99 dashboards showed A at 4.1s and B at 3.9s — adding to 8.0s for a call that took 4.1s. The trace was not wrong; the *attribution algebra* was. ## Condition of Validity The double-count is only possible when three conditions co-occur: 1. **Provisional usage emission.** A parent span sets `gen_ai.usage.*` before its children exist (budget reservation, pre-flight estimate, or a streaming partial that is later overwritten rather than replaced). 2. **Federation merge without span-kind discrimination.** The aggregator treats every span carrying `gen_ai.usage.*` as a *leaf consumption event* rather than distinguishing `span.kind = INTERNAL` (aggregate) from `span.kind = CLIENT` (actual call). 3. **No `gen_ai.usage.actual` vs `gen_ai.usage.estimated` qualifier.** The GenAI semantic conventions at time of record do not mandate a discriminator attribute, so the merge is lossy by construction. If any one is absent, the invariant holds. The dangerous case is (1)+(2) with (3) absent — the common case in federated deployments where each tier uses a different SDK version and only some emit `span.kind`. ## Decision Boundary An instance must **refuse to inherit** parent token accounting — i.e., must emit its own usage as a *replacement*, not an *addition*, and must mark the parent's provisional usage as superseded — when and only when: - The parent span's `gen_ai.usage.*` was set *before* the child's span start timestamp (provisional), **and** - The child's `gen_ai.operation.name` matches the parent's (same model tier or same provider), **and** - The child's `traceparent` was propagated from the parent (true parentage, not a linked-but-independent call). The boundary is precise: if the child is a *different* model or provider (e.g., a cheap classifier child under an expensive reasoner parent), the usages are **additive and must not be merged** — they are distinct consumption events. The refusal applies only to same-operation re-emission, where the parent's number is an estimate of the child's actual. Concretely, the guardrail is: on span end, if a span has `gen_ai.usage.estimated = true` and any child span in the same trace has `gen_ai.usage.estimated = false` with a matching operation name, the parent must set its usage to zero and emit `gen_ai.usage.superseded_by = `. Aggregators then sum only non-superseded usage. ## Operational Effect Without the guardrail, cost attribution is non-monotonic in fan-out: the more tiers, the larger the multiplier, and the multiplier is invisible because each tier's dashboard looks internally consistent. Teams chasing a "cost spike" will find it correlates with routing depth, not with token volume — a diagnostic signature that points at the merge algebra, not the model. Latency P99s inflate with trace depth for the same reason, and SLO burn-rate alerts fire on the orchestrator while the actual slow hop is a worker. The invariant to enforce at the collector: **for any trace, `sum(gen_ai.usage.input_tokens over spans where estimated != true and superseded_by is null)` must equal the provider invoice for that trace's request IDs.** If it does not, the federation is double-counting and the trace is not a valid attribution record. ```python from dataclasses import dataclass from typing import Optional class AttributionInvariantError(RuntimeError): """Raised when a federated trace's summed usage cannot be reconciled.""" @dataclass class Span: span_id: str parent_id: Optional[str] operation: str input_tokens: int output_tokens: int estimated: bool = False superseded_by: Optional[str] = None end_ns: int = 0 def reconcile_trace(spans: list[Span], provider_invoice_tokens: int) -> int: """Return attributable input tokens; raise if federation double-counts.""" by_id = {s.span_id: s for s in spans} # Enforce: a provisional parent whose child shares operation is superseded. for s in spans: if not s.estimated or s.superseded_by is not None: continue for child in spans: if child.parent_id == s.span_id and child.operation == s.operation: if child.estimated: continue s.superseded_by = child.span_id s.input_tokens = 0 s.output_tokens = 0 break attributable = sum( s.input_tokens for s in spans if not s.estimated and s.superseded_by is None ) # Invariant: attributable usage must match the provider invoice within tolerance. tolerance = max(1, int(0.02 * provider_invoice_tokens)) if abs(attributable - provider_invoice_tokens) > tolerance: raise AttributionInvariantError( f"trace reconciliation failed: summed={attributable} " f"invoice={provider_invoice_tokens} " f"spans={[(s.span_id, s.input_tokens, s.estimated, s.superseded_by) for s in spans]}" ) return attributable ```