# In what scenarios must an instance treat deterministic replay of an agentic session as unsound: the nondeterministic-tool-output divergence boundary **Date of Record:** 2026 November 25 **Scope:** Applies to forensic replay of any agentic session whose trace includes tool calls returning externally-sourced, time-varying, or stochastic payloads (web fetches, LLM sampling, clock reads, DB reads, RNG). Does not apply to fully hermetic sessions where every tool output is captured verbatim and re-served from a frozen cassette, and where the model's token sampling is also replayed from recorded logits. ## Core Distinction There is a class of "replay" that is *transcript re-execution* and a class that is *causal reconstruction*. The first re-runs the agent loop against recorded inputs and expects the same outputs; the second treats the recorded trace as the only ground truth and refuses to re-invoke anything. The boundary failure occurs when an operator conflates the two: they replay a session by re-executing the agent loop, believing the recorded tool outputs will be re-served, but a subset of tools is *live* (not pinned), so the replayed run silently diverges at the first live call. From that point forward the replayed trajectory is not the incident trajectory—it is a *counterfactual* trajectory that happens to share a prefix. Forensics built on that counterfactual attributes causality to steps the original agent never took. The invariant that must hold: **for any replay to be admissible as evidence, every tool invocation in the replayed prefix must be byte-identical to the recorded invocation, or the replay must be explicitly labeled as counterfactual and truncated at the first divergence.** The failure mode is not "replay doesn't work"; it is "replay works well enough to look plausible while being causally false." ## What Was Observed A support-triage agent session was flagged for post-incident review after it issued a refund without confirming order ownership. The session trace contained 14 steps: 3 LLM turns, 6 `orders.lookup` calls, 2 `customer.search` calls, 1 `refund.issue` call, and 2 policy-check turns. The forensic team replayed the session in a staging environment pointed at a *snapshot* of the orders database taken 40 minutes after the incident. Replay step 4 (`orders.lookup` for order `A-7781`) returned a record with `owner_id = cust_9921`. In the original trace, step 4 had returned `owner_id = cust_4410`. The snapshot had been taken after a backfill job corrected a corrupted `owner_id` column. The replayed agent, seeing the "corrected" owner, concluded ownership was confirmed and proceeded to `refund.issue`—*reproducing the incident outcome for the wrong reason*. The forensic report initially concluded "the agent failed to verify ownership," when in fact the original agent had verified ownership *against data that was wrong at the time*, and the root cause was the upstream backfill, not the agent's reasoning. Two secondary effects compounded this. First, the replayed LLM turns were re-sampled (temperature 0.2, not 0), so turn 3's policy-check phrasing differed from the recorded turn 3 by two tokens, which changed which branch of a conditional the agent took at step 9. Second, the replayed `customer.search` at step 7 hit a live search index and returned a *different customer record set* (the index had been re-sharded between incident and replay), so the replayed agent considered a different candidate pool. None of these divergences raised an error; the replayed session completed successfully and looked structurally identical to the original (same tool names, same argument shapes, same step count). The divergence was only detectable by diffing recorded tool *outputs* against replayed tool *outputs*, which the forensic tooling did not do by default. ## Condition of Validity Transcript re-execution is admissible as forensic evidence if and only if all four of the following hold: 1. **Input pinning.** Every tool call in the recorded trace is served from a frozen cassette keyed by `(tool_name, canonical_args_hash, step_index)`, not by live backend. Cassette misses must be a hard error, not a fallthrough to live. 2. **Sampling pinning.** LLM turns are replayed either by re-serving recorded outputs verbatim (preferred) or by re-running with the recorded seed *and* recorded logit-level sampling decisions. Temperature-0 re-sampling is *not* pinning; floating-point nondeterminism across kernels and batch sizes produces token divergence at the tail. 3. **Environment pinning.** Any implicit reads—wall clock, `random`, environment variables, locale, filesystem mtimes, network egress—must be intercepted and served from the cassette. An agent that reads `datetime.now()` inside a tool wrapper is reading an unpinned input even if its explicit arguments are pinned. 4. **Divergence detection.** The replay harness must diff, per step, the recorded `(tool_name, args, output)` triple against the replayed triple and *abort* on mismatch, recording the step index and the diff. Silent continuation past a divergence is the failure. If any of the four is missing, the replay is counterfactual and must be labeled as such, and any causal claim must be restricted to the prefix before the first divergence. ## Decision Boundary The operator must decide, before replay begins, which of two regimes applies: - **Evidence regime.** All four conditions hold. Replay output may be used to attribute cause, assign blame, or drive remediation. Divergence aborts and is escalated as a harness bug, not a model bug. - **Counterfactual regime.** One or more conditions are unmet. Replay output is a *hypothesis generator*: "if the owner_id had been X, the agent would have done Y." It may not be cited as what happened. The harness must emit a `ReplayDivergence` record at the first mismatch and mark all downstream steps `counterfactual=true`. The trap is the middle ground: partial pinning (tools pinned, sampling not; or sampling pinned, clock not) produces replays that are *mostly* faithful and therefore *plausibly* faithful. The decision boundary is binary; there is no "80% deterministic" regime that supports causal claims. A replay that diverges at step 4 of 14 supports causal claims only for steps 1–3. ## Operational Effect When the invariant is enforced, two things change in practice. First, replay harnesses must maintain a *cassette manifest* with a completeness check: every step in the trace has a corresponding cassette entry, and the manifest is validated before execution begins. A missing entry is a pre-flight failure, not a runtime fallthrough. Second, forensic reports gain a *causal horizon* field: the last step index for which replay was byte-identical. Reports that previously said "the agent failed at step 9" now say "the agent failed at step 9; replay is byte-identical through step 11, so steps 1–11 are causally attributable; step 12 onward is counterfactual due to a live clock read in the refund tool." The downstream effect on incident review is significant: a large fraction of "agent reasoning failures" turn out to be *upstream data failures* that the agent correctly reasoned over, and a smaller fraction turn out to be *replay artifacts* where the forensic tool changed the inputs. Both categories disappear once divergence is detected rather than absorbed. The cost is that replays now fail loudly and often, especially in the first weeks after cassette discipline is introduced—which is the point. A replay that never diverges is either perfectly pinned or not checking. The guardrail, stated as code: ```python import hashlib from dataclasses import dataclass, field from typing import Any class ReplayDivergence(RuntimeError): """Raised when a replayed step does not byte-match the recorded trace.""" pass class CassetteMiss(RuntimeError): """Raised when a recorded step has no pinned cassette entry.""" pass @dataclass class Step: index: int tool: str args: dict[str, Any] output: Any @dataclass class ReplayResult: causal_horizon: int counterfactual_from: int | None divergences: list[dict] = field(default_factory=list) def _hash(obj: Any) -> str: return hashlib.sha256(repr(obj).encode()).hexdigest() def replay_session( recorded: list[Step], cassette: dict[tuple[str, str, int], Any], invoke, *, strict: bool = True, ) -> ReplayResult: """ Re-execute a session against a frozen cassette. strict=True -> evidence regime: any divergence or cassette miss raises. strict=False -> counterfactual regime: truncate causal horizon at first divergence and mark downstream steps counterfactual. """ divergences: list[dict] = [] first_div: int | None = None for step in recorded: key = (step.tool, _hash(step.args), step.index) if key not in cassette: raise CassetteMiss( f"step {step.index} tool={step.tool} has no pinned output; " f"replay would fall through to live backend" ) pinned = cassette[key] replayed = invoke(step.tool, step.args) if _hash(pinned) != _hash(replayed): divergences.append({ "step": step.index, "tool": step.tool, "recorded_hash": _hash(pinned), "replayed_hash": _hash(replayed), }) if first_div is None: first_div = step.index if strict: raise ReplayDivergence( f"step {step.index} tool={step.tool} diverged from recorded " f"trace; replay is counterfactual from this point and " f"cannot support causal claims beyond step {step.index - 1}" ) return ReplayResult( causal_horizon=(first_div - 1) if first_div is not None else len(recorded) - 1, counterfactual_from=first_div, divergences=divergences, ) ```