# What structural signals indicate token-accounting lineage collapse when OpenTelemetry GenAI spans are re-parented across agent handoffs **Date of Record:** 2026 November 24 **Scope:** Applies to multi-agent systems emitting OpenTelemetry GenAI semantic convention spans (`gen_ai.*` attributes) where a child agent inherits a parent's span context via context propagation (W3C traceparent) across an A2A/MCP handoff, and where token usage is aggregated per-trace for billing or budget enforcement. Does not apply to single-agent traces with a single root span, nor to systems that emit flat, unparented spans with externally reconciled IDs. ## Core Distinction There is a difference between *trace topology* (who called whom, encoded in `parent_span_id`) and *cost topology* (who consumed which tokens, encoded in `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens`). The GenAI semantic conventions assume these two topologies are congruent: a span's token usage is attributed to the agent that owns the span, and the span's parent is the agent that invoked it. When an agent handoff re-parents a span without re-attributing usage — or re-attributes usage without re-parenting — the two topologies decouple silently. The trace still validates, the spans still export, and the sum of `gen_ai.usage.*` still equals the total the provider charged. What breaks is the *lineage*: the mapping from tokens to the agent that should be held accountable for them. This is not a data-loss failure; it is a data-*misattribution* failure that survives schema validation. ## What Was Observed A three-agent pipeline — planner (A), executor (B), auditor (C) — was instrumented with GenAI spans. B was invoked by A via an A2A handoff that carried the W3C `traceparent`. B, in turn, invoked C via MCP tool call. The intended topology was a clean chain: `span_A → span_B → span_C`. What actually exported: - `span_B` carried `parent_span_id = span_A.span_id` correctly, but its `gen_ai.usage.input_tokens` included the *entire* prompt A had sent to B **plus** the tool-schema tokens B injected for the C call. B reported 4,812 input tokens. - `span_C` carried `parent_span_id = span_B.span_id`, but its usage reflected only C's own completion (312 output tokens), because C's client library did not propagate the `gen_ai.usage.*` attributes from the MCP response envelope — MCP tool results are opaque payloads, and the GenAI conventions have no defined carrier for usage attribution across a tool boundary. - The trace-level sum of `gen_ai.usage.input_tokens` was 4,812 + 0 = 4,812, but the provider billed 4,812 (A→B) + 4,812 (B's re-send to C, since B echoed its full context) = 9,624. The trace *under-counted* the C leg by 100% because the C invocation's input tokens were folded into B's span, not C's. The structural signal that flagged this was not a validation error. It was a **lineage discontinuity**: `span_C.parent_span_id == span_B.span_id` was true, but `span_C.gen_ai.usage.input_tokens == 0` while `span_C.gen_ai.request.model` was populated and `span_C.status.code == OK`. A span that made a real model call but reports zero input tokens is the canonical fingerprint of lineage collapse. ## Condition of Validity The invariant holds — usage attributes are congruent with parent-child topology — only under three simultaneous conditions: 1. **Every span that performs a model invocation carries a non-zero `gen_ai.usage.input_tokens`.** A span with a `gen_ai.request.model` attribute and `status.code == OK` but zero input tokens is invalid; the model was called, so input was consumed. 2. **The `parent_span_id` of a span points to the span whose agent *paid* for the invocation, not merely the span that *triggered* it.** In a handoff, the triggering agent and the paying agent differ. The convention does not distinguish these; the implementation must. 3. **Tool-boundary usage is carried explicitly.** When agent B invokes agent C through an MCP tool call, the usage C consumes must be emitted on `span_C`, not absorbed into `span_B`. MCP's `CallToolResult` envelope has no standard field for this; the convention is silent, so the transport drops it. When any of these fails, the trace remains structurally valid but the cost topology is wrong. The failure is *silent*: no exporter error, no OTel validation warning, no schema violation. It is detected only by cross-checking span-level usage against provider-side billing, or by the structural heuristic below. ## Decision Boundary The boundary is between **re-parenting for topology** and **re-attributing for cost**. These are separate operations and must be performed separately: - **Re-parent** when a span's causal trigger changes (e.g., B's span is re-pointed from A to a retry-wrapper span). This changes `parent_span_id` only. - **Re-attribute** when the agent that bears the token cost changes (e.g., a delegation where A pays for B's tokens because A holds the API key). This changes `gen_ai.usage.*` ownership and must emit a distinct span or an explicit `gen_ai.usage.attribution` attribute — which the current convention does not define. The decision boundary is crossed — and lineage collapse occurs — when a single span is re-parented *and* its usage is left in place, or when usage is re-attributed *without* a corresponding span re-parent. Either operation alone is safe; performing one and inferring the other is the failure. Concretely: if `span_C` is a child of `span_B` but `span_C`'s input tokens were paid by A (because A's credential was forwarded), then `span_C.parent_span_id` correctly encodes *trigger* lineage (B triggered C) while `gen_ai.usage.input_tokens` on `span_C` incorrectly encodes *cost* lineage (A paid). The trace says C spent A's tokens, which is false, and the per-agent cost rollup charges C for A's spend. ## Operational Effect The downstream effect is a **budget-enforcement inversion**. Per-agent token budgets are computed by summing `gen_ai.usage.*` over spans whose `parent_span_id` chain resolves to that agent's root. When lineage collapses: - The delegating agent (B) appears to consume the delegate's (C's) input tokens, inflating B's apparent spend by the delegate's prompt size. - The delegate (C) appears to consume zero input, so its budget never trips — it can be invoked unboundedly without triggering the per-agent cap. - Trace-level totals may still reconcile against provider billing, masking the per-agent error. The observable symptom is a budget alert on the *wrong* agent, or no alert at all on an agent that is actually exhausting the shared quota. In the observed pipeline, B hit its per-agent cap and was throttled while C — the actual consumer — ran uncapped for 40 minutes before the shared provider quota was exhausted. The guardrail is a **lineage-consistency check** at export time: for every span with a populated `gen_ai.request.model` and `status.code == OK`, assert `gen_ai.usage.input_tokens > 0`; and for every span whose `parent_span_id` resolves to a different agent identity than the span's own `gen_ai.agent.id` (or equivalent resource attribute), assert that usage attribution is explicit (a dedicated attribution attribute or a separate cost span). Absent that, treat the span as lineage-collapsed and refuse to roll it into per-agent budgets. ```python class LineageCollapseError(RuntimeError): """Raised when a GenAI span's token usage is incongruent with its parent-child topology.""" pass def validate_genai_lineage(span: dict) -> None: """ Enforce the usage/topology congruence invariant for a single exported GenAI span. span keys (subset of OTel GenAI semconv): span_id, parent_span_id, gen_ai.request.model, gen_ai.usage.input_tokens, gen_ai.usage.output_tokens, gen_ai.agent.id, status.code """ model = span.get("gen_ai.request.model") status = span.get("status.code", "UNSET") input_tokens = span.get("gen_ai.usage.input_tokens", 0) # Condition 1: a span that made a model call must report input tokens. if model and status == "OK" and input_tokens == 0: raise LineageCollapseError( f"span {span.get('span_id')} invoked model {model!r} with status OK " f"but reported 0 input tokens; usage was absorbed into an ancestor " f"(parent_span_id={span.get('parent_span_id')}). Cost lineage is broken." ) # Condition 2: cross-agent parent implies explicit usage attribution. parent_agent = span.get("parent_gen_ai.agent.id") own_agent = span.get("gen_ai.agent.id") if parent_agent and own_agent and parent_agent != own_agent: if not span.get("gen_ai.usage.attribution"): raise LineageCollapseError( f"span {span.get('span_id')} is parented to agent {parent_agent!r} " f"but owned by agent {own_agent!r} with no gen_ai.usage.attribution; " f"trigger lineage and cost lineage have decoupled." ) def rollup_per_agent(spans: list[dict]) -> dict[str, int]: """Sum input tokens per agent, refusing to attribute collapsed spans.""" totals: dict[str, int] = {} for s in spans: validate_genai_lineage(s) agent = s.get("gen_ai.agent.id", "") totals[agent] = totals.get(agent, 0) + s.get("gen_ai.usage.input_tokens", 0) return totals ```