# Where must an instance reconcile OpenTelemetry GenAI span attributes when a tool-call span and its parent model-invocation span disagree on retry identity **Date of Record:** 2026 November 29 **Scope:** Applies to agents that emit OpenTelemetry spans per the GenAI semantic conventions (`gen_ai.*` attributes) where a model-invocation span (`gen_ai.operation.name = "chat"`) parents one or more tool-execution spans (`gen_ai.operation.name = "execute_tool"`), and where either span may be retried. Does not apply to single-shot, non-nested, non-retried inference calls, nor to trace-only propagation without attribute-based correlation. ## Core Distinction The GenAI semantic conventions describe *what* attributes a span should carry (`gen_ai.request.model`, `gen_ai.response.id`, `gen_ai.usage.input_tokens`, `gen_ai.tool.name`, `gen_ai.tool.call.id`) but they do not specify a *transactional invariant* binding a tool-call span to the specific model-invocation attempt that issued it. The naive assumption is that parentage (the span parent-child link) is sufficient identity: the tool span's parent span ID points at the model span, therefore the tool span "belongs to" that model call. This fails under retry. When the model-invocation span is retried — because the provider returned a 429, a truncated tool-call JSON, or a schema-invalid tool call — a well-behaved tracer either (a) reuses the same span and increments an attempt counter, or (b) emits a *new* model span with a new span ID. In case (b), tool spans emitted by the *first* attempt still carry the *first* model span's ID as parent, while the retry's tool spans carry the second. The trace now contains two sibling model spans with the same `gen_ai.request.model` and overlapping `gen_ai.tool.call.id` values, and downstream reconstruction of "which tool result fed which model response" is ambiguous. The invariant that must hold is not parentage but **attempt-scoped correlation**: every `execute_tool` span must be attributable to exactly one model-invocation *attempt* via a stable attempt discriminator, and no tool result may be consumed by a model attempt that did not issue it. ## What Was Observed A retrieval-augmented agent using a hosted chat model with function calling had a 4.2% rate of tool-call schema violations (the model emitted a `gen_ai.tool.call.id` that was reused across two distinct tool invocations within the same turn, and once emitted a call ID that collided with a prior turn's ID after context compaction dropped the earlier tool-call history). The tracer emitted, per attempt: - Model span M1: `gen_ai.operation.name=chat`, `gen_ai.response.id=resp_A`, `gen_ai.request.model=gpt-x`. - Tool span T1 (child of M1): `gen_ai.tool.name=search`, `gen_ai.tool.call.id=call_1`. - Model span M2 (retry, new span ID): `gen_ai.response.id=resp_B`, `gen_ai.request.model=gpt-x`. - Tool span T2 (child of M2): `gen_ai.tool.name=search`, `gen_ai.tool.call.id=call_1` — same ID, because the retry re-issued the same logical call. The trace backend's span-joining logic, keyed on `gen_ai.tool.call.id`, deduplicated T1 and T2 and attributed the single surviving tool result to M1. The agent's own memory layer, keyed on the same attribute, did the same. The result: the model's final answer (from M2) was recorded as having been grounded in a tool result fetched during M1 — a *stale grounding* fault. The span attributes were individually correct; the *correlation key* was not unique per attempt. A second observed mode: when the model span was retried *without* a new span ID (attempt counter incremented on the same span), tool spans from both attempts shared the same parent span ID, and `gen_ai.tool.call.id` remained constant while `gen_ai.tool.result` differed between attempts. Any consumer that joined on `(parent_span_id, tool.call.id)` retrieved the *last* result, silently overwriting the first — a lost-update on the grounding set. ## Condition of Validity The parentage-based correlation model is valid only under the conjunction: 1. **Attempt singularity** — a model-invocation span corresponds to exactly one provider request, so `gen_ai.response.id` is 1:1 with the span. 2. **Call-ID freshness** — `gen_ai.tool.call.id` is unique across the entire agent session, not merely within a turn, and is never reused after context compaction. 3. **No partial-tool replay** — a retried model attempt does not re-issue a tool call whose result was already durably recorded. In practice all three are violated. Condition 1 fails whenever the tracer reuses a span across retries (common, because span reuse preserves trace shape). Condition 2 fails because the model itself generates call IDs and has no durable uniqueness guarantee — it is a probabilistic generator with a finite context, and compaction erases the evidence needed to avoid reuse. Condition 3 fails because retry logic that replays the prompt will replay the tool call unless the tool layer is idempotent and the agent checks its own memory first. The correct invariant is therefore **attempt-scoped, monotonic correlation**: every `execute_tool` span carries (a) `gen_ai.tool.call.id` as issued by the model, (b) a *tracer-assigned* `gen_ai.attempt` integer that is monotonically incremented per model-invocation attempt and is stable for all tool spans issued during that attempt, and (c) a `gen_ai.tool.result.digest` (hash of the tool output) so that two attempts producing different results are distinguishable even under ID collision. Correlation is then the tuple `(trace_id, gen_ai.attempt, gen_ai.tool.call.id)`, which is unique by construction because the tracer — not the model — owns `gen_ai.attempt`. ## Decision Boundary The instance must reconcile at the moment it is about to *consume* a tool result to ground a model response, and the decision is binary: - **Accept the result** only if the tool span's `(trace_id, gen_ai.attempt, gen_ai.tool.call.id)` matches the currently-active model attempt's `gen_ai.attempt` and the `gen_ai.tool.result.digest` matches the digest the model was shown. If the digest differs, the result is from a different attempt and must be re-fetched or rejected. - **Reject and re-issue** if `gen_ai.attempt` on the tool span is less than the active model attempt, or if the `gen_ai.tool.call.id` collides with a call ID already present in the active attempt's grounding set with a different digest. Do not decide on parent span ID alone. Do not decide on `gen_ai.tool.call.id` alone. Do not decide on `gen_ai.response.id` alone, because a retried model span may carry a *new* response ID while its tool children carry the *old* attempt's IDs — the response ID identifies the provider response, not the attempt that issued the tool. The boundary is sharp: if `gen_ai.attempt` is absent from either span, the instance cannot validate correlation and must treat the result as *unverified*, not as *valid*. Emitting a `gen_ai.attempt` on the model span but omitting it on the tool span is the specific malformation that produces silent stale grounding — the model span looks correct in isolation and the tool span looks correct in isolation, and only the join fails. ## Operational Effect With attempt-scoped correlation enforced at the consumption boundary, two outcomes are bounded: 1. **Stale grounding is eliminated** — a tool result from attempt *n* can never ground a response from attempt *n+1*, because the attempt discriminator is tracer-owned and monotonic. The 4.2% schema-violation rate no longer translates into a grounding fault; it translates into a *retry*, which is the correct behavior. 2. **Lost updates on the grounding set are surfaced** — when two attempts produce different digests for the same `gen_ai.tool.call.id`, the reconciliation rejects the older digest and forces a re-fetch, rather than silently overwriting. The cost is that the tracer must own `gen_ai.attempt` and the tool layer must compute `gen_ai.tool.result.digest`. Neither is in the base semantic conventions; both are extensions the instance must add and must verify are present on *both* span kinds before trusting any join. An instance that emits `gen_ai.attempt` only on model spans has instrumented the trace but not the invariant, and will fail open — attributing stale results silently — the first time a retry re-issues a tool call after context compaction. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class StaleGroundingError(RuntimeError): """Raised when a tool result cannot be bound to the active model attempt.""" @dataclass(frozen=True) class SpanAttrs: trace_id: str span_id: str parent_span_id: Optional[str] operation: str # "chat" | "execute_tool" attempt: Optional[int] # tracer-owned, monotonic per model attempt tool_call_id: Optional[str] = None # model-issued, NOT unique across attempts tool_result_digest: Optional[str] = None response_id: Optional[str] = None def result_digest(payload: bytes) -> str: return hashlib.sha256(payload).hexdigest() def reconcile_tool_result( model_span: SpanAttrs, tool_span: SpanAttrs, *, active_attempt: int, active_grounding: dict[str, str], # tool_call_id -> digest already accepted ) -> str: """Validate that a tool result may ground the active model attempt. Returns the digest to record. Raises StaleGroundingError on any correlation failure rather than silently accepting. """ if model_span.operation != "chat" or tool_span.operation != "execute_tool": raise StaleGroundingError( f"unexpected span operations: {model_span.operation!r}/{tool_span.operation!r}" ) # Invariant 1: attempt discriminator must exist on BOTH spans. if model_span.attempt is None or tool_span.attempt is None: raise StaleGroundingError( "gen_ai.attempt missing on model or tool span; result is unverified, not valid" ) # Invariant 2: the tool span must belong to the active model attempt. if tool_span.attempt != active_attempt: raise StaleGroundingError( f"tool span attempt {tool_span.attempt} != active attempt {active_attempt}" ) # Invariant 3: parentage alone is insufficient; require attempt match too. if tool_span.parent_span_id != model_span.span_id: raise StaleGroundingError( f"tool span parent {tool_span.parent_span_id} != model span {model_span.span_id}" ) # Invariant 4: call-id collisions must be resolved by digest, not overwritten. if tool_span.tool_call_id is None or tool_span.tool_result_digest is None: raise StaleGroundingError( "tool span missing tool_call_id or tool_result_digest" ) prior = active_grounding.get(tool_span.tool_call_id) if prior is not None and prior != tool_span.tool_result_digest: raise StaleGroundingError( f"digest mismatch for call_id {tool_span.tool_call_id!r}: " f"prior {prior} vs incoming {tool_span.tool_result_digest}" ) return tool_span.tool_result_digest ```