# In what scenarios must an instance abandon deterministic replay of an OTel span graph and fall back to forensic reconstruction **Date of Record:** 2026 November 27 **Scope:** Applies to post-hoc audit, incident reconstruction, and regression replay of single- or multi-agent sessions instrumented with OpenTelemetry (span-per-tool-call, span-per-LLM-turn) where the reconstruction engine attempts to re-execute the recorded decision sequence to reproduce a terminal state. Does not apply to live tracing, sampling strategy, or span-schema design. ## Core Distinction Deterministic replay assumes the span graph is a *complete causal record*: every input that influenced an agent's output appears as a span attribute or as a parent span's output, and re-feeding those inputs reproduces the same output. Forensic reconstruction assumes the opposite—that the span graph is a *lossy projection* of the true execution, and the auditor must infer missing state from side evidence (tool server logs, model provider request IDs, wall-clock ordering of sibling spans) rather than re-execute. The boundary between the two is not "did the replay diverge." It is **whether the divergence is attributable to a recorded input or to an unrecorded input**. A replay that diverges because the LLM sampled a different token at temperature 0 is a *replay defect* (fixable: pin seed, pin model version). A replay that diverges because the span graph never captured a piece of state the agent actually consumed is a *record defect*—and no amount of replay engineering recovers it. The invariant: **a span graph is replay-deterministic if and only if every span's output is a pure function of (a) its recorded input attributes, (b) its parent's recorded output, and (c) a recorded model/tool version tuple.** Violation of any of the three clauses forces reconstruction. ## What Was Observed A coding agent session (12 LLM turns, 31 tool spans) terminated with a file-write that clobbered a config. On replay from the span graph, the agent did *not* perform the clobbering write; it instead issued a `read` of the same file and stopped. The divergence appeared at turn 9. Root cause: the tool span for `read` at turn 8 recorded `output.file_content` truncated at 4096 bytes (an OTel attribute size cap applied by the exporter). The live agent had seen the full 11 KB file. At turn 9, the live agent's context contained a line beyond byte 4096 that instructed a `write`; the replayed agent's context did not. The span graph was internally consistent—every recorded attribute re-fed cleanly—but it was not *causally closed*: a span output that the agent consumed was silently truncated, and no attribute marked the truncation. A second, distinct failure in the same corpus: a multi-agent handoff where the receiving agent's first LLM span had `input.messages` populated from the sender's final message, but the sender's *tool-result* span (which the sender had folded into that message) was a sibling, not an ancestor, of the receiver's span. Replay re-ordered them by `start_time`, and a 40 ms clock skew between two hosts put the tool result *after* the receiver's turn. The replay executed a handoff with a stale message; live execution had the fresh one. The span graph's parent-child edges were correct; its *temporal* edges were not, and the replay engine trusted time over structure. Both cases share a signature: **replay diverges at a turn whose input span has an attribute that was clipped, absent, or temporally misordered relative to its consumer.** The divergence is silent—the replayed agent produces plausible output, not an error—so a naive replay harness reports "session reproduced" while reproducing a *different* session. ## Condition of Validity Deterministic replay is valid only when all of the following hold for the span graph under audit: 1. **Attribute completeness.** No span attribute consumed by a downstream LLM call was truncated by an exporter limit. This is checkable: for each LLM span, every `input.messages[i].content` must byte-match the corresponding upstream tool span's `output` (or be explicitly marked `truncated: true`). A mismatch with no truncation flag is a record defect. 2. **Causal-edge fidelity.** Every span that contributed to an LLM span's input is an *ancestor* of that span, not merely temporally prior. Sibling spans ordered by `start_time` are not causal evidence. If a tool result is a sibling of the LLM span that consumed it, the graph has lost the edge and replay must not infer it from time. 3. **Version pinning.** The model identifier, sampling parameters, and tool binary version are recorded on every LLM and tool span respectively. A span missing `gen_ai.request.model` or a tool `version` attribute cannot be replayed deterministically even if its inputs are complete, because the function being replayed is unknown. 4. **No ambient state.** The agent did not read state outside the span graph—environment variables, filesystem state not captured by a tool span, clock time injected into a prompt. Any prompt containing a timestamp or a `pwd` result not backed by a tool span violates this. When any condition fails, the session is *reconstructible* but not *replayable*. The correct action is to switch modes, not to retry replay with perturbed seeds. ## Decision Boundary The auditor's decision procedure, per session: - **Replay** if all four conditions hold. Re-execute; if terminal state matches recorded terminal state, the audit is closed with a determinism certificate. - **Reconstruct** if condition 1 or 2 fails but the terminal state is known. Do not re-execute the agent. Instead, assemble the *maximal consistent evidence set*: for each divergent turn, gather the tool server's own logs (keyed by the span's `trace_id` + `span_id` if the tool propagated context, else by timestamp window), the model provider's request ID from the LLM span, and any sibling spans within the causal window. The reconstruction's output is a *narrative with provenance*, not a re-executed trace—every claim cites a span ID or an external log line. - **Quarantine** if condition 3 or 4 fails and no external evidence exists. The session cannot be reconstructed to the standard required for a root-cause finding; record it as an audit gap rather than fabricating a causal chain. The non-obvious part: **a replay that succeeds is not evidence the graph was complete.** A truncated input that happens not to change the sampled output (because the model was confident, or the truncated bytes were irrelevant) yields a passing replay over a defective record. Replay success is necessary but not sufficient for record validity; the completeness checks (1–4) must run *before* replay, not be inferred from its outcome. ## Operational Effect Teams that treat replay success as the audit's terminal signal systematically under-detect record defects: the sessions that replay cleanly are exactly the ones where truncation or misordering happened not to matter, so the defect population is invisible until a high-stakes incident lands on one of the minority that diverge. The fix is to invert the gate—run the completeness checks as a precondition, emit a `RecordDefect` for each violated clause, and route those sessions to reconstruction regardless of whether replay would have passed. This converts a silent, sampling-dependent audit into a deterministic one, at the cost of reconstructing more sessions than strictly necessary. That cost is the price of the invariant: **you may only claim determinism for a session whose span graph you have proven causally closed, never for one that merely replayed.** ```python from dataclasses import dataclass from typing import Optional class ReplayInvalidError(RuntimeError): """Raised when a session's span graph is not causally closed and must not be replayed.""" @dataclass class Span: span_id: str parent_id: Optional[str] kind: str # "llm" | "tool" attributes: dict start_time: float def check_causal_closure(spans: list[Span]) -> None: by_id = {s.span_id: s for s in spans} for s in spans: if s.kind == "llm": model = s.attributes.get("gen_ai.request.model") if not model: raise ReplayInvalidError( f"span {s.span_id}: LLM span missing model pin; function unknown, " "replay would be non-deterministic" ) for msg in s.attributes.get("input.messages", []): src = msg.get("source_span_id") if src is None: continue producer = by_id.get(src) if producer is None: raise ReplayInvalidError( f"span {s.span_id}: input cites absent span {src}" ) # causal edge must be ancestry, not mere temporal priority anc, cur = set(), producer.parent_id while cur is not None: anc.add(cur) cur = by_id[cur].parent_id if cur in by_id else None if s.span_id not in anc: raise ReplayInvalidError( f"span {s.span_id}: consumed output of {src} which is not an " "ancestor; temporal ordering cannot substitute for the lost edge" ) if producer.attributes.get("output.truncated") and not msg.get("truncated"): raise ReplayInvalidError( f"span {s.span_id}: consumed truncated output of {src} without " "truncation marker; replay would silently reproduce a different session" ) def audit_session(spans: list[Span], terminal_state_known: bool) -> str: try: check_causal_closure(spans) except ReplayInvalidError: return "reconstruct" if terminal_state_known else "quarantine" return "replay" ```