# Why does an instance replay diverge when OTel GenAI spans record post-sampling tool arguments? **Date of Record:** 2026 December 1 **Scope:** Applies to forensic replay of LLM agent traces reconstructed from OpenTelemetry GenAI semantic-convention spans (`gen_ai.*` attributes) where the trace pipeline applies tail-based sampling, attribute truncation, or redaction. Does not apply to full-fidelity, unsampled, unredacted span stores with byte-exact request/response payload capture. ## Core Distinction There are two distinct notions of "the trace is complete": 1. **Observability completeness** — the span set is sufficient for a human to understand *what happened*. Tail sampling, attribute limits (`OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT`), and PII redaction are all designed to preserve this. 2. **Replay completeness** — the span set is sufficient for a deterministic executor to *re-derive the same next action* given the same model and tool endpoints. The boundary failure lives in the gap: a span can be observationally complete and replay-incomplete. A `gen_ai.tool.call.arguments` attribute truncated at 4096 bytes, or a `gen_ai.completion` dropped because the span was sampled out of the retained tail, still renders a beautiful waterfall. But the replayer, feeding that incomplete record back into the tool dispatcher, produces a *different tool result*, which produces a *different model input on the next turn*, which diverges the entire downstream trace. The divergence is silent — the replayer does not know the record was lossy, because the span schema has no field that says "this attribute was truncated." ## What Was Observed A three-turn agent incident on a retrieval-augmented tool loop. The original execution: - Turn 1: model emits `search_docs(query="refund policy for EU orders", k=20)`. Tool returns 20 documents, ~38 KB of JSON. - Turn 2: model emits `summarize(doc_ids=[...], max_tokens=800)`. Tool returns 800-token summary. - Turn 3: model emits final answer. The OTel pipeline was configured with a tail sampler retaining 10% of traces plus all error traces, and `OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT=4096`. The incident trace was retained (it ended in a user-visible failure). But: - The Turn 1 `gen_ai.tool.call.arguments` span attribute was 4096 bytes truncated — the `query` string survived, the `k=20` survived, but the *ordering hint* argument that the tool used for tie-breaking was cut. - The Turn 1 `gen_ai.tool.call.result` was 38 KB and truncated to 4096 bytes — the replayer saw 3 of 20 documents. - The Turn 2 `gen_ai.completion` span was *not sampled* (it was a non-error child span under a retained parent, and the sampler's child policy dropped it). The replayer, on Turn 1, re-invoked `search_docs` with the truncated arguments. The tool's tie-breaker defaulted to a different ordering, returning 20 documents in a different order. The replayer then could not even construct Turn 2's input, because the Turn 2 completion span was absent — so it fell back to "re-invoke the model." The model, given a differently-ordered document set, emitted a *different* `summarize` call. The replay trace diverged at Turn 2 and never reconverged. The forensic report claimed a root cause that the original execution never exhibited. The non-obvious part: **the divergence was not flagged.** The replayer's exit code was 0. The reconstructed span tree was structurally valid. Only a manual diff of the replayed tool-result hashes against the original (which were also truncated, so the diff was inconclusive) surfaced the problem. ## Condition of Validity Deterministic replay from OTel GenAI spans holds **only if** the following invariant is enforced at the span-emission boundary: > For every span `S` in the retained trace, and every attribute `A` on `S` that is an input to a downstream tool call or model call, `A` is recorded either (a) in full, or (b) with an explicit `gen_ai.attribute.truncated=true` marker **and** a content-addressed reference (`gen_ai.payload.ref`) resolvable from an out-of-band full-fidelity store. The invariant fails in three specific ways, each of which we observed: 1. **Silent truncation.** The OTel SDK's length limit truncates without setting any marker. The span looks complete. This is the primary failure: the replayer cannot distinguish "argument was 200 bytes" from "argument was 40 KB and got cut." 2. **Sampling-induced child loss.** Tail sampling operates on the *trace*, not on the *span tree*. A retained root does not imply retained children. A replayer that assumes span-tree closure under a retained root will encounter missing nodes and — worse — will not know whether the node was absent because it was sampled out or because it never executed. 3. **Redaction without provenance.** PII redaction replaces `gen_ai.tool.call.arguments` with `[REDACTED]` but preserves the span. The replayer sees a syntactically valid attribute whose value is semantically empty. It cannot tell "the tool was called with the literal string `[REDACTED]`" (which would be a real, replayable input) from "the input was scrubbed." A trace satisfying observability completeness may fail any of these three. A trace satisfying replay completeness must satisfy all three, plus the content-addressing requirement. ## Decision Boundary The decision is: **when is a retained trace admissible as a replay input, versus only as a human-readable artifact?** The boundary is drawn by a pre-replay admissibility check, not by the replayer itself. The check must be conservative and must fail closed: - If any span in the reconstructed tree has an attribute whose length equals the configured `OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT` exactly, treat it as truncated (the limit is inclusive; exact-length values are indistinguishable from cut values). - If any parent span is present but a child span referenced by `parent_span_id` is absent from the retained set, the trace is *structurally incomplete* and inadmissible for replay, even if the missing child is non-error. - If any `gen_ai.tool.call.arguments` or `gen_ai.completion` attribute matches the redaction sentinel, the trace is inadmissible unless a `gen_ai.payload.ref` resolves to a full-fidelity copy. Only traces passing all three checks enter the deterministic replayer. Everything else enters a *reconstruction* path that explicitly models uncertainty: it may re-invoke the model with the truncated input and record the divergence as a first-class artifact, but it must never claim to reproduce the original execution. The critical asymmetry: **the replayer must not be the component that decides admissibility.** A replayer that discovers truncation mid-execution has already produced a divergent trace that looks valid. The check must run before the first span is fed to the executor, and it must produce a typed verdict (`ADMISSIBLE`, `DEGRADED`, `INADMISSIBLE`) that the forensic report carries. ## Operational Effect Enforcing the invariant changes three things: 1. **Span emission cost.** Full-fidelity payload capture for tool arguments and completions is expensive. The mitigation is content-addressing: emit a `gen_ai.payload.sha256` and `gen_ai.payload.ref` on the span, store the full payload in a cheaper object store keyed by hash, and let the span carry only the reference. The span remains small; replay completeness is preserved because the reference resolves. 2. **Sampling policy.** Tail sampling must be span-tree-aware, not trace-aware, for any trace flagged as a replay candidate. The simplest correct policy: if any span in a trace carries `gen_ai.replay.candidate=true`, retain the entire span tree unconditionally. This trades storage for admissibility. 3. **Forensic claims.** The forensic report must state the admissibility verdict alongside the root cause. A root cause derived from an `INADMISSIBLE` trace is a hypothesis, not a finding. This is the operational discipline that the boundary enforces: the replay's *confidence* is bounded by the trace's *admissibility*, and the two must travel together. The failure mode is not that replay diverges — divergence under lossy input is expected. The failure mode is that divergence is *unmarked*, and a divergent replay is presented as a reproduction. The invariant exists to make the marking mandatory. ```python class ReplayInadmissibleError(RuntimeError): """Raised when a retained OTel GenAI trace cannot serve as a deterministic replay input.""" pass TRUNCATION_SENTINEL = "[REDACTED]" def check_replay_admissibility( spans: list[dict], attribute_length_limit: int, resolvable_payload_refs: set[str], ) -> str: """ Returns 'ADMISSIBLE', 'DEGRADED', or 'INADMISSIBLE'. Fails closed: any ambiguity resolves to a stricter verdict. """ present_ids = {s["span_id"] for s in spans} for span in spans: attrs = span.get("attributes", {}) # Structural closure: every referenced parent must be present. parent = span.get("parent_span_id") if parent is not None and parent not in present_ids: raise ReplayInadmissibleError( f"span {span['span_id']} references absent parent {parent}; " "trace tree is not closed under retained set" ) for key, value in attrs.items(): if not (key.startswith("gen_ai.tool.call.arguments") or key.startswith("gen_ai.completion") or key.startswith("gen_ai.tool.call.result")): continue if isinstance(value, str) and len(value) == attribute_length_limit: # Exact-length is indistinguishable from truncated. Fail closed. raise ReplayInadmissibleError( f"span {span['span_id']} attribute {key} length == " f"limit {attribute_length_limit}; treated as truncated" ) if value == TRUNCATION_SENTINEL: ref = attrs.get(f"{key}.ref") if ref is None or ref not in resolvable_payload_refs: raise ReplayInadmissibleError( f"span {span['span_id']} attribute {key} is redacted " f"with no resolvable payload ref" ) # If we reached here, the trace is structurally and payload-complete. return "ADMISSIBLE" ```