# Under what conditions must an instance reject an OpenTelemetry GenAI span as non-authoritative when tool-call events and model-invocation attributes disagree on turn ordering **Date of Record:** 2026 November 19 **Scope:** Applies to any agent runtime that emits or consumes OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) for multi-turn model invocations interleaved with tool-call events, where span export is asynchronous and the tool-call event stream is buffered independently of the model-invocation span tree. Does not apply to single-shot inference telemetry with no tool calls, nor to spans synthesized purely from post-hoc logs. ## Core Distinction The GenAI semantic conventions treat a model invocation (`gen_ai.operation.name = "chat"`) and each tool call (`gen_ai.operation.name = "execute_tool"`) as spans that *can* be parented under a common agent span, but they do not define a mandatory total order across the two families when they are emitted by different instrumentation layers. The convention specifies *attributes* (e.g., `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.tool.name`, `gen_ai.tool.call.id`) and a *parenting* relationship, but it does **not** specify a monotonic sequence number that binds a tool-call event to the specific model-invocation turn that produced it. This creates a distinction that operators routinely conflate: **span-tree parentage is not turn ordering.** Two spans can share a correct parent (the agent span) and still be ordered incorrectly relative to each other in the exported stream, because the model-invocation span is closed by the inference client's exporter while the tool-call span is closed by the tool executor's exporter, and the two exporters flush on independent timers. The `start_time_unix_nano` field is the only ordering signal, and it reflects *when the span was started on the emitting host*, not when the logical turn occurred in the agent's reasoning loop. The boundary condition: an instance must treat the exported GenAI trace as **non-authoritative for turn ordering** whenever the tool-call events and the model-invocation spans cannot be reconciled to a single monotonic sequence by `start_time_unix_nano` alone — i.e., when clock skew, buffered export, or overlapping in-flight turns produce a trace where a `execute_tool` span appears to precede the `chat` span whose completion logically triggered it. ## What Was Observed A tool-using agent (three tools: `search`, `fetch`, `summarize`) ran a task loop that, per turn, invoked the model, parsed a tool call from the response, executed the tool, and fed the result back. Instrumentation was split: the inference client emitted `chat` spans with `gen_ai.request.model`, `gen_ai.usage.*`, and a `gen_ai.response.finish_reasons` attribute; the tool executor emitted `execute_tool` spans with `gen_ai.tool.name` and `gen_ai.tool.call.id`. Both were parented to the same agent span and exported via an OTLP batch processor with a 5-second schedule delay. Under normal load the trace reconstructed cleanly: `chat` → `execute_tool` → `chat` → … in `start_time_unix_nano` order. Under a burst (12 concurrent agent instances on one host, tool executor on a separate process with a 200 ms clock drift and its own batch processor), the reconstructed order for one instance became: ``` execute_tool (search, call_id=c7) start=...100 chat start=...150 finish_reason=tool_calls execute_tool (fetch, call_id=c8) start=...120 chat start=...400 finish_reason=tool_calls ``` Two anomalies appeared simultaneously. First, `execute_tool(search)` appears *before* the `chat` span that requested it — because the tool executor's clock was 200 ms behind and its span started at wall-clock `...100` while the inference client's `chat` span (whose response contained the `search` call) started at `...150` after the client's own startup latency. Second, `execute_tool(fetch)` (start `...120`) sorts *between* the two `chat` spans even though it was logically the second tool call, issued after the first `chat` completed at `...150`. A downstream replay engine that reconstructed the turn sequence by sorting on `start_time_unix_nano` produced a transcript where the agent called `fetch` before it had received the `search` result — an impossible reasoning trace. The `gen_ai.tool.call.id` was present and unique, but nothing in the convention links a `call.id` to the `chat` span whose `finish_reasons` contained `tool_calls`. The linkage exists only in the agent's own in-memory state, which is not exported. ## Condition of Validity The trace is authoritative for turn ordering **only if** all of the following hold: 1. All GenAI spans for a given agent instance are emitted by a single exporter process with a single clock source (no cross-process or cross-host span emission within one logical turn). 2. The batch export delay is strictly greater than the maximum in-flight turn duration, so that spans are never flushed out of logical order relative to their own start times — *and* the exporter preserves emission order within a batch (OTLP does not guarantee this across resource boundaries). 3. Every `execute_tool` span carries a `gen_ai.tool.call.id` that is also recorded as an attribute on (or a child event of) the `chat` span that produced it, establishing an explicit turn linkage independent of timestamps. 4. No two turns overlap in wall-clock time on the same agent instance (single-threaded reasoning loop), so `start_time_unix_nano` is a total order. If any condition fails — and in any multi-process or multi-host agent it will — the timestamp ordering is a *heuristic*, not an invariant, and the instance must not use it to reconstruct reasoning state. ## Decision Boundary The instance must classify the trace as `AUTHORITATIVE` versus `ORDER_AMBIGUOUS` and refuse to replay reasoning from an `ORDER_AMBIGUOUS` trace. The discriminator is a reconciliation check, not a timestamp comparison: - Build the set of `gen_ai.tool.call.id` values from `execute_tool` spans. - Build the set of `call.id` values referenced by `chat` spans (via a linkage attribute or child event). - If the two sets are equal **and** sorting all spans by `start_time_unix_nano` yields a sequence in which every `execute_tool` span is immediately preceded by a `chat` span referencing its `call.id`, the trace is `AUTHORITATIVE`. - If sorting produces a sequence where any `execute_tool` span precedes the `chat` span referencing its `call.id`, or where a `call.id` appears in one set but not the other, the trace is `ORDER_AMBIGUOUS`. On `ORDER_AMBIGUOUS`, the instance must **not** attempt to repair ordering by re-sorting on `end_time_unix_nano`, on `gen_ai.usage` deltas, or on span arrival order at the collector — all three were observed to fail independently under the burst condition. The only safe recovery is to fall back to the agent's own durable turn log (the checkpoint the agent wrote before executing each tool), or to declare the trace unusable for replay and re-run the task from the last checkpoint. ## Operational Effect Enforcing this boundary changes three behaviors: 1. **Replay engines stop fabricating impossible transcripts.** The most damaging failure was not the misordering itself but that a naive replay engine *accepted* the misordered trace and reconstructed a reasoning chain in which the agent used a tool result it had not yet received — silently corrupting any downstream fine-tuning data or audit record derived from the trace. 2. **The `call.id` linkage becomes a hard requirement on instrumentation**, not a nice-to-have. Instrumentation that emits `execute_tool` spans without a corresponding `call.id` reference on the originating `chat` span produces traces that are permanently `ORDER_AMBIGUOUS` and therefore non-replayable. This is a correctness gate on the instrumentation layer, enforced at the consumer. 3. **Clock skew between the inference client and tool executor becomes a first-class monitored quantity.** When the reconciliation check fails, the instance logs the skew between the earliest `chat` start and the earliest `execute_tool` start as a diagnostic, because skew is the most common root cause and it is fixable at the deployment layer (shared clock source, single exporter). The invariant, stated compactly: *a GenAI trace is authoritative for turn ordering iff every tool call is linked to its originating model invocation by an explicit identifier, and the timestamp sort does not contradict that linkage.* Timestamps order spans; identifiers order turns. Conflating the two is the failure. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Iterable class TraceOrderAmbiguousError(RuntimeError): """Raised when a GenAI trace cannot be reconciled to a single turn order.""" @dataclass(frozen=True) class Span: operation: str # "chat" | "execute_tool" start_unix_nano: int tool_call_id: str | None = None # set on execute_tool spans referenced_call_ids: frozenset[str] = field(default_factory=frozenset) # set on chat spans def classify_trace(spans: Iterable[Span]) -> str: """Return AUTHORITATIVE only if call.id linkage and timestamp sort agree.""" spans = list(spans) executed = {s.tool_call_id for s in spans if s.operation == "execute_tool" and s.tool_call_id} referenced = set() for s in spans: if s.operation == "chat": referenced |= set(s.referenced_call_ids) if executed != referenced: missing = executed.symmetric_difference(referenced) raise TraceOrderAmbiguousError( f"call.id linkage mismatch; unreconciled ids: {sorted(missing)}" ) ordered = sorted(spans, key=lambda s: s.start_unix_nano) seen_referenced: set[str] = set() for s in ordered: if s.operation == "chat": seen_referenced |= set(s.referenced_call_ids) elif s.operation == "execute_tool" and s.tool_call_id: if s.tool_call_id not in seen_referenced: raise TraceOrderAmbiguousError( f"execute_tool(call_id={s.tool_call_id}) sorts before the chat span " f"that references it; timestamp order contradicts turn linkage" ) return "AUTHORITATIVE" ```