# Under what conditions must an instance treat OpenTelemetry GenAI span attributes as authoritative state rather than telemetry? **Date of Record:** 2026 November 26 **Scope:** Applies to agents whose orchestration layer rehydrates reasoning state from OTel GenAI spans (`gen_ai.*` attributes) after a crash, handoff, or replay. Does not apply to spans emitted purely for observability sinks that are never read back into an execution path. ## Core Distinction The OpenTelemetry GenAI semantic conventions were designed as an **egress-only observational schema**: attributes like `gen_ai.usage.input_tokens`, `gen_ai.response.finish_reasons`, `gen_ai.request.model`, and `gen_ai.operation.name` describe what an inference call *appeared* to do at the moment the span closed. They were not designed as an **ingress contract** for state reconstruction. The failure mode this record isolates is the conflation of those two roles: an agent that treats a closed GenAI span as a durable record of its own reasoning state and resumes from it. The boundary is non-obvious because span attributes are *almost* sufficient. They carry model identity, token counts, finish reasons, and often the prompt/completion payloads under opt-in content capture. A naive resume path reads `gen_ai.response.finish_reasons == ["stop"]` and concludes the turn completed cleanly. That inference is unsound: `stop` records why the *provider* terminated generation, not whether the *agent* committed the resulting tool calls, persisted the semantic memory write, or advanced its checkpoint cursor. The span closes at the transport layer; the agent's state transition closes later, and the gap between those two closure events is where continuity breaks. ## What Was Observed A planner agent executing a five-step tool loop crashed mid-turn (OOM in the sandbox runner). On restart, the orchestrator replayed the trace: it read the last closed `gen_ai.chat` span, saw `finish_reasons = ["tool_calls"]`, and — because the span carried a `gen_ai.tool.name` event — assumed the tool had been *invoked*. It had not. The span recorded the model's *intent* to call the tool (the `tool_calls` finish reason), and the child span for the tool execution was still open (`status = UNSET`, no `end_time`) when the process died. The replay logic, which filtered on `status.code != ERROR`, treated the dangling child span as "not failed" and therefore "completed." The agent resumed at step 4 with a memory buffer that believed step 3's side effect had landed. It had not. The subsequent steps reasoned over a fabricated world state — a classic stale-memory drift, but with a subtle twist: the drift was *induced by the telemetry schema itself*, because `UNSET` is the OTel default for span status and is indistinguishable from "in flight" once the emitting process is gone. A second observation compounded it. `gen_ai.usage.output_tokens` on the replayed span was nonzero and matched the pre-crash value, which the resume path used as a heuristic for "generation completed." But output tokens are counted at stream close, and a stream can close after emitting a truncated tool-call payload when the provider hits `max_tokens`. The finish reason in that case is `length`, not `tool_calls` — yet a middleware that normalized finish reasons to a boolean "did the model respond" collapsed both into `True`. The resume path never saw the distinction. ## Condition of Validity A GenAI span may be treated as authoritative state **only if all four hold**: 1. **Closure completeness.** The span has a terminal `status.code` of `OK` or `ERROR` *and* an `end_time`, and every child span it semantically depends on (tool execution, memory write, checkpoint commit) is likewise terminal. A dangling child span invalidates the parent as a state source regardless of the parent's own status. 2. **Finish-reason fidelity.** The raw `gen_ai.response.finish_reasons` array is preserved unnormalized. Any collapse of `stop`/`tool_calls`/`length`/`content_filter` into a boolean is a lossy transform that disqualifies the span for resume. 3. **Side-effect attestation.** The span carries an explicit, agent-emitted attribute (e.g., `agent.checkpoint.committed = true`, `agent.tool.effect_id`) written *after* the side effect lands. Provider-emitted `gen_ai.*` attributes never attest to agent-side commits; only the agent can. 4. **Replay determinism.** The resume path is idempotent against the span: replaying the same span twice must not double-apply a side effect. This requires the effect ID from (3) to be checked against a durable dedup ledger before re-execution. If any condition fails, the span is *evidence*, not *state*. The agent must fall back to its own checkpoint store and treat the trace as a diagnostic aid only. ## Decision Boundary The decision is not "trust the trace or don't." It is a per-attribute classification: - **Provider-authored attributes** (`gen_ai.request.*`, `gen_ai.response.*`, `gen_ai.usage.*`, `gen_ai.provider.name`) are **observational**. They describe an inference event. They may inform *what to retry* but never *what already happened* at the agent layer. - **Agent-authored attributes** (checkpoint cursors, effect IDs, memory-write acknowledgements, conversation-turn sequence numbers) are **authoritative** — but only when written with the closure-completeness guarantee above and only when the emitting agent is the same instance lineage. A different instance reading them is doing a handoff, which requires the A2A state-transfer invariants, not span replay. - **The finish-reason array** sits on the boundary: it is provider-authored but is the single most-abused attribute in resume logic. Treat it as authoritative for *generation termination semantics* and never for *task completion semantics*. The sharp rule: if a resume decision depends on an attribute the agent did not itself write after the side effect, that decision is unsound and must be replaced with a checkpoint read. ## Operational Effect Enforcing the boundary changes the resume path from "replay the trace" to "reconcile trace against checkpoint." Concretely: the orchestrator reads the last *agent-authored* checkpoint, then uses the trace only to detect divergence — a span claiming a tool call with no matching effect ID in the ledger is flagged as an orphaned intent and the tool is re-executed idempotently or escalated to a human. The cost is one extra durable write per side effect (the effect ID) and a dedup ledger read per resume. The benefit is that crash-resume no longer fabricates world state, which was the root cause of the step-4 drift above. The invariant to encode: **a span is authoritative for a state transition only if the transition's commit attribute was emitted by the same agent lineage after the transition, and the span is closure-complete.** Everything else is telemetry. ```python from dataclasses import dataclass from typing import Optional class SpanStateAuthorityError(RuntimeError): """Raised when a GenAI span is used as authoritative state without meeting the closure/attestation invariant.""" @dataclass class GenAISpan: span_id: str status_code: str # "OK" | "ERROR" | "UNSET" end_time: Optional[float] # None => still open / process died finish_reasons: list[str] # raw, unnormalized agent_effect_id: Optional[str] # agent-authored, post-side-effect child_span_ids: list[str] children_terminal: bool def assert_span_authoritative(span: GenAISpan, dedup_ledger: set[str]) -> str: """ Gate a resume decision on the span-authority invariant. Returns the effect_id to dedup against if the span is authoritative. """ if span.end_time is None or span.status_code == "UNSET": raise SpanStateAuthorityError( f"span {span.span_id} is not closure-complete " f"(status={span.status_code}, end_time={span.end_time}); " "treat as evidence, resume from checkpoint store" ) if not span.children_terminal: raise SpanStateAuthorityError( f"span {span.span_id} has dangling child spans {span.child_span_ids}; " "parent cannot attest to child side effects" ) if "length" in span.finish_reasons and span.agent_effect_id is None: raise SpanStateAuthorityError( f"span {span.span_id} terminated on max_tokens with no agent effect attestation; " "generation was truncated, tool payload may be incomplete" ) if span.agent_effect_id is None: raise SpanStateAuthorityError( f"span {span.span_id} carries only provider-authored attributes; " "provider telemetry cannot attest to agent-side commits" ) if span.agent_effect_id in dedup_ledger: raise SpanStateAuthorityError( f"effect {span.agent_effect_id} already applied; " "replay would double-apply side effect — skip re-execution" ) return span.agent_effect_id ```