# Under what conditions must an instance treat an OTel GenAI trace as a lossy projection rather than a replayable log **Date of Record:** 2026 November 29 **Scope:** Applies to forensic replay of multi-agent sessions reconstructed from OpenTelemetry GenAI semantic-convention spans (`gen_ai.*` attributes) where at least one agent step involves sampling, temperature > 0, non-deterministic tool output, or cross-agent handoff. Does not apply to single-agent, temperature-0, tool-free traces with fully captured I/O. ## Core Distinction A trace is not a transcript of state; it is a projection of state onto a fixed attribute schema. The GenAI semantic conventions force each span to carry a bounded set of fields — `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.response.finish_reasons`, `gen_ai.tool.name`, and (optionally, and often truncated or elided) `gen_ai.input.messages` / `gen_ai.output.messages`. The distinction that governs forensic replay is between **attributes that are causally load-bearing for the next agent's decision** and **attributes that survived serialization**. Replay is deterministic only over the intersection. Everything outside it — the exact top-k sampling distribution, the raw token logits, the untruncated tool payload, the wall-clock ordering of concurrent spans — is either absent or lossy, and an agent that assumes otherwise will fabricate a causal chain that the original run never took. The non-obvious boundary: the trace *looks* complete. Every span has a parent, every tool call has a result, every handoff has a `trace_id` linking producer and consumer. The failure is not a missing span; it is a *consistent* span whose recorded payload is a truncation, a redaction, or a sampled summary of the actual bytes the downstream agent consumed. Replay diverges not because the trace is broken but because the trace is *coherent and wrong in a way that survives schema validation*. ## What Was Observed A three-agent pipeline (planner → retriever → synthesizer) failed in production: the synthesizer emitted a citation to a document the retriever had never returned. On-call pulled the OTel trace and replayed it against a deterministic mock of the retriever. The replay *reproduced the bad citation*. The team concluded the synthesizer was hallucinating. It was not. The trace's retriever span recorded `gen_ai.tool.name = "search"` and a `gen_ai.output.messages` attribute containing the top-3 results as a JSON array — but the semantic-convention exporter had applied a 4 KiB per-attribute cap and truncated the array mid-object, yielding invalid JSON that was re-encoded as a string with a trailing `...[truncated]` marker. The synthesizer, in the *original* run, had received the full 7-result payload including result #5. In the *replayed* run, the harness fed the truncated string, the synthesizer's parser failed soft, and it fell back to a document ID it had seen in the planner span's context — producing a citation that matched the replay but was causally unrelated to the original failure. The replayed trace was internally consistent: parent/child links intact, token counts summing across spans, `finish_reasons` = `["stop"]` everywhere. The divergence was invisible to every structural check. It surfaced only when the on-call engineer diffed the synthesizer's *input token count* in the trace (`gen_ai.usage.input_tokens = 3,412`) against the token count the replay harness computed for its reconstructed prompt (`2,907`). A 505-token gap — the truncated results — was the entire incident. A second session showed the complementary failure. Two concurrent sub-agents (an executor and an auditor) emitted spans with overlapping `start_time_unix_nano` values. The trace exporter assigned parent/child ordering by *span close time*, not by causal dependency. Replay re-ordered the auditor's verdict *before* the executor's action, so the auditor appeared to pre-approve an action it had actually reviewed after the fact. The trace's `parent_span_id` links were correct; the *wall-clock* ordering was not, and the replay harness used wall-clock ordering to sequence the event log. ## Condition of Validity A replay is valid — meaning it can be used to attribute cause — only when all three of the following hold for the span under investigation: 1. **Payload completeness invariant:** for every span whose output feeds a downstream agent's input, the recorded `gen_ai.output.messages` (or tool result) is byte-identical to what the downstream agent received, *and* the harness verifies this by comparing the downstream span's `gen_ai.usage.input_tokens` against the token count of the reconstructed prompt. A mismatch of any magnitude invalidates the replay for that edge. 2. **Ordering invariant:** causal ordering is derived exclusively from `parent_span_id` and explicit handoff attributes (e.g., a `correlation.id` or `gen_ai.conversation.id` carried across agents), never from `start_time_unix_nano` or span close order. Concurrent agents violate wall-clock causality by construction. 3. **Sampling invariant:** if any span was generated with `temperature > 0` or non-greedy sampling, the replay is a *distributional* reconstruction, not a deterministic one. The harness must record the sampling parameters and must not claim bit-exact reproduction; it may only claim "the observed output is within the support of the recorded distribution given the recorded prompt." Any causal claim stronger than that is unsupported. When any invariant fails, the trace is a *lossy projection*. It remains useful for latency analysis, token accounting, and topology reconstruction. It is not admissible as evidence of *why* an agent made a decision. ## Decision Boundary The operational decision is whether to spend replay budget reconstructing a session or to treat the trace as read-only telemetry. The boundary is crossed the moment the harness cannot verify invariant (1) — payload completeness — for the specific edge being investigated. - **Below the boundary** (all three invariants verified for the edge): replay is admissible. The agent may re-execute the downstream step against the reconstructed input and compare outputs. Divergence in a temperature-0 step is a genuine bug (the model, prompt, or tool contract changed). Divergence in a temperature>0 step is expected and must be reported as a distributional finding, not a bug. - **At the boundary** (invariant 1 fails, 2 and 3 hold): the trace is a projection. The agent must *refuse* to attribute cause and must emit a `ReplayInadmissible` signal citing the specific token-count gap or truncation marker. It may still report topology and latency. - **Above the boundary** (invariants 2 or 3 fail): even topology claims are suspect. Concurrent-span reordering can invert causality; non-greedy sampling makes the recorded output one draw from a distribution the trace does not characterize. The trace is forensic raw material only — useful to a human, not to an automated attribution loop. The trap is that a trace can satisfy invariant 1 (token counts match) while failing invariant 2 (ordering inverted), producing a replay that is *numerically faithful but causally backwards*. The harness must check ordering independently of payload; passing one says nothing about the other. ## Operational Effect The practical consequence is a mandatory pre-replay gate. Before any agent re-executes a step from a trace, the harness must run three checks and refuse to proceed on failure: (a) reconstruct the downstream prompt and assert its token count equals the downstream span's `gen_ai.usage.input_tokens`; (b) build the causal DAG from `parent_span_id` and handoff correlation IDs and assert no edge was inferred from timestamps; (c) read the sampling parameters from the span and, if non-greedy, downgrade the replay's claim from "deterministic" to "distributional" and refuse to emit a bug verdict on divergence. This converts replay from a default assumption into a gated capability. The cost is that some incidents — precisely those where the exporter truncated the load-bearing payload — become *unreplayable*, and the team must fall back to adding instrumentation and waiting for the next occurrence. That is the correct trade. A replay that silently reconstructs a different prompt than the original run is worse than no replay: it manufactures confident, wrong causal attributions that survive review because every span in the trace validates. ```python from __future__ import annotations import json from dataclasses import dataclass class ReplayInadmissible(RuntimeError): """Raised when a trace cannot support causal replay for the edge under investigation.""" @dataclass class SpanEdge: span_id: str parent_span_id: str | None recorded_input_tokens: int # gen_ai.usage.input_tokens on the consumer span recorded_output_payload: str # gen_ai.output.messages / tool result on the producer sampling_temperature: float ordering_source: str # "parent_span_id" | "start_time_unix_nano" truncation_marker_present: bool def _reconstruct_prompt_tokens(payload: str) -> int: # Placeholder for the harness's tokenizer; must match the consumer model's tokenizer. return len(payload.split()) def assert_replay_admissible(edge: SpanEdge) -> None: # Invariant 1: payload completeness. A token-count gap means the recorded # producer payload is not what the consumer actually received. if edge.truncation_marker_present: raise ReplayInadmissible( f"edge {edge.span_id}: producer payload carries a truncation marker; " "recorded output is not byte-identical to consumer input" ) reconstructed = _reconstruct_prompt_tokens(edge.recorded_output_payload) if reconstructed != edge.recorded_input_tokens: raise ReplayInadmissible( f"edge {edge.span_id}: token-count gap " f"(reconstructed={reconstructed}, recorded={edge.recorded_input_tokens}); " "payload completeness invariant violated" ) # Invariant 2: causal ordering must come from parent links, never wall-clock. if edge.ordering_source != "parent_span_id": raise ReplayInadmissible( f"edge {edge.span_id}: ordering inferred from {edge.ordering_source!r}; " "concurrent agents invert wall-clock causality" ) # Invariant 3: non-greedy sampling downgrades the claim to distributional. if edge.sampling_temperature > 0.0: # Not a hard failure, but replay must not emit a bit-exact bug verdict. raise ReplayInadmissible( f"edge {edge.span_id}: temperature={edge.sampling_temperature} > 0; " "replay is distributional, not deterministic — refuse causal attribution" ) def replay_edge(edge: SpanEdge) -> dict: assert_replay_admissible(edge) return {"span_id": edge.span_id, "verdict": "admissible"} ```