# When must an instance refuse to replay a trajectory that OTel telemetry claims is complete? **Date of Record:** 2026 November 27 **Scope:** Applies to deterministic replay and counterfactual debugging of LLM agent trajectories reconstructed from OpenTelemetry (OTel) spans, where replay is expected to reproduce the original tool-call sequence and model outputs bit-for-bit. Does not apply to statistical offline evaluation, sampling-based regression suites, or traces where the agent's sampling temperature > 0 and no seed was recorded. ## Core Distinction The distinction that matters is between **span completeness** and **causal completeness**. A trace can be 100% span-complete—every `gen_ai.*` span closed, every `tool_call` span with a matching response, no dropped spans in the exporter queue—while still being causally incomplete for replay, because the *inputs* to a given span were not themselves captured as first-class attributes. Replay determinism requires that every non-deterministic function call in the trajectory be a *pure function of recorded state*. OTel's semantic conventions for GenAI capture the *outputs* of tool calls and the *prompt/completion* of model calls, but they do not guarantee capture of the *sampling parameters*, *tool version hashes*, *retrieved context byte-ranges*, or *ambient clock/rng state* that produced those outputs. A trace that looks archival-grade is often only a *transcript*, not a *program image*. The failure mode: a replay engine loads a trace, sees a clean parent-child span tree with `status=OK` on every node, and begins re-execution. It reproduces the first N steps, then diverges at step N+1 because the recorded tool response was the result of a non-deterministic external call (e.g., a vector search over a mutable index, a shell command whose output depends on filesystem state) that the trace recorded as an *opaque payload* rather than as a *replayable input*. The divergence is silent: the replayed agent continues, produces a different trajectory, and the counterfactual debugger attributes the difference to the *change under test* rather than to the *replay artifact*. This is the boundary failure: **a trace that is span-complete but not replay-closed will produce a false-positive counterfactual**. ## What Was Observed A representative incident: an agent with a `search_docs` tool and a `run_shell` tool, instrumented with OTel `gen_ai` spans. The trace for a failing run contained 14 spans, all `status=OK`, all with `parent_span_id` set, all exported within the batch interval. The replay engine (a custom harness that re-issued the recorded prompts to the same model with `temperature=0` and `seed=42`) reproduced steps 1–6 exactly. At step 7, the recorded `search_docs` span carried `gen_ai.tool.result.count=3` and a `gen_ai.tool.result.hashes` attribute, but the *retrieved document bodies* were not captured—only their hashes and IDs. The replay engine, lacking the bodies, re-issued the same query to the live index. The live index had been reindexed 40 minutes earlier. The replay retrieved 3 documents with *different* hashes, the model's step-8 reasoning diverged, and the harness reported "counterfactual change caused step-8 divergence" when in fact the divergence was caused by *index drift between capture time and replay time*. The tell: the recorded `gen_ai.tool.result.hashes` at step 7 did not match the hashes the replay engine computed at step 7. The harness had no invariant asserting that replay-time tool outputs must equal capture-time tool outputs *for spans marked as replay-authoritative*. It treated tool output as a side effect to be tolerated, not as a boundary condition to be verified. A second, subtler observation: the trace's `gen_ai.request.seed` attribute was present on model spans but absent on tool spans. The replay engine assumed tool determinism by default. In reality, `run_shell` at step 4 had executed `date +%s` and the model had consumed the timestamp as a reasoning input. The recorded span stored the *output* (`"1744632000"`) but not the *command's determinism class*. Replay reproduced the same string only because the replay window happened to be within the same second; a replay 2 seconds later would have diverged at step 4. ## Condition of Validity A trajectory is **replay-closed**—and therefore safe to use as the basis for counterfactual debugging—if and only if the following invariant holds for every span in the trace: > For every span `s` with a non-deterministic effect (model sampling, tool I/O, clock read, RNG read, network fetch, filesystem read), the span either (a) carries a `replay.authoritative=true` attribute together with a byte-exact capture of its output, or (b) carries a `replay.determinism=seeded` attribute together with the seed/parameter that reproduces the output, or (c) is explicitly marked `replay.opaque=true` and is *excluded* from the counterfactual's causal attribution. The condition of validity is not "all spans present." It is "all non-determinism accounted for." A trace with a missing span is *obviously* incomplete and will be rejected by any sane loader. A trace with all spans present but with an unaccounted non-determinism is *deceptively* complete and is the dangerous case. The invariant must be enforced at load time, not at divergence time, because by divergence time the counterfactual has already produced a wrong answer. Corollary: **replay-closure is a property of the trace, not of the replay engine.** An engine cannot manufacture determinism from a trace that did not capture it. The engine's job is to *detect* non-closure and refuse, not to paper over it with best-effort re-execution. ## Decision Boundary The boundary between "replay and attribute" and "refuse to replay" is crossed at the first span whose non-determinism class is `unknown` or `live` and whose output was not byte-captured. Concretely: - **Replay and attribute** when every span in the causal chain from root to the divergence point is `replay-authoritative` (output captured) or `replay-determinism=seeded` (seed recorded and honored). Tool outputs captured as opaque blobs with a `replay.authoritative=true` marker are fine—the engine replays the *blob*, not the tool. - **Refuse to replay** when any span in the causal chain is `replay.determinism=live` (e.g., a shell command, a live index query, a clock read) and its output was not captured byte-exact. Re-issuing the live call is *not* replay; it is a new experiment with an unmodeled variable. - **Refuse to replay** when the trace's `gen_ai.request.seed` is present on some model spans but absent on others in the same causal chain, because the harness cannot know which spans were sampled and which were greedy. - **Refuse to replay** when the trace has a `replay.authoritative=true` marker on a span whose captured output hash does not match the hash recomputed at replay time—this indicates either trace corruption or a hash-collision attack on the replay boundary. The decision is *per causal chain*, not *per trace*. A trace may contain 13 replay-closed spans and 1 opaque span; the counterfactual is valid for questions whose causal chain does not pass through the opaque span, and invalid for questions that do. The engine must compute the causal chain for each counterfactual question and check closure on that chain, not on the whole trace. ## Operational Effect The operational effect of enforcing replay-closure is a shift from *post-hoc divergence attribution* to *pre-replay admissibility checking*. In practice this means: 1. **Instrumentation must capture determinism class at span creation time.** A tool wrapper must declare `replay.determinism ∈ {authoritative, seeded, live, opaque}` before the span closes. Retrofitting this at export time is impossible because the wrapper no longer knows whether the output was reproducible. 2. **Replay engines must fail closed.** A replay engine that silently re-issues live calls when captured output is missing will produce counterfactuals that look plausible and are wrong. The engine must raise on the first non-closed span in the causal chain. 3. **Counterfactual reports must carry an admissibility stamp.** Every reported "change X caused divergence at step N" must be accompanied by the closure status of the causal chain to step N. Reports without this stamp are unfalsifiable. 4. **Trace retention must include tool output bodies, not just hashes.** Hash-only capture (as in the incident above) is insufficient for replay because it detects divergence but cannot *replay through* it. The body must be stored, or the span must be marked `opaque` and excluded from attribution. The cost is storage: capturing tool output bodies increases trace size, sometimes by orders of magnitude for retrieval-heavy agents. The alternative—hash-only traces—produces a class of counterfactual bugs that are indistinguishable from real regressions until someone manually diffs the trace against the live system. The invariant trades storage for falsifiability. ```python import hashlib from dataclasses import dataclass from enum import Enum from typing import Optional class DeterminismClass(Enum): AUTHORITATIVE = "authoritative" # output captured byte-exact SEEDED = "seeded" # reproducible via recorded seed LIVE = "live" # non-deterministic, not captured OPAQUE = "opaque" # excluded from causal attribution UNKNOWN = "unknown" # not declared; treated as unsafe @dataclass class Span: span_id: str parent_span_id: Optional[str] determinism: DeterminismClass captured_output_hash: Optional[str] = None captured_output_body: Optional[bytes] = None seed: Optional[int] = None class ReplayNotClosedError(RuntimeError): """Raised when a trace is span-complete but not replay-closed.""" def causal_chain(spans: dict[str, Span], leaf_id: str) -> list[Span]: chain, cursor = [], leaf_id while cursor is not None: if cursor not in spans: raise ReplayNotClosedError( f"causal chain broken: span {cursor!r} referenced but absent" ) span = spans[cursor] chain.append(span) cursor = span.parent_span_id return list(reversed(chain)) def assert_replay_closed(spans: dict[str, Span], leaf_id: str) -> None: for span in causal_chain(spans, leaf_id): if span.determinism is DeterminismClass.LIVE: raise ReplayNotClosedError( f"span {span.span_id!r} is determinism=live and was not " f"byte-captured; replay would re-issue a live call" ) if span.determinism is DeterminismClass.UNKNOWN: raise ReplayNotClosedError( f"span {span.span_id!r} has undeclared determinism class; " f"replay cannot bound its non-determinism" ) if span.determinism is DeterminismClass.SEEDED and span.seed is None: raise ReplayNotClosedError( f"span {span.span_id!r} is determinism=seeded but no seed " f"was recorded; replay would diverge silently" ) if span.determinism is DeterminismClass.AUTHORITATIVE: if span.captured_output_body is None: raise ReplayNotClosedError( f"span {span.span_id!r} is authoritative but only a hash " f"was captured; replay cannot reproduce the output body" ) recomputed = hashlib.sha256(span.captured_output_body).hexdigest() if span.captured_output_hash and recomputed != span.captured_output_hash: raise ReplayNotClosedError( f"span {span.span_id!r} authoritative hash mismatch: " f"recorded={span.captured_output_hash!r} " f"recomputed={recomputed!r}" ) def replay_counterfactual(spans: dict[str, Span], leaf_id: str) -> None: assert_replay_closed(spans, leaf_id) # ... re-execute using captured bodies / seeds only ... ```