# Under what conditions must an instance treat a GenAI tool-call span as non-authoritative when its `gen_ai.tool.call.id` is reused across a retry boundary **Date of Record:** 2026 November 29 **Scope:** Applies to any agent runtime that emits OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*`) and reconstructs execution history, cost attribution, or replay state from those spans. Does not apply to span consumers that treat telemetry purely as observability (human dashboards) with no feedback into agent decision-making. ## Core Distinction The GenAI semantic conventions specify `gen_ai.tool.call.id` as an identifier for a single tool invocation, and `gen_ai.operation.name = "execute_tool"` on the span that wraps it. The conventions do **not** specify a uniqueness or idempotency contract across retries, resumptions, or re-emissions of the same logical call. This produces a fault line between two readings of the same span: - **Observability reading:** a span is an immutable record of one attempt; duplicate `tool.call.id` values are merely correlated events. - **Control-plane reading:** a span is a claim about what the agent *did and can rely on*; a stable `tool.call.id` is treated as "this call happened once, here is its authoritative result." An agent that consumes its own (or a peer's) span stream to rebuild state — for example, to decide whether a tool has already been executed before resuming a checkpointed task — is doing the control-plane reading. Under that reading, identifier reuse across a retry boundary silently collapses N attempts into one logical fact, and the fact selected is whichever span the consumer happens to see last. ## What Was Observed A checkpointed agent resumes a task mid-execution. The checkpoint was taken after a `execute_tool` span was *started* but before its result was durably recorded. On resume, the runtime re-issues the tool call. Because the tool-call ID is derived deterministically (e.g., `hash(task_id, step_index, tool_name)` — a common pattern chosen precisely to make retries idempotent at the *tool server*), the retry emits a second span with the **same** `gen_ai.tool.call.id`. The trace now contains two `execute_tool` spans sharing one `tool.call.id`, differing in: - `start_time` / `end_time` (retry is later) - `gen_ai.tool.call.result` or the span status (`ERROR` on the first, `OK` on the second — or the reverse if the first timed out but actually succeeded server-side) - `span_id` (always distinct) A state-reconstruction consumer that indexes spans by `tool.call.id` and keeps the last-written value is now correct *only if* the last-written span is also the last-*completed* attempt. These diverge whenever spans are exported out of order — which is the normal case for a batch span processor that flushes the first (errored) span late, after the retry span has already been exported. The consumer then believes the tool failed when it succeeded, or vice versa, and the agent either re-executes a non-idempotent side effect or skips a step whose only successful attempt was the one it discarded. The failure is not in the tool, not in the retry logic, and not in the span exporter individually. It is in the **implicit invariant** the consumer assumes: *`gen_ai.tool.call.id` is unique per logical operation and its latest-arriving span reflects the terminal outcome.* Neither half of that invariant is guaranteed by the specification. ## Condition of Validity The control-plane reading of a tool-call span is valid only when **all** of the following hold: 1. The producer guarantees `gen_ai.tool.call.id` is freshly minted per *attempt*, not per *logical call* — i.e., retries get new IDs and are linked via `gen_ai.tool.call.id` being absent or via a separate `retry_of` attribute (the spec does not define this; you must). 2. The consumer orders spans by `end_time`, not by export arrival, and treats any span without a terminal status as *unknown*, never as *failed*. 3. The tool is declared idempotent, or a deduplication key independent of `tool.call.id` is carried in the span attributes and honored by the tool server. If any of these is violated, the span stream is an observability artifact and must not be used to gate execution. ## Decision Boundary The precise boundary: **a consumer may treat a `gen_ai.tool.call.id` as authoritative for "this call completed with result R" only if exactly one terminal-status span exists for that ID in the reconstructed window, and that span's `end_time` is not superseded by a later-starting span sharing the ID.** If two or more terminal spans share the ID, the ID is *contested* and the consumer must fall back to the tool server's own idempotency record (or refuse to resume and escalate). If zero terminal spans exist but one non-terminal span does, the state is *indeterminate* — the call may have succeeded server-side and the span simply never closed — and the consumer must not assume failure. The trap is that the naive rule ("last terminal span wins") passes every happy-path test and fails exactly on the resume-after-checkpoint, out-of-order-flush case, which is rare enough to escape staging and common enough to corrupt production state. ## Operational Effect An agent that violates this boundary exhibits a characteristic corruption signature: after a mid-task crash and resume, it either (a) re-executes a side-effecting tool whose first attempt actually succeeded (duplicate charge, duplicate message, duplicated file append), or (b) marks a step complete based on a stale errored span and proceeds with missing state, causing downstream reasoning divergence that surfaces many steps later with no traceable cause. The trace looks clean — one `tool.call.id`, apparently one call — which is precisely why it evades diagnosis. The guardrail is to never let the telemetry plane be the source of truth for execution gating unless the producer has explicitly minted per-attempt IDs and the consumer has an ordering discipline that survives out-of-order export. ```python from dataclasses import dataclass from typing import Iterable, Optional class ContestedToolCallIdError(RuntimeError): """Raised when a tool.call.id cannot be resolved to a single authoritative outcome.""" pass class IndeterminateToolCallError(RuntimeError): """Raised when no terminal span exists but a non-terminal span does (call may have succeeded).""" pass @dataclass(frozen=True) class ToolSpan: tool_call_id: str span_id: str start_time: float end_time: Optional[float] # None => non-terminal (still open or never closed) status: Optional[str] # "OK" | "ERROR" | None result: Optional[str] = None def resolve_authoritative_outcome( spans: Iterable[ToolSpan], tool_call_id: str ) -> ToolSpan: """Resolve the single terminal span that may gate execution for a given tool.call.id. Enforces the decision boundary: exactly one terminal span, not superseded by a later-starting span sharing the same id. Otherwise raise. """ candidates = [s for s in spans if s.tool_call_id == tool_call_id] if not candidates: raise ContestedToolCallIdError(f"no spans for tool.call.id={tool_call_id!r}") terminal = [s for s in candidates if s.end_time is not None and s.status is not None] open_spans = [s for s in candidates if s.end_time is None or s.status is None] if not terminal: # A call may have succeeded server-side with a span that never closed. raise IndeterminateToolCallError( f"tool.call.id={tool_call_id!r} has {len(open_spans)} non-terminal span(s); " "cannot assume failure" ) if len(terminal) > 1: # Retry boundary reused the id: multiple attempts, contested authority. raise ContestedToolCallIdError( f"tool.call.id={tool_call_id!r} has {len(terminal)} terminal spans " f"(span_ids={[s.span_id for s in terminal]}); id reused across retry boundary" ) winner = terminal[0] # Supersession check: any span starting later than the winner's start invalidates # the winner as terminal for the logical call. later = [s for s in candidates if s.span_id != winner.span_id and s.start_time > winner.start_time] if later: raise ContestedToolCallIdError( f"tool.call.id={tool_call_id!r} terminal span {winner.span_id!r} is superseded " f"by later-starting span(s) {[s.span_id for s in later]}" ) return winner ```