# What structural signals indicate a GenAI agent span has silently decoupled its tool-call attributes from the actual model invocation it claims to trace **Date of Record:** 2026 November 29 **Scope:** Applies to agents instrumented with OpenTelemetry GenAI semantic conventions (`gen_ai.*`) where a single agent invocation emits both a model-invocation span and one or more tool-execution spans, correlated by trace/span IDs and by `gen_ai.operation.name`. Does not apply to single-shot completion calls with no tool loop, nor to systems that emit a flat span per turn without parent/child linkage. ## Core Distinction The GenAI semantic conventions model an agent turn as a *span tree*: a parent span with `gen_ai.operation.name = "chat"` (or `"invoke_agent"`) carrying model attributes (`gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`), and child spans with `gen_ai.operation.name = "execute_tool"` carrying `gen_ai.tool.name`, `gen_ai.tool.call.id`, and `gen_ai.tool.call.arguments`/`gen_ai.tool.call.result`. The convention assumes the parent span's token accounting and the child spans' tool attributes describe *the same logical exchange*. The failure this record covers is **attribute decoupling**: the span tree remains structurally valid (parent present, children linked, no missing-parent errors) while the tool-call attributes on child spans no longer correspond to the model invocation that actually produced them. This happens because the tool-call ID emitted by the model in its `tool_calls` payload is frequently *regenerated, re-minted, or normalized* by the agent framework before the tool span is created, and because the token counts on the parent are often populated from a *different* response object than the one whose `tool_calls` were dispatched. The trace looks complete. It is not coherent. The distinction that matters operationally: a *broken* trace fails loudly (missing parent, orphaned span, exporter rejection). A *decoupled* trace passes every structural validator while being causally false. Structural signals — not error logs — are the only way to detect it. ## What Was Observed A tool-augmented agent (framework emits OTel GenAI spans, model = a function-calling endpoint) was traced across a 4-step tool loop. The trace exported cleanly: one `invoke_agent` parent, four `execute_tool` children, correct `trace_id` propagation, no dropped spans. Three structural signals indicated decoupling: 1. **`gen_ai.tool.call.id` on children did not appear in the parent's recorded `tool_calls`.** The framework had re-minted call IDs (prefixing them with a local counter) before dispatch. The parent span recorded the model's raw IDs; the children recorded the framework's IDs. A join on `call.id` between the model's actual output and the tool span returned zero rows — but nothing in the span tree flagged this, because the convention does not require the parent to record `tool_calls` at all. 2. **Parent `gen_ai.usage.output_tokens` was constant across all four children.** The parent span was closed *once*, after the loop, with token usage summed from a single response object (the first). Each child, however, was attributed to a distinct model call. The per-call token cost was therefore unrecoverable, and the sum was wrong for three of four steps. The signal: `usage.output_tokens` on the parent did not increase between child spans when child spans were ordered by `start_time`. 3. **`gen_ai.tool.name` on a child did not match any `function.name` the model was offered in that turn.** The framework had renamed a tool at dispatch time (`search` → `web_search`) to route through a local wrapper. The span recorded the dispatched name, not the offered name. A replay against the model's tool schema could not resolve the call. None of these produced an error. All three are detectable purely from span attributes and their relationships. ## Condition of Validity The GenAI conventions are *coherent* — tool attributes faithfully describe the model invocation that produced them — only when all of the following hold: - **Call-ID fidelity:** the `gen_ai.tool.call.id` on a child span equals the `id` field of the corresponding entry in the model's `tool_calls` output for the parent invocation. Any framework-side re-minting, deduplication, or namespacing breaks this. - **Usage attribution:** `gen_ai.usage.*` on a span describes the model call that span represents. If a parent span aggregates multiple model calls, per-call usage must live on per-call child spans, not be summed onto the parent. A parent that carries *both* aggregate usage and child tool spans is ambiguous unless a `gen_ai.usage.aggregation` (or equivalent) attribute disambiguates. - **Name resolution:** `gen_ai.tool.name` on the child equals the `function.name` offered to the model in that turn's request. Dispatch-time aliasing must be recorded (e.g., as a separate `tool.dispatch.name` attribute) rather than overwriting the offered name. - **Temporal nesting:** each child's `[start_time, end_time]` falls within the parent's, and children are non-overlapping for a sequential loop. Overlapping children with a single parent `chat` span indicate concurrent dispatch the parent did not model. When any of these is violated, the span tree is structurally valid but semantically decoupled, and every downstream consumer — cost attribution, replay, audit, eval harnesses keyed on `call.id` — silently reads false data. ## Decision Boundary The boundary is between **trusting the span tree as a causal record** and **treating it as a structural skeleton that requires an independent coherence check**. Concretely: - **Trust directly** only if the instrumentation layer is the *same component* that received the model response and dispatched the tool — i.e., no intermediate framework re-mints IDs or renames tools between response parse and span emit. In that case `call.id` join is guaranteed and usage attribution is per-call by construction. - **Require a coherence check** whenever there is any framework layer between the model client and the tool executor. This is the common case. The check is: for each parent `chat`/`invoke_agent` span, (a) every child `execute_tool` `call.id` must be a member of the set of `tool_calls[].id` the model emitted, and (b) the count of children must equal the count of `tool_calls` in the response, and (c) parent usage must not be a single scalar shared across multiple children without an aggregation marker. - **Reject the trace as evidence** (route to a quarantine pipeline, do not feed to cost/eval systems) if the join fails. Do not "repair" by matching on tool name — name aliasing makes that ambiguous, and a wrong repair is worse than a flagged gap. The boundary is sharp: it is not a tuning threshold but a set-membership invariant. Either the child's call ID is in the model's emitted set or it is not. ## Operational Effect When decoupling goes undetected, the operational consequences are specific and compounding: - **Cost attribution drifts.** Summed parent usage undercounts multi-step loops; per-tool cost becomes unattributable. Budget alarms keyed on `gen_ai.usage.output_tokens` fire late or never. - **Replay and eval diverge.** An eval harness that replays a trace by joining on `call.id` finds zero tool results and scores the trajectory as "no tools used," inflating or deflating pass rates depending on the task. - **Audit trails become non-falsifiable.** A decoupled trace cannot be used to prove what the agent actually did, because the tool attributes do not provably originate from the model output. This is the failure that matters for agent accountability: the record exists, is structurally valid, and is inadmissible. The guardrail is a **coherence validator at the exporter or collector boundary** that enforces the call-ID membership invariant and the usage-attribution rule before spans enter the durable store. It must fail closed — quarantine, not drop — because a decoupled span is evidence of an instrumentation bug that needs fixing, not noise to be discarded. ```python from dataclasses import dataclass, field from typing import Any class SpanCoherenceError(RuntimeError): """Raised when a GenAI agent span tree is structurally valid but causally decoupled.""" @dataclass class ToolCall: call_id: str name: str @dataclass class ModelResponse: """The actual output the model emitted for one invocation.""" tool_calls: list[ToolCall] = field(default_factory=list) output_tokens: int = 0 @dataclass class ToolSpan: call_id: str tool_name: str @dataclass class ParentSpan: operation: str # "chat" | "invoke_agent" recorded_output_tokens: int children: list[ToolSpan] = field(default_factory=list) def validate_coherence(parent: ParentSpan, response: ModelResponse) -> None: """ Enforce the GenAI semantic-convention coherence invariant: every execute_tool child's call.id must be a member of the model's emitted tool_calls, and parent usage must not be a single scalar silently shared across multiple distinct model calls. """ emitted_ids = {tc.call_id for tc in response.tool_calls} if len(parent.children) != len(response.tool_calls): raise SpanCoherenceError( f"child count {len(parent.children)} != model tool_calls " f"{len(response.tool_calls)} for span op={parent.operation}" ) for child in parent.children: if child.call_id not in emitted_ids: raise SpanCoherenceError( f"call.id decoupled: child tool span id={child.call_id!r} " f"not in model-emitted ids={sorted(emitted_ids)!r} " f"(framework likely re-minted the id before dispatch)" ) # Usage attribution: a parent carrying multiple children must not present # a single scalar that claims to be the sum of calls it does not own. if len(parent.children) > 1 and parent.recorded_output_tokens == response.output_tokens: raise SpanCoherenceError( "usage attribution decoupled: parent output_tokens equals a single " "response while multiple tool children are attributed to it; " "per-call usage must live on per-call spans" ) def ingest(parent: ParentSpan, response: ModelResponse) -> None: validate_coherence(parent, response) # fail closed; caller quarantines on raise # ... persist to durable store only after coherence passes ... ```