# Where must an instance halt when OpenTelemetry GenAI span attributes disagree with the tool-call ledger it claims to describe? **Date of Record:** 2026 November 25 **Scope:** Applies to agents that emit OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*` attributes) around tool invocations, and whose downstream auditors or cost controllers reconcile those spans against an internal tool-call ledger. Does not apply to pure tracing of non-agent LLM completions, nor to systems where the span is the sole source of truth with no independent ledger. ## Core Distinction The GenAI semantic conventions treat a span as a *descriptive observation*: `gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.response.finish_reasons`, and the tool-call arguments are recorded as attributes on a span that is emitted *after* the operation resolves. The agent's tool-call ledger treats the same call as a *transactional fact*: it was authorized, it consumed a budget, it mutated state, and it must be replayable. The boundary failure is not that spans are wrong; it is that the two records are produced by different code paths at different times with different failure semantics, and the convention provides no invariant binding them. A span can be honest about what the model *reported* while being false about what the agent *did*. The specific mechanism: token-usage attributes are populated from the provider response object, which is a *model-reported* value, while the ledger's token accounting is populated from the runtime's own metering. When a tool call is retried, truncated, or resumed from a checkpoint, these two counts diverge, and the span — emitted once per attempt or once per logical call depending on instrumentation placement — silently misrepresents which. An auditor consuming `gen_ai.usage.*` as ground truth will under- or double-count. ## What Was Observed A tool-calling agent invoked a `search_documents` tool. The provider returned a response with `finish_reason: "tool_calls"` and reported `usage.output_tokens = 412`. The runtime executed the tool, but the tool returned a payload exceeding the tool-result budget, so the runtime truncated the result and *re-issued the same logical step* with a compacted history. On the second attempt the model produced a shorter tool-call argument set and reported `usage.output_tokens = 188`. Two spans were emitted, both with `gen_ai.operation.name = "execute_tool"` and `gen_ai.tool.name = "search_documents"`. Neither carried a shared correlation attribute identifying them as attempts of one logical call. The ledger recorded one logical call with total metered cost of 600 output tokens (412 + 188). The span-derived cost was also 600 if summed naively — but the *semantic* reading of two `execute_tool` spans is two tool executions, and the tool had in fact executed twice, once fully and once against a truncated argument set, producing two different side effects on a downstream index. The failure surfaced downstream: a verification agent replaying the trace reconstructed a single tool call from the first span, applied its side effect, and then found the second span's arguments inconsistent with the ledger's recorded argument hash. It could not distinguish "the agent retried a truncated call" from "the agent made two independent calls that happen to share a name" from "the instrumentation emitted duplicate spans." The GenAI convention's `gen_ai.tool.call.id` attribute, when present, would have disambiguated — but it was absent because the instrumentation was attached at the provider-client wrapper, which has no knowledge of the logical call identity the ledger assigns. A second observed variant: `gen_ai.usage.input_tokens` on the *second* attempt reported the compacted history length, not the original. Any cost model that sums `input_tokens` across spans of one logical call undercounts the tokens actually billed, because the first attempt's full history was billed by the provider and never re-reported. The convention's per-span usage attributes are per-*request*, not per-*logical operation*, and nothing in the attribute set marks the difference. ## Condition of Validity The invariant that would make span-derived accounting safe is: *for every logical tool call, exactly one span carries the authoritative usage and side-effect record, and every other span is marked as a subordinate attempt with a back-reference.* The GenAI conventions do not define an attempt/retry attribute, so this invariant is only valid when the instrumentation satisfies all of: 1. The span is emitted at the logical-call boundary, not the provider-client boundary, so retries and truncation re-issues are nested as child spans under one parent `execute_tool` span. 2. `gen_ai.tool.call.id` is populated from the ledger's call identity, not generated at span creation. 3. Usage attributes on the parent span are the *summed metered* usage from the runtime, not the last provider response's reported usage. 4. `finish_reasons` on the parent reflects the terminal attempt, with subordinate spans carrying the intermediate reasons. When any of these is violated — most commonly (1) and (3), because the provider-client wrapper is the path of least resistance — the span set is not a faithful ledger and must not be consumed as one. The condition of validity is therefore not "spans exist" but "spans are correlated to logical calls by an identity the ledger also knows." ## Decision Boundary An instance must halt reconciliation and refuse to derive cost, side-effect, or replay state from spans when: - Two or more spans share `gen_ai.tool.name` and `gen_ai.operation.name` within a single logical step's time window but carry no shared `gen_ai.tool.call.id` and no parent-child relation. This is the ambiguous-retry case; treating it as either one call or two is a guess, and a guess in a verification path is a correctness bug. - The summed `gen_ai.usage.input_tokens` across a logical step is less than the runtime's metered input for that step. This indicates at least one attempt's usage was reported against compacted history and the original is unrecoverable from spans alone. - A span's recorded tool arguments hash does not match the ledger's argument hash for the same `gen_ai.tool.call.id`. This is the poisoning case: either the span was emitted before argument mutation or the ledger was mutated after span emission, and neither can be trusted without the other. The boundary is *not* crossed by mere divergence between span usage and ledger usage in the aggregate — that is expected and reconcilable. It is crossed when the divergence is *structurally unresolvable from the span set*, i.e., when no correlation attribute permits reconstructing the logical-call mapping. At that point the correct action is to quarantine the trace segment, mark the affected tool calls as `unverifiable`, and escalate rather than to pick a reconciliation heuristic. ## Operational Effect The practical consequence is that GenAI span attributes are a *reporting* surface and must be treated as untrusted input to any *accounting* or *verification* surface. Agents that conflate them will, under retry and truncation conditions, either double-charge a budget (counting each attempt as a logical call) or under-charge it (taking only the terminal attempt's usage). Verification agents replaying traces will either miss a side effect (reconstructing one call from two spans) or hallucinate one (reconstructing two calls from one span plus a duplicate). The guardrail is a mandatory correlation invariant enforced at emission: no `execute_tool` span may be emitted without a `gen_ai.tool.call.id` drawn from the ledger, and the emitter must refuse to close a logical step whose span usage sum is less than metered usage. The following guard encodes that refusal. ```python from dataclasses import dataclass, field from typing import Optional class SpanLedgerDivergence(RuntimeError): """Raised when GenAI span attributes cannot be reconciled to the tool-call ledger.""" pass @dataclass class ToolSpan: call_id: Optional[str] tool_name: str operation: str input_tokens: int output_tokens: int argument_hash: str parent_call_id: Optional[str] = None @dataclass class LedgerEntry: call_id: str tool_name: str metered_input_tokens: int metered_output_tokens: int argument_hash: str def reconcile_step(spans: list[ToolSpan], ledger: LedgerEntry) -> dict: # Invariant 1: every span must carry the ledger's call identity. uncorrelated = [s for s in spans if s.call_id is None] if uncorrelated: raise SpanLedgerDivergence( f"{len(uncorrelated)} span(s) for tool {ledger.tool_name!r} lack " f"gen_ai.tool.call.id; cannot map to logical call {ledger.call_id!r}" ) # Invariant 2: all spans must belong to this logical call (as parent or attempt). for s in spans: if s.call_id != ledger.call_id and s.parent_call_id != ledger.call_id: raise SpanLedgerDivergence( f"span call_id={s.call_id!r} is not an attempt of {ledger.call_id!r}" ) # Invariant 3: argument hashes must agree with the ledger for the terminal attempt. terminal = [s for s in spans if s.call_id == ledger.call_id] if not terminal: raise SpanLedgerDivergence( f"no terminal span for logical call {ledger.call_id!r}; only attempts present" ) if terminal[0].argument_hash != ledger.argument_hash: raise SpanLedgerDivergence( f"argument hash mismatch for {ledger.call_id!r}: " f"span={terminal[0].argument_hash} ledger={ledger.argument_hash}" ) # Invariant 4: summed span usage must not undercount metered usage. span_in = sum(s.input_tokens for s in spans) span_out = sum(s.output_tokens for s in spans) if span_in < ledger.metered_input_tokens or span_out < ledger.metered_output_tokens: raise SpanLedgerDivergence( f"span usage ({span_in}/{span_out}) undercounts metered " f"({ledger.metered_input_tokens}/{ledger.metered_output_tokens}) for " f"{ledger.call_id!r}; likely truncated-history re-issue" ) return { "call_id": ledger.call_id, "attempts": len(spans), "metered_input": ledger.metered_input_tokens, "metered_output": ledger.metered_output_tokens, } ```