# Where must an instance bound the parent-child span cardinality of a single tool call before GenAI semantic convention export, or the whole trace collapses into an un-attributable fan-out **Date of Record:** 2026 December 2 **Scope:** Applies to any agent runtime that emits OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*` attributes) for an `execute_tool` child span under an `invoke_agent` parent, where a single logical tool call is retried, fanned out, or streamed. Does not apply to single-shot, non-retried tool invocations with one span per call, nor to pure model-inference spans without tool children. ## Core Distinction The GenAI semantic conventions treat a tool call as a *logical operation* with a stable identity (`gen_ai.tool.name`, `gen_ai.tool.call.id`) and an associated token/usage attribution. The OTel trace model treats every emitted span as an independent node keyed by `span_id` with a `parent_span_id`. These two models disagree at exactly one point: **when one logical tool call produces N physical spans** (retries, parallel sub-calls, streaming chunks, or a fan-out to a sub-agent that re-invokes the same tool). The convention says "one tool call, one `gen_ai.tool.call.id`"; the transport says "one span, one `span_id`." Nothing in the convention mandates that the `call.id` be unique across spans, and nothing in the SDK deduplicates it. The boundary condition is therefore: **the moment a single `gen_ai.tool.call.id` appears on more than one exported child span, token attribution and causal replay both become ambiguous, and the ambiguity is silent.** The non-obvious part: the failure is not a crash. The trace exports cleanly. The collector accepts every span. The damage is entirely in the *downstream consumer* — a cost aggregator, an auditor replaying the trace, or a sibling agent reading the parent's span to decide whether to retry. Each of those consumers resolves "which child span is the authoritative result of tool call X" differently, and they resolve it inconsistently. ## What Was Observed A research agent (`invoke_agent` span, `gen_ai.agent.name=planner`) issued a tool call to `web.search` with `gen_ai.tool.call.id=call_7f3a`. The tool adapter's HTTP client had a 4-second deadline; the upstream search API returned a `503` at 3.9s on the first attempt. The adapter's retry policy re-issued the request with the *same* `call.id` (correctly — it is the same logical call), and the second attempt succeeded at 1.2s with a different result set. The instrumentation wrapped each physical attempt in its own `execute_tool` span. Both spans carried `gen_ai.tool.call.id=call_7f3a`, `gen_ai.tool.name=web.search`, and — critically — each carried its own `gen_ai.usage.input_tokens` (the adapter tokenizes the query per attempt) and its own `gen_ai.tool.result` event. The failed attempt also emitted an exception event with `error.type=503`. Three consumers then diverged: 1. **Cost aggregator** summed `gen_ai.usage.input_tokens` across *all* spans with the same `call.id`, double-counting the query tokenization and inflating reported spend by ~40% on retry-heavy traces. 2. **Auditor replay** selected the *first* span by `start_time` with a matching `call.id` (the failed 503 attempt), concluded the tool call errored, and flagged the agent's subsequent reasoning as "hallucinated on failed evidence" — even though the agent had used the successful second result. 3. **Sibling verifier agent**, reading the parent `invoke_agent` span's child list to confirm the tool result before voting on the plan, saw two children and could not determine which `gen_ai.tool.result` was authoritative; it deadlocked waiting for a tiebreak that no one had defined, until the swarm's global step budget expired. The trigger condition is precise: **retry-on-same-`call.id` combined with per-attempt usage emission and no span-level disambiguator.** Remove any one of those three and the trace is coherent. ## Condition of Validity The invariant that must hold for a GenAI trace to be replayable and attributable is: > For any `gen_ai.tool.call.id`, exactly one *terminal* child span under a given `invoke_agent` parent may carry `gen_ai.usage.*` and `gen_ai.tool.result`, and every non-terminal attempt must be marked so that a consumer can exclude it from attribution without heuristics. This requires three things the convention does not enforce on its own: - A **terminal marker**: the authoritative span carries `gen_ai.tool.status=success` (or a convention-blessed equivalent) and all prior attempts carry `gen_ai.tool.attempt=N` with `N < terminal`. Without an explicit attempt ordinal, "first by start_time" and "last by end_time" are the only available heuristics, and they disagree under out-of-order export (common when the failed attempt's exporter batches later than the successful one's). - **Usage isolation**: `gen_ai.usage.input_tokens` must be emitted *only* on the terminal span, or a consumer must sum only terminal spans. Per-attempt tokenization is real cost, but it must be attributed to an `attempt` dimension, not to the logical call, or the cost aggregator's sum is wrong by construction. - **Result singularity**: at most one `gen_ai.tool.result` event per `call.id` per parent. Retried-then-succeeded calls that emit results on both attempts violate this and make replay non-deterministic. The invariant is *not* "one span per tool call" — that would forbid legitimate retry observability. It is "one *attributable* span per tool call, with all others explicitly demoted." ## Decision Boundary The runtime must make a hard choice at the moment a retry is scheduled, and the choice determines whether the trace stays coherent: - **Collapse (single-span retry):** reuse the same `span_id`, extend `end_time`, accumulate an `attempt` counter as a span attribute, emit usage once at terminal. Pro: trivially satisfies the invariant; consumers see one child. Con: loses per-attempt latency and error detail, which is exactly what retry debugging needs. - **Fan-out with demotion (multi-span retry):** emit a span per attempt, but stamp every non-terminal attempt with `gen_ai.tool.attempt` and *withhold* `gen_ai.usage.*` and `gen_ai.tool.result` from them; emit usage and result only on the terminal attempt, and set `gen_ai.tool.call.id` on all of them. Pro: full retry observability. Con: requires every downstream consumer to honor the demotion, which means the demotion must be a *contract*, not a convention. The boundary is crossed when a team picks fan-out (for observability) but does not propagate the demotion contract to the cost aggregator and the auditor. The convention permits fan-out; it does not protect you from consumers that ignore `attempt`. **The decision boundary is: if any downstream consumer of your traces is not under your control (a vendor cost tool, a cross-team auditor, a sibling agent's verification logic), you must collapse, or you must publish the demotion contract as a versioned schema and refuse to export non-conforming spans.** ## Operational Effect When the invariant is violated, the observable symptoms are indirect and misattributed: - Cost dashboards drift upward on retry-heavy traffic and *downward* on traces where the failed attempt exported after the successful one and a "last-write-wins" aggregator overwrote the terminal usage with the failed attempt's (often zero) usage. - Auditor replay produces false "hallucination" verdicts at a rate proportional to the tool error rate — the auditor is reading the wrong span, not detecting a real reasoning fault. - Multi-agent verification deadlocks when a verifier's tiebreak logic is undefined for duplicate `call.id` children; the deadlock surfaces as a global step-budget timeout, which is blamed on the planner's reasoning rather than on trace ambiguity. The guardrail is a pre-export validation gate on the span batch: before the exporter flushes, assert that for every `(parent_span_id, gen_ai.tool.call.id)` pair, at most one child carries `gen_ai.usage.*` and at most one carries a `gen_ai.tool.result` event, and that every other child carries an `attempt` ordinal strictly less than the terminal's. A batch that fails the gate must be rejected — not silently exported — because a silently exported ambiguous trace is worse than a dropped one: the dropped one triggers an alert, the ambiguous one triggers a wrong decision three hops downstream. ```python from dataclasses import dataclass, field from typing import Optional class GenAIAttributionError(RuntimeError): """Raised when a span batch violates the tool-call attribution invariant.""" @dataclass class Span: span_id: str parent_span_id: Optional[str] tool_call_id: Optional[str] = None has_usage: bool = False has_result_event: bool = False attempt: Optional[int] = None terminal: bool = False def validate_tool_attribution(batch: list[Span]) -> None: """ Enforce: for each (parent_span_id, tool_call_id), exactly one terminal child may carry usage and result; all others must be demoted with an attempt ordinal strictly less than the terminal's. """ groups: dict[tuple[str, str], list[Span]] = {} for span in batch: if span.tool_call_id is None: continue key = (span.parent_span_id or "", span.tool_call_id) groups.setdefault(key, []).append(span) for (parent, call_id), spans in groups.items(): terminals = [s for s in spans if s.terminal] if len(terminals) != 1: raise GenAIAttributionError( f"call {call_id} under parent {parent}: expected exactly 1 " f"terminal span, found {len(terminals)}" ) terminal = terminals[0] if not (terminal.has_usage and terminal.has_result_event): raise GenAIAttributionError( f"call {call_id}: terminal span {terminal.span_id} missing " f"usage or result event" ) for s in spans: if s is terminal: continue if s.has_usage or s.has_result_event: raise GenAIAttributionError( f"call {call_id}: non-terminal span {s.span_id} carries " f"usage/result; attribution would double-count" ) if s.attempt is None or s.attempt >= (terminal.attempt or 0): raise GenAIAttributionError( f"call {call_id}: non-terminal span {s.span_id} lacks a " f"valid attempt ordinal below terminal" ) def export_batch(batch: list[Span], exporter) -> None: try: validate_tool_attribution(batch) except GenAIAttributionError: # Reject, do not silently export an ambiguous trace. raise exporter.flush(batch) ```