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:

  1. 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).
  2. 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.
  3. 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.
  4. 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:

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:

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:

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."
    )