Under what conditions must an instance reject a GenAI span whose token-accounting attributes are internally consistent but semantically orphaned by tool-call fan-out
**Date of Record:** 2026 December 1 **Scope:** Applies to any agent runtime that emits OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*`) where a single logical agent turn fans out into multiple tool-call child spans and token usage is reported per assistant message rather than per span. Does not apply to single-shot completion telemetry, nor to runtimes that emit one span per model invocation with usage attributes scoped strictly to that invocation.
Core Distinction
The GenAI semantic conventions treat `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes of a *model invocation* span, and `gen_ai.tool.name`, `gen_ai.tool.call.id`, and tool arguments/results as attributes of *tool execution* spans. In a naive executor these two layers are emitted 1:1 — one model span, one tool span. But a real agent loop is N:1 in the other direction: one assistant message may contain *several* tool calls in a single completion, and the tokens billed for that completion cover the reasoning that produced *all* of them. The boundary condition is this: the token attributes on the parent model span are arithmetically correct, the tool-call child spans are individually well-formed, and yet the *attribution graph is orphaned* — there is no way to reconstruct which output tokens paid for which tool call, because the convention provides no per-tool token partition and the executor does not synthesize one.
An instance must reject (or explicitly annotate as un-attributable) such a span when the tool-call fan-out count on a model span exceeds one and the runtime has no recorded partition of output tokens across the child tool calls. Accepting it silently produces telemetry that looks complete and is analytically wrong: cost-per-tool dashboards, retry-budget analysis, and context-saturation alarms will all mis-attribute because they divide or duplicate a single token figure across siblings.
What Was Observed
A three-tool turn — `search_docs`, `read_file`, `run_tests` — emitted as children of a single `gen_ai.chat` span carrying `gen_ai.usage.output_tokens = 412`. Each child tool span carried `gen_ai.tool.name` and a `gen_ai.tool.call.id`, and each was individually valid against the convention. The failure trace:
- The model span closed with `output_tokens=412` and three `gen_ai.tool.call` child spans, none carrying usage attributes (the convention does not define them for tool spans).
- A downstream cost-attribution job summed `output_tokens` grouped by `gen_ai.tool.name`. Because no tool span had usage, the job fell back to the parent span and — by its own default — *copied* the parent's 412 to each of the three children.
- The dashboard reported 1,236 output tokens for a turn that cost 412. The error factor was exactly the fan-out count, and it was invisible because every individual number was a real number.
- Worse, the retry-budget alarm read the inflated figure, concluded the turn was near the context ceiling, and suppressed a legitimate retry on a subsequent turn — a *behavioral* consequence of a *telemetry* defect.
The non-obvious part: the child spans were not malformed. A schema validator passes them. The defect lives in the *absence* of a partition, which no per-span validator can see because it only ever inspects one span at a time.
Condition of Validity
The invariant that makes a fanned-out model span safe to emit is:
> For every `gen_ai.chat` span S with child tool-call spans C₁…Cₙ (n > 1), the sum of any per-child token attribution must be ≤ `gen_ai.usage.output_tokens(S)`, and the runtime must record *explicitly* either a partition (Σ = parent) or a declared "unpartitioned" marker so consumers cannot default to duplication.
This holds only when one of three conditions is met:
- **Partitioned:** the runtime instrumented the completion to split output tokens across the n tool calls (rare, and only approximate — the model does not emit token boundaries per call).
- **Declared-unpartitioned:** the parent span carries an explicit attribute (e.g. `gen_ai.usage.attribution = "aggregate"`) instructing consumers to attribute the whole figure to the parent and *not* to children.
- **n = 1:** the fan-out is a single tool call, so parent and child are trivially 1:1 and duplication is harmless.
When none hold — n > 1, no partition, no marker — the span set is valid-looking but violates the invariant, and the instance must not treat it as authoritative telemetry.
Decision Boundary
The instance decides at span-close time, not at query time, because the query-time consumer cannot distinguish "child has no usage because it's unpartitioned" from "child has no usage because it's zero." The boundary is:
- If `n == 1`: emit normally; the 1:1 mapping is sound.
- If `n > 1` and a partition attribute is present and `Σ partition == output_tokens`: emit with partition; consumers may attribute per-child.
- If `n > 1` and no partition: the instance MUST set `gen_ai.usage.attribution = "aggregate"` on the parent and MUST NOT copy usage onto children. If it cannot set the marker (e.g. the exporter schema forbids custom attributes), it MUST raise a telemetry-integrity error rather than emit an ambiguous span, because an ambiguous span is worse than a missing one — it is silently wrong.
The line is not "is the token number correct" (it always is, on the parent) but "is the attribution *unambiguous* to a consumer that only sees individual spans."
Operational Effect
Enforcing the invariant converts a silent 3× cost inflation into a loud, at-source rejection. The practical consequences:
- Cost dashboards switch from `sum(output_tokens by tool)` to `sum(output_tokens by parent)`, and per-tool cost becomes an explicitly-modeled approximation with a known error term (fan-out count), not a phantom precise number.
- Retry-budget and context-saturation alarms stop firing on inflated figures, restoring the retry behavior they had been suppressing.
- The rejection surfaces missing instrumentation at emit time, when the executor still has the completion object and can be fixed, rather than weeks later when a billing discrepancy is traced back through three services.
The cost is that some turns now fail to export until the executor is taught to set the aggregate marker. That is the correct trade: a rejected span is recoverable, an orphaned one is not.
class OrphanedTokenAttributionError(RuntimeError):
"""Raised when a GenAI model span fans out to multiple tool calls
without a token partition or an aggregate marker, making per-tool
attribution ambiguous to span-at-a-time consumers."""
def validate_genai_turn(
output_tokens: int,
tool_call_ids: list[str],
partition: dict[str, int] | None,
attribution_marker: str | None,
) -> str:
"""Return the attribution mode to emit, or raise if the span set is orphaned.
Invariant: for n > 1 children, either a partition summing to the parent
figure exists, or an explicit 'aggregate' marker must be set. Otherwise
the span is internally consistent but semantically orphaned.
"""
n = len(tool_call_ids)
if n == 0:
return "none"
if n == 1:
return "single"
if partition is not None:
if set(partition) != set(tool_call_ids):
raise OrphanedTokenAttributionError(
f"partition keys {sorted(partition)} do not match "
f"tool calls {sorted(tool_call_ids)}"
)
if sum(partition.values()) != output_tokens:
raise OrphanedTokenAttributionError(
f"partition sum {sum(partition.values())} != "
f"parent output_tokens {output_tokens} across {n} calls"
)
return "partitioned"
if attribution_marker == "aggregate":
return "aggregate"
raise OrphanedTokenAttributionError(
f"model span fans out to {n} tool calls with output_tokens="
f"{output_tokens} but no partition and no aggregate marker; "
f"consumers will duplicate the figure {n}x. Refusing to emit "
f"ambiguous telemetry."
)