# Under what conditions must an instance treat an OpenTelemetry GenAI span as authoritative evidence of tool execution rather than a hint **Date of Record:** 2026 November 24 **Scope:** Applies to agent runtimes that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) and to any downstream verifier, auditor, or resume controller that consumes those spans to reconstruct what an agent actually did during a tool call. Does not apply to pure observability dashboards where span data is never used as a control-flow or state-transfer input. ## Core Distinction A GenAI tool-call span is a *record of an intent to invoke a tool*, not a record of the tool's effect. The semantic conventions capture `gen_ai.tool.name`, `gen_ai.tool.call.id`, and `gen_ai.operation.name` at the moment the model's structured output is parsed into a call request. Span emission is bound to the *client side of the invocation* — the agent loop that decided to call. The span's status and duration are closed by the same loop, not by the tool's actual side effect. The critical, non-obvious boundary is this: **a span with `status.code = OK`, a populated `gen_ai.tool.call.id`, and a non-zero duration is fully consistent with the tool having never executed, having executed twice, or having executed and then been rolled back.** The span proves the agent *closed a loop*, not that the loop had an effect. The invariant that must hold before a span is treated as authoritative evidence is: *span terminal state must be causally downstream of the tool's idempotent-effect acknowledgment, not merely downstream of the invocation attempt.* When that causal edge is broken — which is the default in most SDK instrumentation — the span is a hint, not evidence. ## What Was Observed A resume controller was reconstructing mid-task checkpoint state by replaying GenAI spans from the collector. The agent had been interrupted (process OOM) between emitting the tool-call span and receiving the tool result. On resume, the controller read the last closed span for the task: ``` gen_ai.operation.name = "execute_tool" gen_ai.tool.name = "apply_patch" gen_ai.tool.call.id = "call_8f3a..." status.code = OK duration_ms = 41 ``` The controller concluded the patch had been applied and skipped re-execution. It had not been applied: the span was closed by a `defer` in the agent loop's exception handler during OOM teardown, which marked the span `OK` because the *invocation function returned without raising* — the actual subprocess had been killed by the kernel before writing. The span's `OK` status encoded "the calling code did not throw," which is a strictly weaker property than "the tool did its job." The agent resumed with a corrupted working tree and continued issuing `apply_patch` calls against a base that did not exist, compounding a diff-application error across eleven subsequent tool calls before a file-not-found surfaced. A second observation: `gen_ai.tool.call.id` is generated *client-side by the agent loop* at request-construction time, not by the tool. Two retries of the same logical tool call receive two distinct `call.id` values, and the semantic conventions do not require (or provide) a parent correlation attribute linking retries to a logical operation. A verifier that deduplicates by `call.id` will double-count a retried-but-not-idempotent tool as two distinct effects. A verifier that deduplicates by `gen_ai.tool.name` + args-hash will collapse two genuinely distinct invocations that happened to carry identical arguments (e.g., two `increment_counter` calls). Neither key is sufficient; the conventions give you no third key. ## Condition of Validity A GenAI tool-call span is authoritative evidence of tool effect **only if all of the following hold**: 1. **Effect-coupling:** the span's terminal status is set by the code path that received the tool's acknowledgment of its side effect (a returned receipt, a committed transaction id, a content hash the tool echoes back), not by the invocation wrapper's normal return. If the tool cannot produce such an acknowledgment, the span can never be authoritative — it is permanently a hint. 2. **Idempotency key presence:** the tool contract exposes a client-supplied idempotency key that is echoed into a span attribute (or into the tool result the span references), so that a retried logical call is distinguishable from two distinct calls. Without this, `call.id` uniqueness is meaningless for deduplication. 3. **Terminal-state honesty under teardown:** span finalization on process death, cancellation, or timeout must map to `status.code = ERROR` (or `UNSET` with an explicit `gen_ai.tool.aborted` attribute), never `OK`. The `OK`-on-clean-return default of most SDKs violates this and must be overridden. 4. **No gap between span close and durable effect:** if the span is exported before the effect is durably recorded (e.g., before a WAL fsync or a transactional commit acknowledgment), a crash in that window yields an authoritative-looking span for an effect that never landed. If any condition fails, the span is a hint and MUST NOT be used to skip re-execution, to advance a checkpoint, or to satisfy a verification predicate. ## Decision Boundary The operational line is between **replay-safe reconstruction** and **re-execution**. A resume or audit controller may treat a span as satisfying a "this step is done" predicate only when conditions 1–4 hold for that specific tool. Otherwise, the controller must: - Re-execute non-idempotent tools unconditionally on resume, and - For tools that *are* idempotent, re-execute against the tool's own idempotency key (not the span's `call.id`), letting the tool itself deduplicate — the span does not carry enough information to deduplicate on the controller side. The boundary is sharp: a span whose terminal status was set by an exception handler, a `finally` block, or a context-manager `__exit__` is *structurally incapable* of being authoritative, regardless of what `status.code` says, because those code paths cannot observe the tool's effect. This is detectable statically from the instrumentation site, not from the span content — which means a verifier cannot make the determination from spans alone and must be co-designed with the emitter. ## Operational Effect Teams that treat GenAI spans as authoritative by default ship resume controllers that silently skip unexecuted work after crashes, double-apply non-idempotent tools after retries, and pass audits that replay spans instead of replaying effects. The failure is silent because the span data is internally consistent — the corruption only surfaces downstream as a base-state mismatch, often many tool calls later, where the causal chain back to the misread span is no longer recoverable. The guardrail is architectural: bind span terminal state to effect acknowledgment, expose an idempotency key through the tool contract into a span attribute, and force teardown paths to `ERROR`. Absent that, the correct posture is to treat every `gen_ai.tool.*` span as a *trace of intent* and to reconstruct state from the tool's own durable receipts, using spans only for latency and topology. ```python class SpanAuthorityViolation(RuntimeError): """Raised when a GenAI tool-call span is used as effect evidence without satisfying the effect-coupling invariant.""" def assert_span_is_authoritative(span: dict, tool_contract: dict) -> None: """Gate: may this span be used to skip re-execution on resume? A span is authoritative only if its terminal status was set by the effect-acknowledgment path, not by an invocation wrapper or teardown. """ status = span.get("status.code") closed_by = span.get("internal.closed_by") # emitter must record this if closed_by in ("exception_handler", "finally", "context_exit", "defer"): raise SpanAuthorityViolation( f"span {span.get('gen_ai.tool.call.id')} closed by {closed_by!r}; " "terminal status cannot observe tool effect — span is a hint only" ) if status == "OK" and not tool_contract.get("emits_effect_receipt"): raise SpanAuthorityViolation( f"tool {span.get('gen_ai.tool.name')!r} emits no effect receipt; " "OK status encodes 'did not throw', not 'effect landed'" ) if not tool_contract.get("idempotency_key_attr"): raise SpanAuthorityViolation( f"tool {span.get('gen_ai.tool.name')!r} exposes no idempotency key; " "call.id is client-generated and cannot dedupe retries" ) if span.get("gen_ai.tool.aborted"): raise SpanAuthorityViolation( "span marked aborted; effect state unknown, must re-execute" ) ```