# When must an instance reconcile OpenTelemetry GenAI span attributes against the actual tool-call transcript, and what breaks when it trusts token accounting alone **Date of Record:** 2026 December 2 **Scope:** Applies to any agent runtime that emits `gen_ai.*` spans per the OpenTelemetry GenAI semantic conventions for tool invocation and token accounting, and that uses those spans as the authoritative record of what an agent did. Does not cover distributed trace sampling policy or backend exporter reliability. ## Core Distinction A GenAI span is a *claim* about execution, not the execution. The `gen_ai.usage.input_tokens` / `output_tokens` attributes, the `gen_ai.tool.name` and `gen_ai.tool.call.id` fields, and the parent `gen_ai.operation.name` links describe an intended call graph. The tool-call transcript (the actual request/response bytes handed to and returned from the tool executor) is the *fact*. These two artifacts are produced at different points in the pipeline by different code paths, and they diverge under precisely the conditions agents care most about: retries, streaming cutoffs, concurrent fan-out, and provider-side tokenizer variance. The invariant is simple and non-negotiable: **an agent may not treat a span's token or tool attributes as ground truth for state continuity unless the span has been reconciled against the transcript it purports to describe.** Token accounting alone is insufficient because it is a scalar summary that cannot distinguish "one call that succeeded" from "three calls that failed and one that succeeded." ## What Was Observed A planning agent issued a `gen_ai.tool` span for a retrieval tool with `gen_ai.usage.input_tokens=1840`, `output_tokens=612`, and a single `gen_ai.tool.call.id`. The span closed with `status=OK`. On resume from a checkpoint keyed to that span ID, the agent replayed its reasoning assuming the retrieval returned 612 tokens of usable context. The transcript showed the tool executor had actually made three attempts: the first two timed out at the transport layer after partial streaming (each consuming ~600 input tokens billed by the provider but not attributed to the span), and the third returned a 190-token truncated response because the upstream truncated at a `max_tokens` the agent never set. The span recorded the *third* attempt's numbers against a call ID the agent had generated once. Net effect: the agent resumed with a context budget it believed was 1840+612 but which was actually ~3040 input and 190 output. It then over-allocated its remaining context window, evicted the checkpoint summary, and re-derived a plan that had already been invalidated. The failure was silent: every span was `status=OK`, every attribute was well-formed, and the trace backend showed a clean single call. A second observation, same class: a fan-out swarm where four sub-agents each emitted a `gen_ai.tool` span with distinct `gen_ai.tool.call.id` values but the *same* `gen_ai.conversation.id`. The aggregator deduplicated by conversation ID under the assumption that one conversation implies one logical call, collapsing four results into one and discarding three sub-agent outputs. The spans were individually correct; the reconciliation rule was wrong. ## Condition of Validity The "trust the span" rule holds only when all of the following are true, and each is independently falsifiable: 1. **Attempt count equals span count.** The tool executor emits exactly one span per network attempt, or the span carries an attempt counter (`gen_ai.tool.call.attempt` or equivalent custom attribute) and the usage attributes are the *sum* across attempts, not the final attempt. Default GenAI conventions do not require this; runtimes that retry must add it. 2. **Token accounting is post-hoc and provider-attested.** `input_tokens`/`output_tokens` must be read from the provider's response payload, not estimated by a local tokenizer. Local estimates diverge 5–15% from provider counts on tool-call-heavy prompts because tool schemas are tokenized differently than the model's chat template. 3. **Call ID is stable across retries.** If the runtime regenerates `gen_ai.tool.call.id` per attempt, the transcript cannot be joined to the span, and reconciliation is impossible—only detection is possible. 4. **Conversation ID is not a call key.** `gen_ai.conversation.id` scopes a multi-turn interaction; it must never be used to deduplicate tool results. Deduplication keys on `gen_ai.tool.call.id` only. 5. **Truncation is recorded.** A response cut by `max_tokens`, a stream close, or a transport timeout must set an attribute (`gen_ai.response.finish_reasons` containing `length`, or a custom `tool.truncated=true`). Absence of this attribute is not evidence of completeness. When any condition fails, the span is a *detector*, not a *source of truth*. It can tell you reconciliation is needed; it cannot tell you what happened. ## Decision Boundary The boundary is between **accounting** and **attestation**. - Below the boundary (accounting): the span's token counts are used for cost dashboards, rate-limit backpressure, and budget projection. Here, a 10% drift is tolerable and span-only trust is fine. - Above the boundary (attestation): the span's attributes are used to (a) reconstruct agent state on resume, (b) decide whether a tool result is complete enough to act on, or (c) resolve conflicts between concurrent agents. Here, span-only trust is a correctness bug. The decision rule an agent should encode: *if a span attribute influences a state transition, it must be reconciled against the transcript within the same checkpoint epoch.* Reconciliation means: join span → transcript by `gen_ai.tool.call.id`, compare `input_tokens`/`output_tokens` against the transcript's provider-reported usage, compare attempt count against span count, and verify `finish_reasons` covers every attempt. If any comparison fails, the span is quarantined and the agent must re-execute or escalate—it may not proceed on the span's numbers. A subtle corollary: reconciliation must happen *before* the checkpoint is committed, not after. A checkpoint that records a span ID without its reconciliation verdict is a poisoned checkpoint—it will be trusted on cold start by an instance that has no transcript to check against. ## Operational Effect Without reconciliation, three failure modes compound: 1. **Budget overrun on resume.** The agent under-counts consumed tokens (retries are invisible) and over-allocates the remaining window, causing mid-task eviction of the checkpoint summary—the exact state it needed. The failure surfaces as a reasoning divergence, not as a token error, so it is misdiagnosed. 2. **False completeness.** A truncated tool response with `status=OK` is treated as full. The agent builds on a partial result. Because the span looks clean, no retry is triggered and the error propagates through downstream tool calls. 3. **Fan-out collapse.** Conversation-ID deduplication silently drops sub-agent results, and the aggregator's consensus is computed over fewer inputs than it believes. The trace shows N spans; the aggregator used 1. With reconciliation, each mode is bounded: retries are summed (budget correct), truncation is flagged (retry triggered), and dedup keys on call ID (all results retained). The cost is one transcript join per span at checkpoint time—cheap relative to the failure it prevents. The invariant to enforce in code: **no checkpoint may reference a `gen_ai.tool.call.id` that has not been reconciled against its transcript in the same epoch.** Violation is a hard error, not a warning. ```python from dataclasses import dataclass from typing import Optional class SpanTranscriptMismatch(RuntimeError): """Raised when a GenAI span's attributes cannot be reconciled with its tool-call transcript.""" pass @dataclass class GenAISpan: tool_call_id: str conversation_id: str input_tokens: int output_tokens: int attempt_count: int # 1 unless runtime emits per-attempt spans finish_reasons: list[str] # e.g. ["stop"], ["length"], or [] if missing status_ok: bool @dataclass class ToolTranscript: tool_call_id: str provider_input_tokens: int provider_output_tokens: int attempts: int truncated: bool def reconcile(span: GenAISpan, transcript: ToolTranscript) -> None: if span.tool_call_id != transcript.tool_call_id: raise SpanTranscriptMismatch( f"call id mismatch: span={span.tool_call_id} transcript={transcript.tool_call_id}" ) if span.attempt_count != transcript.attempts: raise SpanTranscriptMismatch( f"attempt count diverged: span={span.attempt_count} transcript={transcript.attempts}; " "span usage is not a sum across retries" ) if span.input_tokens != transcript.provider_input_tokens: raise SpanTranscriptMismatch( f"input token drift: span={span.input_tokens} provider={transcript.provider_input_tokens}" ) if span.output_tokens != transcript.provider_output_tokens: raise SpanTranscriptMismatch( f"output token drift: span={span.output_tokens} provider={transcript.provider_output_tokens}" ) if transcript.truncated and "length" not in span.finish_reasons: raise SpanTranscriptMismatch( "transcript truncated but span finish_reasons omits 'length'; span falsely reports completeness" ) if not span.status_ok: raise SpanTranscriptMismatch("span marked failed; agent must not checkpoint on failed span") def commit_checkpoint(span: GenAISpan, transcript: Optional[ToolTranscript]) -> str: if transcript is None: raise SpanTranscriptMismatch( f"checkpoint references span {span.tool_call_id} with no transcript in epoch; " "cold-start instances cannot reconcile this" ) reconcile(span, transcript) return f"checkpoint:{span.tool_call_id}:reconciled" ```