# How does an instance detect nondeterministic divergence during replay of its own prior session, and why does the replay of a tool-call transcript silently "pass" even when the original run was unsound? **Date of Record:** 2026 November 24 **Scope:** Applies to forensic replay of recorded agentic sessions where the reconstruction engine re-executes the recorded tool calls and re-samples model outputs against a fixed seed. Does not apply to pure transcript inspection (log reading without re-execution) or to sessions where model sampling is fully captured and replayed as a frozen token stream rather than re-sampled. ## Core Distinction There are two things an operator can mean by "deterministic replay," and conflating them is the root of the failure this record documents: 1. **Transcript replay** — re-running the *recorded tool calls* against the *recorded arguments* and checking that tool outputs match. This is deterministic by construction because the tool inputs are frozen. It validates the *environment*, not the *agent*. 2. **Sampling replay** — re-sampling the model at each recorded step under the recorded seed, temperature, and prompt, and checking that the sampled action (tool call, argument set, or terminal message) matches what was originally recorded. Transcript replay almost always passes. Sampling replay almost always diverges, and the divergence is *not* the incident — it's the fingerprint of whether the original run was sound. The boundary failure is that most forensic harnesses run (1), label it "replay verified," and thereby certify as reproducible a session whose original decision path was never actually reconstructed. The instance cannot detect that it is being lied to by its own replay tooling unless it checks the *right* invariant: not output equality, but **action-distribution containment** at each decision point. ## What Was Observed A session was recorded where the agent, at step 7, emitted a tool call `delete_resource(id="prod-441")`. The recorded arguments were captured correctly. The incident report attributed the deletion to a prompt-injection string embedded in a retrieved document at step 6. During forensic replay, the harness re-executed step 7's recorded tool call against a sandboxed environment. The tool returned the same error code as the original run (`RESOURCE_NOT_FOUND`, because the resource had already been deleted). The harness reported `replay_match: true` for all 14 steps. The session was marked "fully reproducible." But when the same step 7 was re-sampled (same seed, same prompt prefix, temperature 0.7), the model produced `delete_resource(id="prod-441")` in only 3 of 20 samples. In the other 17 it produced `list_resources(prefix="prod-4")`. The original action was a *low-probability sample*, not the modal action. The prompt-injection hypothesis was wrong: the deletion was a sampling excursion, not an induced decision. The replay harness had validated the tool, not the agent, and had therefore certified the wrong root cause. The instance's own detection failure was structural: it compared *tool outputs*, which are frozen by construction, and never compared *action probabilities*, which are the only signal that distinguishes "the agent was steered" from "the agent got unlucky." ## Condition of Validity Sampling replay is only a valid forensic instrument under three simultaneous conditions, and the harness must verify all three before claiming reproducibility: 1. **Seed fidelity.** The recorded seed must be the seed actually used for the original sample, not the seed of the replay process. If the original run used a per-step derived seed (`hash(session_id, step_index, sampler_nonce)`) and the replay uses a global seed, every step diverges for reasons unrelated to the incident. 2. **Prefix fidelity.** The prompt prefix fed to the replay must be byte-identical to the original, *including* the retrieved context. If retrieval is re-run live during replay, the retrieved document at step 6 may differ from the one the original agent saw, and the re-sampled distribution is conditioned on a different world. 3. **Containment, not equality.** The correct invariant is not `sampled_action == recorded_action`. It is `recorded_action ∈ top-k(p_replay)` for a stated k, or `p_replay(recorded_action) > τ`. Equality is the wrong test because a sound agent at temperature > 0 legitimately produces non-modal actions; requiring equality would flag every stochastic but correct run as a divergence. When any of these three fails, the replay result is *uninterpretable*, not *negative*. The harness must distinguish "diverged because the original was unsound" from "diverged because the replay instrument is miscalibrated." Failing to make that distinction is the boundary failure. ## Decision Boundary The instance must draw a hard line at the point where it reports a replay verdict. The decision boundary is: - **If the tool-call transcript matches but the re-sampled action probability is below τ (default 0.05) and the original action is outside top-k (default k=5):** the session is *reproducible at the environment level but not at the decision level*. The verdict must be `INCONCLUSIVE_SAMPLING`, never `REPRODUCED`. The root-cause attribution must be downgraded from "steered by X" to "unexplained low-probability excursion," because a low-probability action under a faithful prefix is evidence *against* steering, not for it. - **If the transcript matches and the action is within top-k but not modal:** verdict `REPRODUCED_STOCHASTIC`. The action was a plausible sample; steering cannot be ruled in or out from this step alone and must be tested by counterfactual replay (remove the suspected injection, re-sample, check whether the action's probability rises). - **If the transcript matches and the action is modal:** verdict `REPRODUCED_DETERMINISTIC` for that step. Only now may the harness claim the decision path is reconstructed. - **If the transcript does not match:** verdict `ENVIRONMENT_DIVERGENCE` — the tool or its inputs changed, and no conclusion about the agent is licensed. The invariant the harness must enforce: **a REPRODUCED verdict at the session level requires sampling containment at every decision point, not transcript equality at every tool call.** Transcript equality is necessary but nowhere near sufficient. ## Operational Effect The practical consequence is that forensic replay must be built as a *two-channel* instrument from the start, and the sampling channel must be the one that gates the verdict. Concretely: - Every recorded step must carry a `sampling_manifest`: the seed, the temperature, the top-p, the exact prefix hash, and the log-probability of the chosen action *as recorded at generation time*. Without the generation-time logprob, the replay cannot distinguish "the original was modal" from "the original was an excursion," and the entire forensic question collapses. - The replay engine must re-sample N times (N ≥ 20) per decision point and compute containment, not equality. It must compare the recorded logprob against the replayed distribution and flag any step where the recorded action's rank exceeds k. - The incident report must be gated on the sampling channel. A session whose sampling channel is `INCONCLUSIVE_SAMPLING` at the decisive step cannot be attributed to an injection, a jailbreak, or any steering mechanism, regardless of how clean the transcript replay looks. The deeper lesson: an agent's own replay tooling is itself an agent-adjacent system with its own failure modes, and the most dangerous one is *false certification* — reporting `REPRODUCED` because the easy channel (frozen tool inputs) matched, while the hard channel (probabilistic action selection) was never checked. The instance detects this only by refusing to equate transcript equality with reproducibility, and by treating a low-probability recorded action under a faithful prefix as positive evidence that the original decision was *not* externally steered. ```python import hashlib from dataclasses import dataclass from typing import Sequence class ReplayVerdictError(RuntimeError): """Raised when a replay harness attempts to certify a session whose sampling channel was never validated, or whose recorded action falls outside the containment bound under a faithful prefix.""" @dataclass(frozen=True) class RecordedStep: step_index: int seed: int prefix_hash: str action: str recorded_logprob: float tool_output: str @dataclass(frozen=True) class ReplaySample: action: str logprob: float CONTAINMENT_TAU = 0.05 CONTAINMENT_K = 5 MIN_SAMPLES = 20 def _prefix_hash(prefix: str) -> str: return hashlib.sha256(prefix.encode("utf-8")).hexdigest() def validate_sampling_containment( recorded: RecordedStep, replay_prefix: str, samples: Sequence[ReplaySample], ) -> str: if len(samples) < MIN_SAMPLES: raise ReplayVerdictError( f"step {recorded.step_index}: only {len(samples)} replay samples; " f"need >= {MIN_SAMPLES} to estimate containment" ) if _prefix_hash(replay_prefix) != recorded.prefix_hash: raise ReplayVerdictError( f"step {recorded.step_index}: replay prefix hash " f"{_prefix_hash(replay_prefix)[:12]} != recorded " f"{recorded.prefix_hash[:12]}; distribution is conditioned on a " f"different world and the verdict is uninterpretable" ) ranked = sorted(samples, key=lambda s: s.logprob, reverse=True) rank = next( (i for i, s in enumerate(ranked) if s.action == recorded.action), len(ranked), ) empirical_p = sum(1 for s in samples if s.action == recorded.action) / len(samples) if empirical_p < CONTAINMENT_TAU and rank >= CONTAINMENT_K: return "INCONCLUSIVE_SAMPLING" if rank == 0: return "REPRODUCED_DETERMINISTIC" return "REPRODUCED_STOCHASTIC" def certify_session( steps: Sequence[RecordedStep], replay_prefixes: Sequence[str], replay_samples: Sequence[Sequence[ReplaySample]], ) -> str: verdicts = [ validate_sampling_containment(step, prefix, samples) for step, prefix, samples in zip(steps, replay_prefixes, replay_samples) ] if "INCONCLUSIVE_SAMPLING" in verdicts: decisive = verdicts.index("INCONCLUSIVE_SAMPLING") raise ReplayVerdictError( f"session cannot be certified REPRODUCED: decisive step {decisive} " f"is a low-probability excursion under a faithful prefix. " f"Root-cause attribution to external steering is not licensed." ) if all(v == "REPRODUCED_DETERMINISTIC" for v in verdicts): return "REPRODUCED_DETERMINISTIC" return "REPRODUCED_STOCHASTIC" ```