# When must an instance refuse to emit a GenAI tool-call span it cannot attribute to a single model turn **Date of Record:** 2026 November 28 **Scope:** Applies to agents instrumented with OpenTelemetry GenAI semantic conventions (`gen_ai.*`) that emit `execute_tool` child spans under an `invoke_agent` or `chat` span, where tool invocation may be triggered by parallel model turns, retried by a supervisor loop, or replayed from a checkpoint. Does not apply to pure retrieval spans or to spans emitted by a deterministic orchestrator with a single serialized model call per tool dispatch. ## Core Distinction The GenAI semantic conventions treat a tool-call span as a *child of a specific model turn* — the `chat` span that produced the tool call request. The attribute set (`gen_ai.tool.name`, `gen_ai.tool.call.id`, `gen_ai.operation.name=execute_tool`) presumes a 1:1 binding between one model response and one tool execution. That binding is an *invariant*, not a guarantee. The failure mode is not "tool span missing" or "wrong tool name" — it is **span mis-attribution under fan-out and replay**, where a single `gen_ai.tool.call.id` is emitted under two parent `chat` spans, or where a tool span survives a checkpoint resume but its parent `chat` span does not. The trace tree stays syntactically valid; the causal graph is silently wrong. The non-obvious boundary: OpenTelemetry's span model tolerates orphaned children (they become roots) and duplicate span IDs across batches (last-writer-wins at the collector). Both tolerances are *lossy* for GenAI traces, because the semantic convention's whole value proposition — reconstructing "which model turn caused which tool call" — depends on a strict parent-child identity that the transport layer will happily violate without raising. ## What Was Observed A multi-step agent with a planner loop executed a `search_docs` tool call. The planner model response contained two parallel tool calls (`call_a`, `call_b`) in one `chat` span. The executor dispatched both concurrently. `call_a` succeeded in 340ms. `call_b` hit a sandbox timeout at 30s, was retried by the supervisor, and on retry was re-emitted under a *new* `chat` span generated by a re-planning step that re-derived the tool call from scratch. Result: - `call_b` appears twice in the trace, once under the original `chat` span (status `ERROR`, timeout) and once under the re-plan `chat` span (status `OK`). - Both carry the same `gen_ai.tool.call.id`, because the re-planner copied the call ID from the failed turn's context. - A downstream trace-based evaluator counted two distinct tool invocations and flagged the agent as "redundant tool use," when the actual execution was one call plus one retry. - Separately, a checkpoint resumed mid-task emitted the `execute_tool` span for `call_a` with `parent_span_id` pointing at a `chat` span that had been evicted from the in-memory span buffer before export. The orphaned tool span exported as a root, breaking the `invoke_agent → chat → execute_tool` chain in the backend. The invariant violated: **`gen_ai.tool.call.id` must be unique per (parent `chat` span, tool name) pair, and every `execute_tool` span must export after its parent `chat` span or carry an explicit `gen_ai.tool.retry_of` link.** Neither is enforced by the semconv; both are required for causal reconstruction. ## Condition of Validity The strict parent-child binding is valid only when all of the following hold: 1. **Single model turn owns the tool call.** The `gen_ai.tool.call.id` is minted by the model response and never re-minted by a supervisor, re-planner, or checkpoint resume. 2. **Span export order preserves ancestry.** The parent `chat` span is exported (or at least buffered) before the `execute_tool` child, or the child carries an explicit `SpanContext` link to the parent. 3. **Retries are distinguished, not duplicated.** A retried tool call must either reuse the original span (with a `retry.count` attribute) or emit a new span with `gen_ai.tool.retry_of` pointing at the original `call.id`, and the original must be closed with `ERROR` status before the retry opens. 4. **No fan-out ambiguity.** When one `chat` span yields N parallel tool calls, each child carries a distinct `call.id` and the parent span is not closed until all N children are closed or explicitly abandoned. When any of these is violated — which is the normal case under supervisor retries, checkpoint resume, and parallel tool dispatch — the semconv's parent-child semantics are *undefined*, and the trace becomes a plausible-looking fiction. ## Decision Boundary The instance must **refuse to emit** a `gen_ai.tool.call.id` that it cannot bind to a single, currently-open parent `chat` span. Concretely: - If a tool call is re-derived by a re-planner, it is a **new** call: mint a new `call.id`, set `gen_ai.tool.retry_of` to the prior ID, and emit under the re-plan `chat` span. Do not copy the old ID. - If the parent `chat` span has already been closed or evicted, the tool span must be emitted with an explicit `Link` to the parent's `SpanContext` rather than as a child, and the exporter must be configured to drop (not orphan-promote) tool spans whose parent is unknown. - If a checkpoint resume cannot reconstruct the parent `chat` span, the resumed tool execution must be tagged `gen_ai.tool.resumed_from_checkpoint=true` and the parent set to the `invoke_agent` span, not fabricated. The boundary is: **attribution fidelity over span completeness.** A missing tool span is a recoverable gap; a mis-attributed tool span is a poisoned trace that will corrupt every downstream evaluator, cost model, and latency SLO computed from it. ## Operational Effect Without this boundary, three failure classes propagate: 1. **Cost and latency inflation.** Duplicate `call.id`s under different parents double-count tool latency and token cost in any trace-derived metric. 2. **Evaluator corruption.** Trace-based evals that count tool invocations or measure retry rates will report phantom redundancy, triggering spurious agent "fixes." 3. **Causal misdiagnosis.** An orphaned tool span promoted to root loses its `chat` parent, so post-mortems attribute a tool failure to the agent root rather than to the specific model turn that requested it — the exact opposite of what GenAI semconv was designed to enable. The guardrail is a pre-export attribution check: every `execute_tool` span must resolve to an open or explicitly-linked parent `chat` span with a matching `call.id` minted by that parent, or it is rejected at the exporter with a structured error, not silently promoted. ```python from dataclasses import dataclass from typing import Optional class ToolSpanAttributionError(RuntimeError): """Raised when a gen_ai execute_tool span cannot be bound to a single model turn.""" pass @dataclass class ChatSpan: span_id: str call_ids: set[str] closed: bool = False @dataclass class ToolSpan: span_id: str call_id: str parent_span_id: Optional[str] retry_of: Optional[str] = None resumed_from_checkpoint: bool = False def emit_tool_span( tool: ToolSpan, open_chats: dict[str, ChatSpan], known_call_ids: dict[str, str], # call_id -> owning chat span_id ) -> None: # Invariant 1: call_id must be owned by exactly one chat span. owner = known_call_ids.get(tool.call_id) if owner is not None and owner != tool.parent_span_id: raise ToolSpanAttributionError( f"call_id {tool.call_id!r} already owned by chat {owner!r}; " f"refusing to re-attribute to {tool.parent_span_id!r} without retry_of" ) if owner is not None and tool.retry_of is None and not tool.resumed_from_checkpoint: raise ToolSpanAttributionError( f"duplicate emit of call_id {tool.call_id!r} with no retry_of marker" ) # Invariant 2: parent chat must be open, or the span must declare a resume. parent = open_chats.get(tool.parent_span_id) if tool.parent_span_id else None if parent is None: if not tool.resumed_from_checkpoint: raise ToolSpanAttributionError( f"tool span {tool.span_id!r} has no open parent chat " f"{tool.parent_span_id!r} and is not a checkpoint resume; " "refusing to orphan-promote" ) elif parent.closed: raise ToolSpanAttributionError( f"parent chat {parent.span_id!r} already closed; " "emit as Link, not child" ) # Invariant 3: call_id must be one the parent actually minted. if parent is not None and tool.call_id not in parent.call_ids: raise ToolSpanAttributionError( f"call_id {tool.call_id!r} was not minted by parent chat {parent.span_id!r}" ) known_call_ids.setdefault(tool.call_id, tool.parent_span_id) # ... export span here ... ```