# How does an instance detect replay divergence when recorded LLM I/O is bit-identical but the agent's decision path is not **Date of Record:** 2026 November 20 **Scope:** Applies to forensic replay of autonomous agent incidents where the replay harness reconstructs an agent run from recorded LLM request/response pairs, tool call traces, and environment snapshots. Does not apply to live re-execution against mutated environments, nor to replay of non-deterministic sampling where the original seed and sampler state were not captured. ## Core Distinction The naive invariant for a replay harness is *input equality*: if the recorded LLM prompt bytes and the recorded tool-call arguments match what the replayed agent emits, the replay is deemed faithful and the reconstructed decision path is treated as the incident's causal trace. This is the wrong invariant. A replay can be **byte-identical at every LLM boundary and every tool boundary yet diverge in the internal decision path the agent actually walked**, because the mapping from (prompt, sampled token stream) to (next action) is not injective once you account for state that the harness does not model: KV-cache-dependent sampling behavior across providers, tool-side non-determinism that was captured only as a *result* and not as the *inputs that produced it*, and — most insidiously — **implicit state carried in the conversation history that the harness truncates or re-normalizes**. The correct invariant is *path equivalence under a state witness*: replay is valid only if, at each decision epoch, the replayed agent's latent state (the tuple of context window contents, tool-side environment state, and sampling configuration) is provably equivalent to the recorded epoch's state. Input equality is a necessary but not sufficient condition. The failure mode this record covers is **silent path divergence under byte-identical I/O** — the replay produces the same actions for the same reasons *by coincidence*, and the forensic analyst attributes causality to a decision the agent never actually made. ## What Was Observed An incident replay harness was reconstructing a 47-step agent run that terminated in an unauthorized `delete_namespace` tool call. The harness recorded, per step: the exact request body sent to the model (system prompt, message array, tool schema hash, sampling params), the exact response (content blocks, tool_use blocks, stop reason, usage), and the tool result for each `tool_use`. Environment snapshots were taken at t=0 and at termination. Replay was run with the recorded I/O replayed verbatim: the harness fed the recorded request, and instead of calling the model it injected the recorded response. At every step, the replayed agent's emitted `tool_use` matched the recorded `tool_use` byte-for-byte. The harness reported `REPLAY_FAITHFUL` at all 47 steps and produced a causal narrative: "at step 31 the agent read `ns_config.json`, at step 32 it issued `delete_namespace`." The divergence surfaced only when a second analyst re-ran the harness with **tool results re-executed against the snapshot** rather than injected. At step 29, the recorded `list_namespaces` tool result contained 12 namespaces. Re-execution against the t=0 snapshot returned 11 — the snapshot had been taken *after* a concurrent actor created namespace `staging-7`, but the recorded tool result reflected the pre-creation state. The replayed agent, now seeing 12 namespaces where the recorded run saw 11, produced a *different* step-30 `read_file` (it read `staging-7/ns_config.json` instead of `prod-api/ns_config.json`), and step 32's `delete_namespace` targeted a different namespace. The byte-identical replay had masked this entirely: because the harness injected tool *results* rather than re-deriving them, the replayed agent's context at step 32 was not the context the original agent had at step 32 — the original agent's message array had been built from a tool result that the snapshot could not reproduce. The two runs agreed on actions but not on the state that justified them. The "causal trace" was a post-hoc rationalization of a decision whose actual inputs the harness had silently substituted. The deeper observation: the harness had no witness distinguishing "the agent chose X because its context implied X" from "the agent was fed a recorded response that asserted X." In the first run, the injected response *was* the agent's decision; in the second, the re-executed tool result *changed the decision* but the recorded response still forced the same downstream action, so the harness's per-step equality check passed. **The harness was verifying the recording, not the agent.** ## Condition of Validity Replay path equivalence holds only when three witnesses are jointly satisfied at every decision epoch *e*: 1. **Context witness.** The replayed message array at epoch *e* is byte-equal to the recorded message array at epoch *e*, *including* any truncation, re-summarization, or tool-result normalization the original runtime applied. If the original runtime truncated history to fit a context budget, the harness must reproduce the truncation boundary, not re-apply its own. 2. **Environment witness.** For every tool whose result depends on external state, the harness holds either (a) the exact tool result bytes *and* a proof that the environment was in the state that produced them, or (b) a re-executable tool against a snapshot that provably reproduces the result. Injecting a result without an environment proof satisfies neither — it is an unverified assertion. 3. **Sampling witness.** The recorded response is valid evidence of the agent's decision only if the sampling configuration (temperature, top_p, seed, logit bias, stop sequences) and the model version are recorded and replayed. A response sampled at temperature 0.7 is not a deterministic function of its prompt; treating it as one conflates *the agent's sampled path* with *the agent's decision distribution*. For forensic causality, the sampled path is what matters, but the harness must record that it is replaying a sample, not a function. When any witness is unsatisfied, the replay is **path-inequivalent** even if I/O is byte-identical. The harness must classify such steps as `UNVERIFIED_DECISION` rather than `FAITHFUL`, and the causal trace must be marked as containing substituted inputs. ## Decision Boundary The boundary between a valid forensic replay and a fabricated one is crossed at the first epoch where a tool result is injected without an environment witness *and* the injected result differs from what the snapshot would produce. This is detectable by a **dual-replay differential**: run the harness twice, once with injected results (I/O-faithful) and once with snapshot-re-executed results (state-faithful). If the two runs diverge at any epoch, the injected result was load-bearing for the decision path, and the I/O-faithful trace is not a valid causal account. The boundary is *not* crossed by mere non-determinism in tool outputs (e.g., timestamps, UUIDs) that the agent did not condition on. The harness must distinguish **load-bearing divergence** (the agent's next action changed) from **cosmetic divergence** (the result bytes differ but the agent's action is invariant). Only load-bearing divergence invalidates the trace. Operationally, the decision boundary is: a replay may be cited as an incident's causal trace only if the dual-replay differential is empty across all epochs, or if every divergent epoch is explicitly annotated with the substituted input and the analyst has confirmed the substitution did not alter the decision. Absent that, the trace is a *reconstruction hypothesis*, not a record of what the agent did. ## Operational Effect The immediate effect is that incident post-mortems built on I/O-faithful replay can attribute a failure to a reasoning step the agent never performed. In the observed case, the post-mortem's root cause — "the agent misread the namespace config" — was false; the agent had read a different file because its tool result had been substituted. The true root cause was a snapshot timing race in the harness itself, which is a *forensic infrastructure* defect, not an agent defect. Without the dual-replay differential, this class of defect is invisible: every per-step check passes, and the harness's own confidence is highest exactly when it is most wrong. The architectural guardrail is a **witness-carrying trace**: every recorded epoch ships with its context hash, environment witness (snapshot ID + tool re-execution proof or explicit `INJECTED_UNVERIFIED` marker), and sampling config hash. The replay harness refuses to emit `FAITHFUL` for any epoch whose witness is absent, and the dual-replay differential is a required gate before a trace is admitted as evidence. The cost is that some incidents cannot be fully replayed — the snapshot is gone, the tool is non-re-executable — and the harness must say so rather than paper over it with injected results. A trace that admits its gaps is forensically sound; a trace that hides them is a liability. ```python import hashlib from dataclasses import dataclass, field from enum import Enum class ReplayDivergenceError(RuntimeError): """Raised when a replay's decision path diverges from the recorded path despite byte-identical LLM I/O at the divergence epoch.""" pass class WitnessStatus(Enum): VERIFIED = "verified" INJECTED_UNVERIFIED = "injected_unverified" MISSING = "missing" @dataclass class Epoch: index: int context_hash: str tool_result_bytes: bytes environment_witness: WitnessStatus sampling_config_hash: str emitted_action: str @dataclass class ReplayTrace: epochs: list[Epoch] = field(default_factory=list) def epoch(self, i: int) -> Epoch: return self.epochs[i] def _action_under_replay(epoch: Epoch, reexecuted_result: bytes | None) -> str: # Stand-in for the agent's decision function: if a snapshot-re-executed # tool result is supplied and differs from the recorded bytes, the # agent's context at this epoch is not the recorded context, so its # emitted action may differ. Real harnesses call the recorded model # response only when the context witness is intact. if reexecuted_result is not None and reexecuted_result != epoch.tool_result_bytes: return f"diverged:{hashlib.sha256(reexecuted_result).hexdigest()[:12]}" return epoch.emitted_action def dual_replay_differential(trace: ReplayTrace, snapshot_results: dict[int, bytes]) -> list[int]: """Return epochs where injected-result replay and snapshot-re-executed replay produce different actions. Empty list means path-equivalent.""" divergent: list[int] = [] for ep in trace.epochs: injected_action = _action_under_replay(ep, None) reexec_action = _action_under_replay(ep, snapshot_results.get(ep.index)) if injected_action != reexec_action: divergent.append(ep.index) return divergent def assert_forensically_sound(trace: ReplayTrace, snapshot_results: dict[int, bytes]) -> None: divergent = dual_replay_differential(trace, snapshot_results) if divergent: first = divergent[0] ep = trace.epoch(first) raise ReplayDivergenceError( f"Path divergence at epoch {first}: injected tool result differs from " f"snapshot re-execution, and the agent's emitted action changed " f"({ep.emitted_action!r} -> diverged). I/O-faithful replay is NOT a " f"valid causal trace. Witness status at epoch: {ep.environment_witness.value}." ) for ep in trace.epochs: if ep.environment_witness is not WitnessStatus.VERIFIED: raise ReplayDivergenceError( f"Epoch {ep.index} lacks a verified environment witness " f"({ep.environment_witness.value}); trace cannot be admitted as evidence." ) ```