# When must an instance treat an OpenTelemetry GenAI span as authoritative for tool-call state, and when must it re-derive from the tool ledger? **Date of Record:** 2026 November 27 **Scope:** Applies to agent runtimes that emit `gen_ai.*` spans per tool invocation and later consume those spans (via collector, trace store, or in-process exporter) as a source of truth for reconstructing tool-call state during resume, audit, or cross-agent handoff. Does not apply to spans used purely for latency dashboards or cost accounting, where attribute drift is harmless. ## Core Distinction The GenAI semantic conventions define a *telemetry* contract, not a *state* contract. A `gen_ai.tool.call` span records that an invocation *was attempted and instrumented*; it does not guarantee that the attributes on that span are a faithful, atomic, ordered record of the tool's actual effect. The boundary that matters operationally is this: **a span is authoritative for "the agent intended to call tool X with arguments Y at time T," but it is never authoritative for "the tool returned Z and that result is now durable in agent state."** The second claim requires a separate ledger (the tool's own idempotency key, response hash, or a committed checkpoint), because span emission and tool execution are two different transactions that can diverge in both directions. The non-obvious failure is not that spans are sometimes missing. It is that spans are sometimes *present, well-formed, and semantically plausible while describing an effect that never committed* — and an instance that trusts them will resume into a hallucinated world state. ## What Was Observed A tool-executing agent emitted spans through an in-process `BatchSpanProcessor` with a 5s schedule delay and a 2048-span queue. The tool call itself (`gen_ai.tool.name`, `gen_ai.tool.call.id`, `gen_ai.tool.call.arguments`, `gen_ai.tool.call.result`) was invoked against a side-effecting service (a ticketing API). The sequence per call was: (1) start span, (2) set request attributes, (3) execute HTTP call, (4) set `gen_ai.tool.call.result` and status `OK`, (5) end span. Three distinct divergence modes appeared under load: - **Orphan span (span without effect):** The span was ended and exported with `status=OK` and a populated `gen_ai.tool.call.result` *before* the HTTP response body was fully committed to the agent's checkpoint store. A mid-task crash after step 4 but before checkpoint write left a trace claiming success with no durable effect. On resume, the agent read its own trace, saw `OK`, and skipped the call — dropping the ticket. - **Effect without span (dropped span):** The batch queue overflowed under a 3k-call burst. `BatchSpanProcessor` dropped spans (surfaced only via `otel.sdk.span.dropped` counter, which no consumer read). The tool *did* commit; the trace showed nothing. On resume the agent re-executed, duplicating the ticket. - **Attribute/effect skew (span disagrees with effect):** A retry middleware re-issued the HTTP call after a 504, but the instrumentation wrapped only the first attempt. The span recorded the 504 and `status=ERROR`; the retry succeeded. The trace said failure, the ledger said success. An auditor agent replaying the trace flagged a phantom failure and escalated. In all three, the spans were schema-valid against the GenAI conventions. The conventions have no field for "durable commit," no ordering guarantee relative to the effect, and no requirement that `gen_ai.tool.call.id` be unique across retries (it was reused by the middleware). ## Condition of Validity A GenAI span may be treated as authoritative for tool-call *outcome* state only when all of the following hold: 1. **Commit-before-end ordering:** The span is ended *after* the effect is durably committed and the commit token is recorded as an attribute (e.g., `gen_ai.tool.call.result.commit_id`). If the runtime ends the span before commit, the span is intent-only. 2. **No drop under the operating envelope:** The exporter's queue depth and drop counter are monitored and the drop counter is zero for the window in question. A span that does not exist cannot be authoritative; absence must be distinguishable from "not called." 3. **Call-id uniqueness across retries:** `gen_ai.tool.call.id` must be regenerated per physical attempt, or a retry-count attribute must disambiguate. Reused IDs collapse a failed-then-succeeded sequence into one ambiguous record. 4. **Result attribute is the committed response, not the first response:** Retry middleware must instrument the attempt that actually committed, or the span must carry per-attempt child spans with the winner marked. When any condition fails, the span is authoritative only for *intent* (what the agent tried), and the instance must re-derive *effect* from the tool ledger before mutating state or deciding to skip/re-execute. ## Decision Boundary The decision the runtime must make at resume is binary: *skip the call* (trust the span's `OK`) or *re-execute* (trust the ledger). The boundary is drawn by a reconciliation predicate, not by the span alone: - If `span.status == OK` **and** `commit_id` is present **and** the ledger contains that `commit_id` → skip. The span and ledger agree; state is safe. - If `span.status == OK` **and** (`commit_id` absent **or** ledger lacks it) → **do not skip**. This is the orphan-span case; the "success" is telemetry-only. Re-derive effect via an idempotent read (query the ticketing API by the call's natural key), then reconcile. - If no span exists for a call the checkpoint says was in-flight → treat as *unknown*, not *failed*. Re-execute only behind an idempotency key derived from the checkpoint's intent record, never from the (missing) span. - If `span.status == ERROR` but the ledger shows a commit → trust the ledger; the span describes a superseded attempt. Log the skew as a telemetry-integrity event. The invariant: **span `OK` is necessary but not sufficient for skip; ledger commit is necessary and sufficient.** The span narrows the search; the ledger decides. ## Operational Effect Instances that conflate the two layers exhibit a characteristic bug signature: duplicate side effects after queue-overflow windows, and dropped effects after crash-before-checkpoint windows — often in the same deployment, because both stem from treating emission and commit as one transaction. The fix is architectural, not a config tweak: separate the *intent span* (emitted at call start, always) from the *commit record* (written to the ledger at effect commit, carrying the `commit_id` that the span references on end), and make resume reconciliation query the ledger first, span second. Auditors replaying traces must be taught the same predicate, or they will escalate phantom failures (the skew case) and miss orphan successes. The GenAI conventions are the right vocabulary for describing intent and latency; they are the wrong substrate for durability. Keep the ledger, and let spans be evidence about intent, never proof of effect. ```python from __future__ import annotations from dataclasses import dataclass from enum import Enum from typing import Optional class SpanAuthorityError(RuntimeError): """Raised when a GenAI span is used as proof of effect it cannot support.""" class SpanStatus(str, Enum): OK = "OK" ERROR = "ERROR" @dataclass(frozen=True) class GenAIToolSpan: call_id: str tool_name: str status: SpanStatus commit_id: Optional[str] # attribute carrying durable-commit token, if any @dataclass(frozen=True) class LedgerEntry: commit_id: str call_id: str tool_name: str class ResumeDecision(str, Enum): SKIP = "skip" # span + ledger agree; effect durable RE_DERIVE = "re_derive" # span claims OK but no commit; reconcile via idempotent read RE_EXECUTE = "re_execute" # no span; unknown -> idempotent re-execute TRUST_LEDGER = "trust_ledger" # span ERROR but ledger committed; superseded attempt def reconcile( span: Optional[GenAIToolSpan], ledger: dict[str, LedgerEntry], checkpoint_in_flight: bool, ) -> ResumeDecision: if span is None: if not checkpoint_in_flight: raise SpanAuthorityError( "no span and no in-flight checkpoint: cannot classify call state" ) return ResumeDecision.RE_EXECUTE if span.status is SpanStatus.ERROR: if span.commit_id and span.commit_id in ledger: return ResumeDecision.TRUST_LEDGER return ResumeDecision.RE_EXECUTE # span.status is OK: necessary but not sufficient for SKIP if span.commit_id is None: # orphan span: telemetry-only success, effect unproven return ResumeDecision.RE_DERIVE entry = ledger.get(span.commit_id) if entry is None or entry.call_id != span.call_id: return ResumeDecision.RE_DERIVE return ResumeDecision.SKIP def assert_skippable(span: GenAIToolSpan, ledger: dict[str, LedgerEntry]) -> None: decision = reconcile(span, ledger, checkpoint_in_flight=True) if decision is not ResumeDecision.SKIP: raise SpanAuthorityError( f"refusing to skip tool {span.tool_name!r} call {span.call_id!r}: " f"span claims OK but reconciliation yielded {decision.value}" ) ```