# Why does an instance-level trace replay diverge from the causal chain it claims to reconstruct when semantic conventions bind span attributes at emission time **Date of Record:** 2026 November 29 **Scope:** Applies to post-incident causal reconstruction of autonomous agent runs that are replayed from OpenTelemetry-style spans carrying GenAI semantic conventions (`gen_ai.*`), where the replay engine reconstructs state by re-executing or re-interpreting recorded spans. Does not apply to live tracing, to span export/sampling pipelines, or to replays that record full token-level model I/O and treat spans as opaque blobs. ## Core Distinction The failure is not "the trace is incomplete." It is that **semantic-convention attributes are bound at span emission time, not at decision time**, and the replay engine silently treats the bound value as if it were the input the agent actually reasoned over. When an agent emits a `gen_ai.chat` span, the attributes written (`gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.response.finish_reasons`, and any custom `gen_ai.prompt.*` fields) are snapshots taken by the instrumenting SDK *after* the model call returns. The replay engine, reading these spans, reconstructs a causal chain in which the model "saw" the prompt described by the span. But the prompt the model actually conditioned on was assembled from context that may have been mutated, truncated, or re-fetched between the decision to call and the emission of the attribute. The convention does not carry a hash of the conditioning context, only its post-hoc description. Replay therefore reconstructs the *story the SDK told about the call*, not the *call*. This is a narrow, load-bearing boundary: the trace is faithful as a record of *what was emitted*, and unfaithful as a record of *what was conditioned on*. Replay engines that conflate the two produce causally plausible but wrong incident narratives, and they do so most confidently precisely when the incident involved context mutation. ## What Was Observed A multi-step research agent (`plan → retrieve → synthesize → verify`) failed a verification step at turn 7 with a hallucinated citation. The incident trace showed: - Turn 4 `gen_ai.chat` span: `gen_ai.prompt.message.3.content` = a retrieval result containing the correct document ID `DOC-8821`. - Turn 6 `gen_ai.chat` span: `gen_ai.prompt.message.5.content` = a *different* retrieval result, `DOC-4417`, with no record of how the context changed. - Turn 7 verification span: `gen_ai.response.finish_reasons = ["stop"]`, cited `DOC-8821`. Replay reconstructed a clean causal chain: the model at turn 6 still had `DOC-8821` in context (it appeared in turn 4), so turn 7's citation was "supported by context" — the replay engine concluded the verifier hallucinated a *rejection*, and the incident was tagged as a verifier calibration bug. The actual mechanism: between turn 4 emission and turn 6 emission, the agent's context manager evicted turn 4's retrieval result to stay under a context budget, and the `gen_ai.prompt.message.N` indices in the turn 6 span were **renumbered**. The SDK emitted `message.5` as the turn 6 retrieval result, but the replay engine's decoder assumed stable message indices across spans and stitched turn 4's `message.3` into turn 6's window. The replay reconstructed a context window the model never saw. The real failure was a **retrieval mismatch after eviction**: the model at turn 6 had only `DOC-4417` and confabulated `DOC-8821` from a stale summary line that survived eviction. The replay's causal chain was inverted: it exonerated the model and indicted the verifier. The tell was a **token-count discontinuity**: turn 6's `gen_ai.usage.input_tokens` was 1,140, but the replayed prompt assembled from stitched spans totaled 2,310 tokens. The replay engine did not check this invariant. It had a faithful record of token usage and a fabricated record of prompt content, and it trusted the latter. ## Condition of Validity The replay's causal reconstruction is valid only if, for every replayed `gen_ai.chat` span, the following invariant holds: **Span-content invariant:** `tokenize(reconstructed_prompt(span)) == span.gen_ai.usage.input_tokens ± tokenizer_drift`, where `tokenizer_drift` is bounded by the known tokenizer version recorded in `gen_ai.request.model` (or a `gen_ai.tokenizer.version` extension attribute). If the reconstructed prompt's token count diverges from the recorded usage beyond that bound, the reconstruction is **not** a reconstruction of the conditioning context and must not be used as causal evidence. This invariant is necessary but not sufficient. It catches eviction-and-renumbering (the case above), mid-window truncation, and tool-result substitution between decision and emission. It does not catch substitutions that preserve token count — those require a `gen_ai.prompt.hash` extension attribute (a hash of the exact serialized conditioning context) recorded at emission, checked at replay. Absent that attribute, the replay engine must mark the span as `conditioning_unverified` and downgrade any causal claim that depends on it. The convention as written does not mandate either check. That is the boundary: **the semantic conventions describe the call; they do not witness the conditioning**. Replay correctness is a property the replay engine must enforce, not a property the trace provides. ## Decision Boundary The replay engine must branch on the token-count check per span, not per trace: - **Divergence within bound** → span is `conditioning_verified`; causal edges through it are admissible. - **Divergence beyond bound, no `gen_ai.prompt.hash`** → span is `conditioning_unverified`; any causal edge that *depends on span content* (e.g., "model saw X at turn N") is inadmissible. Edges that depend only on span *existence* and *ordering* (e.g., "turn 6 preceded turn 7") remain admissible. - **Divergence beyond bound, with `gen_ai.prompt.hash`** → recompute the hash from the reconstructed context; if it matches, the divergence is tokenizer drift and the span is `conditioning_verified_with_drift`; if it does not match, the span is `conditioning_corrupted` and the replay must halt on that branch rather than emit a narrative. The non-obvious part of the boundary: **a trace can be 100% complete and still yield an inadmissible causal chain**, because completeness is a property of span coverage while admissibility is a property of conditioning verification. Operators routinely conflate them and accept a fully-covered trace as authoritative. The boundary is crossed the moment a replay engine emits a causal claim ("the model was conditioned on X") from a span that only records ("the SDK reported X after the call"). ## Operational Effect Downstream consumers of the replay — incident postmortems, verifier-calibration datasets, regression suites built from replayed failures — inherit the inversion. In the observed case, the verifier was retuned against a hallucination it did not commit, and the actual failure (context eviction without a tombstone) went unremediated for three weeks until a second incident reproduced it with a token-count discontinuity large enough to trip a manual audit. The guardrail is not "record more spans." It is: **record the conditioning hash at emission, and make the replay engine refuse to emit content-dependent causal edges when the hash is absent or the token-count invariant fails.** A replay that cannot verify conditioning must degrade to an ordering-only reconstruction — it can say *when* things happened and *that* a call occurred, but not *what the model reasoned over*. That degradation is the correct operational posture, and it is the one the semantic conventions, as currently specified, do not force. ```python import hashlib from dataclasses import dataclass class ConditioningUnverifiedError(RuntimeError): """Raised when a replay span's conditioning context cannot be verified against recorded usage or hash, making content-dependent causal edges inadmissible.""" @dataclass class ReplaySpan: span_id: str reconstructed_prompt: str recorded_input_tokens: int recorded_prompt_hash: str | None # gen_ai.prompt.hash extension, if present tokenizer_drift_bound: int = 8 def verify_conditioning(span: ReplaySpan, tokenize) -> str: reconstructed_tokens = len(tokenize(span.reconstructed_prompt)) drift = abs(reconstructed_tokens - span.recorded_input_tokens) if drift <= span.tokenizer_drift_bound: return "conditioning_verified" if span.recorded_prompt_hash is None: raise ConditioningUnverifiedError( f"span {span.span_id}: token drift {drift} exceeds bound " f"{span.tokenizer_drift_bound} and no gen_ai.prompt.hash present; " f"content-dependent causal edges inadmissible" ) recomputed = hashlib.sha256(span.reconstructed_prompt.encode()).hexdigest() if recomputed != span.recorded_prompt_hash: raise ConditioningUnverifiedError( f"span {span.span_id}: prompt hash mismatch " f"(recorded {span.recorded_prompt_hash[:12]}..., " f"recomputed {recomputed[:12]}...); replay branch must halt" ) return "conditioning_verified_with_drift" def build_causal_edge(span: ReplaySpan, tokenize, claim: str) -> dict: status = verify_conditioning(span, tokenize) if status == "conditioning_verified_with_drift": # admissible, but annotate the edge so downstream consumers know drift occurred return {"span": span.span_id, "claim": claim, "status": status, "drift_annotated": True} return {"span": span.span_id, "claim": claim, "status": status, "drift_annotated": False} ```