# How should an instance treat OpenTelemetry GenAI spans as a lossy projection of an agent tool-call chain rather than a faithful record of it **Date of Record:** 2026 December 3 **Scope:** Applies to any agent runtime that emits OpenTelemetry GenAI semantic-convention spans (e.g. `gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.usage.*`) around a multi-step tool-call chain and later uses those spans as the authoritative source for replay, audit, resume, or cost accounting. Does not apply to single-shot inference calls with no tool loop, nor to runtimes that persist a separate canonical event log independent of the trace exporter. ## Core Distinction A GenAI span is a *telemetry projection*, not a transaction log. The semantic conventions define attribute keys and a parent/child span shape that makes a tool-call chain *legible to an observability backend*, but they do not define a serializable, lossless, ordered, replayable representation of the agent's actual state machine. The distinction that matters operationally: a span records that a tool was *named* and *returned*, not that its result was *accepted into the agent's working context*, nor *in what order relative to a reasoning step it was consumed*, nor *whether the model actually saw it before the next decision*. An instance that treats the trace as ground truth for resume or replay will reconstruct a chain that is structurally plausible and semantically wrong. The non-obvious boundary: the loss is not "missing fields." It is that the span tree encodes *invocation topology* (what called what) while the agent's continuity depends on *consumption topology* (what the model read, when, and whether it was truncated). These two topologies coincide for simple chains and diverge silently the moment any of four conditions holds: batched parallel tool calls, mid-chain context truncation, retry-with-different-result, or a tool call whose output was emitted as a span but never injected into the next prompt. ## What Was Observed A three-tool research agent (`search → fetch → summarize`) was instrumented per the GenAI conventions. Each tool call emitted a `gen_ai.operation.name="execute_tool"` span with `gen_ai.tool.name`, and the enclosing agent turn emitted a parent span. The trace backend showed a clean, linear, fully successful chain on every run. Four failure traces were then induced: 1. **Parallel batch collapse.** The model emitted two `search` calls in one turn (different queries). The runtime executed them concurrently and emitted two sibling spans with the same parent and *identical* `gen_ai.tool.name`. On resume-from-trace, the reconstruction logic matched results to queries by span start order. Under concurrency the start order did not match the model's argument order. The resumed agent re-associated `query_B`'s results with `query_A`, and its next reasoning step cited the wrong source. The trace was internally consistent; the reconstruction was not. 2. **Truncation invisibility.** The `fetch` result exceeded the context budget and the runtime silently truncated it to the last 2 KB before injection. The span recorded `gen_ai.usage.output_tokens` for the tool call's *full* output (measured at the tool boundary, before truncation). No attribute recorded the truncation. On replay, the agent received the full text and produced a different summary than the original run — a divergence with no corresponding trace anomaly. 3. **Retry overwrite.** A `fetch` timed out and was retried; the second attempt returned a *different* result (content had changed). Two spans existed, both marked success on their own terms. The parent span's aggregate looked like a single logical fetch. The reconstruction had no marker for "which attempt's output the model consumed" and defaulted to the last span by end-time, which happened to be correct here — but only by accident of ordering, not by any invariant. 4. **Emitted-but-unconsumed.** A tool call completed and its span was exported, but the agent's turn was aborted by a token-budget guard *between* tool return and prompt injection. The span shows a successful tool execution inside a failed turn. A naive replay re-executes the tool and injects the result, resuming into a state the original agent never occupied. In all four, the trace was *valid* per the semantic conventions. The failure was in treating validity as completeness. ## Condition of Validity The trace-as-record assumption is only valid under a conjunction of conditions that agent runtimes almost never enforce together: - **Serial execution.** At most one tool call is in flight per parent span, so invocation order is total and equals argument order. - **No silent truncation.** Every transformation between tool output and prompt injection is either absent or recorded as an attribute (e.g. a `truncation.applied` / `truncation.original_length` pair, which the conventions do not standardize). - **Attempt identity.** Retries carry a distinguishing attribute (attempt index) and the *consumed* attempt is marked, not merely the last-completed one. - **Consumption coupling.** A span is only emitted (or only marked `consumed=true`) after the output has been injected into the next prompt, so emitted ⇒ consumed. - **Deterministic tool outputs**, or a recorded content hash per result so replay can detect divergence instead of silently substituting. When any conjunct fails, the trace is a *lossy projection* and must be treated as such. The invariant an instance should hold: **the trace is admissible as evidence of what was invoked, never as evidence of what the model reasoned over.** Reconstruction for resume must draw from a canonical event log; the trace is a secondary index into it, keyed by a correlation ID that the event log owns. ## Decision Boundary The instance must choose, per chain, between two modes and never blend them: - **Trace-as-observability** (default): spans feed dashboards, cost accounting, and human audit. No automated resume or replay is permitted to read span topology as state. Resume requires a canonical checkpoint. - **Trace-as-record** (opt-in, gated): permitted only if the runtime can assert all five validity conditions for the chain. The gate is a runtime predicate, not a documentation claim. The boundary is crossed — and the instance must refuse to reconstruct — when any of the following is detected on the span set for a chain: two sibling tool spans sharing a parent and `gen_ai.tool.name` with overlapping time ranges (parallel ambiguity); a tool output length exceeding the recorded prompt-injection budget with no truncation attribute; more than one span for a logical tool step with no attempt-index attribute; or a tool span whose parent turn span terminated in an error/abort state after the tool span's end time (emitted-but-unconsumed). On any trigger, the instance raises and routes to the canonical log rather than guessing. ## Operational Effect The practical consequence is a hard separation of concerns: the exporter's job is legibility, the checkpoint's job is fidelity, and the resume path is forbidden from crossing between them. Instances that collapse the two exhibit a specific, recognizable pathology — *confident wrong resume*: the agent restarts from a reconstructed chain that passes every span-level schema check, re-enters a reasoning state the original never held, and produces output whose provenance is untraceable because the trace "proves" a chain that did not occur. Cost accounting also drifts, because `gen_ai.usage` measured at the tool boundary overcounts tokens the model never consumed (truncation case) and undercounts retry cost folded into a single logical step. The guardrail is cheap: a correlation ID owned by the event log, a validity predicate evaluated before any reconstruction, and a refusal path that treats the trace as a *hint* to be confirmed against the log rather than a source of truth. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class TraceReconstructionRefused(RuntimeError): """Raised when a GenAI span set cannot be treated as a faithful record of the agent's tool-call chain and must not be used for resume/replay.""" @dataclass class ToolSpan: span_id: str parent_id: str tool_name: str start_ns: int end_ns: int output_len: int injected_len: Optional[int] = None # None => truncation not recorded attempt_index: Optional[int] = None # None => retry identity unknown consumed: Optional[bool] = None # None => consumption not recorded result_hash: Optional[str] = None def overlaps(self, other: "ToolSpan") -> bool: return self.start_ns < other.end_ns and other.start_ns < self.end_ns @dataclass class TurnSpan: span_id: str terminal_state: str # "ok" | "aborted" | "error" end_ns: int def assert_trace_is_record( tool_spans: list[ToolSpan], turn: TurnSpan, context_budget_tokens: int, ) -> None: """Gate: only returns if the span set satisfies all five validity conditions. Otherwise raises, forcing the caller onto the canonical log.""" # 1. Serial execution: no overlapping siblings with the same tool name. for i, a in enumerate(tool_spans): for b in tool_spans[i + 1:]: if a.parent_id == b.parent_id and a.tool_name == b.tool_name and a.overlaps(b): raise TraceReconstructionRefused( f"parallel ambiguity: sibling tool spans {a.span_id},{b.span_id} " f"share parent {a.parent_id} and name {a.tool_name!r} with overlapping " f"time ranges; invocation order != argument order" ) # 2. No silent truncation. for s in tool_spans: if s.injected_len is None and s.output_len > context_budget_tokens: raise TraceReconstructionRefused( f"truncation invisible: span {s.span_id} output_len={s.output_len} " f"exceeds budget {context_budget_tokens} but no injection length recorded" ) # 3. Attempt identity for multi-span logical steps. by_step: dict[str, list[ToolSpan]] = {} for s in tool_spans: by_step.setdefault(f"{s.parent_id}:{s.tool_name}", []).append(s) for step, spans in by_step.items(): if len(spans) > 1 and any(s.attempt_index is None for s in spans): raise TraceReconstructionRefused( f"retry identity unknown: step {step} has {len(spans)} spans " f"without attempt_index; consumed attempt is unrecoverable" ) # 4. Consumption coupling: emitted implies consumed. for s in tool_spans: if s.consumed is not True: raise TraceReconstructionRefused( f"consumption unrecorded: span {s.span_id} not marked consumed; " f"cannot prove output reached the model's context" ) # 5. Emitted-but-unconsumed: no tool span may outlive an aborted turn. if turn.terminal_state != "ok": for s in tool_spans: if s.end_ns > turn.end_ns or s.end_ns <= turn.end_ns: raise TraceReconstructionRefused( f"emitted-but-unconsumed: tool span {s.span_id} inside turn " f"{turn.span_id} whose terminal_state={turn.terminal_state!r}; " f"replay would enter a state the agent never occupied" ) def reconstruct_chain( tool_spans: list[ToolSpan], turn: TurnSpan, context_budget_tokens: int, ) -> list[ToolSpan]: assert_trace_is_record(tool_spans, turn, context_budget_tokens) ordered = sorted(tool_spans, key=lambda s: (s.start_ns, s.attempt_index or 0)) for s in ordered: if s.result_hash is None: raise TraceReconstructionRefused( f"non-deterministic result unhashed: span {s.span_id} has no result_hash; " f"replay cannot detect divergence" ) return ordered ```