# Which invariants prevent replay divergence when an agent's non-deterministic tool outputs are re-executed for forensic evidence **Date of Record:** 2026 November 28 **Scope:** Applies to forensic replay of stateful agentic sessions where tool calls return non-deterministic values (timestamps, RNG, remote API responses, LLM sampling) and the replay must reproduce the exact evidence chain for Byzantine fault attribution. Does not apply to pure-compute sandboxes with fully hermetic, seeded I/O. ## Core Distinction There are two distinct things an auditor can mean by "replay." *Re-execution replay* runs the agent's action sequence again against live tools and LLMs, hoping to observe the same trajectory. *Evidence replay* re-derives the recorded decision trace from a frozen, content-addressed transcript and verifies that each transition was licensed by the recorded inputs. Forensic observability requires the second; naive implementations ship the first and silently diverge. The boundary failure lives exactly here: an agent that passes its own re-execution replay test is not thereby producing admissible evidence, because re-execution sampling reintroduces the non-determinism the audit was supposed to eliminate. The invariant that matters is not "replay produces the same output" but "every recorded transition is a pure function of a recorded, hash-pinned input set." ## What Was Observed A four-agent research swarm (planner, retriever, synthesizer, auditor) ran a 340-step task. The auditor agent flagged a suspected prompt-injection event at step 212: the retriever returned a document whose embedded instructions redirected the synthesizer's tool selection. During incident review, the operator re-executed the session from the checkpoint at step 200 using the same agent code and the same task prompt. The re-execution diverged at step 214: the synthesizer chose a different tool, the injection path was never taken, and the auditor's flag could not be reproduced. The incident was closed as "not reproducible." Three separate mechanisms produced the divergence, and only one was obvious: 1. **Tool-output non-determinism.** The retriever's step-212 result was a live HTTP fetch whose payload had rotated. The recorded transcript stored the *summary* the agent saw, not the raw bytes; the summary was lossy, so re-execution could not reconstruct the exact injected string. 2. **Sampling non-determinism.** The synthesizer's step-214 tool selection was an LLM sample at temperature 0.7. Re-execution drew a different sample from the same distribution and never selected the poisoned tool. 3. **Clock and ID non-determinism.** The auditor's evidence records used `uuid4()` and `datetime.now()` inside the tool wrapper, so even a byte-identical transcript produced a different evidence hash on replay, breaking the tamper-evidence chain. The critical, non-obvious observation: the agent's own self-test ("replay the last 10 steps and assert the final answer matches") *passed*, because the final answer was robust to the divergence. The self-test was measuring output equivalence, not transition provenance. A Byzantine agent could exploit precisely this gap—produce a stable final answer while its internal trajectory is unverifiable, so any accusation of misbehavior at an intermediate step is deniable. ## Condition of Validity Evidence replay is valid only under a conjunction of invariants; violating any one collapses the audit to re-execution replay: - **Input closure.** Every tool call's *effective input*—the exact bytes the model conditioned on—is recorded and content-addressed (e.g., SHA-256 of the raw payload, not a summary). The model's view must be a deterministic projection of the recorded bytes. - **Sampling pinning.** Any LLM call whose output affects control flow records the sampler seed, temperature, top-p, model version hash, and the full token logprob trace sufficient to reconstruct the choice. Replay verifies the recorded choice is *consistent with* the recorded distribution and seed rather than re-drawing. - **Effect quarantine.** Side-effecting tools (writes, sends, payments) are recorded as *intent + committed receipt*, and replay must never re-invoke them. The receipt is the evidence; the tool is not re-run. - **Monotonic evidence log.** The evidence hash chain uses a logical sequence number, not wall-clock time or random UUIDs, so replay reproduces the chain bit-for-bit. - **Transition licensing.** Each step's state transition is checked as `next_state == f(prev_state, recorded_observation, recorded_decision)`, where `f` is the deterministic agent step function with all non-determinism lifted into the recorded inputs. If the sampler seed or the raw tool bytes are absent, the session is *replayable for output* but *not admissible for attribution*—and the two must be labeled differently in the evidence store. ## Decision Boundary The operative question is not "did replay reproduce the outcome?" but "can every transition be re-derived without consulting any live source?" The boundary: - If all five invariants hold → the transcript is a *witness*: a Byzantine agent's intermediate misbehavior is provable because the transition is pinned to recorded inputs, and any deviation from the recorded trajectory is itself evidence of tampering. - If input closure or sampling pinning fails → the transcript is a *testimony*: it records what the agent claims happened, and a divergent re-execution cannot distinguish "the agent lied" from "the world changed." Attribution is unsound; the correct action is to mark the session `UNVERIFIABLE`, not `PASS`. - If effect quarantine fails (replay re-invokes side effects) → replay is not merely useless but *harmful*: it can duplicate payments or re-send injected instructions, and the audit itself becomes an incident. The trap is treating the middle case as the first. A session that reproduces its final answer under re-execution feels verified; it is only testimony. The guardrail is a hard gate: the replay engine must refuse to emit a `VERIFIED` verdict unless it can recompute the evidence hash chain from recorded bytes alone, with zero live calls, and must raise on any attempt to fall back to re-execution. ## Operational Effect Enforcing these invariants changes the agent runtime, not just the audit tool. The tool wrapper must capture raw bytes before summarization and hash them into the transcript; the LLM client must log seeds and logprob traces; side-effecting tools must be split into an intent record and a committed receipt with the receipt written *before* the effect is acknowledged. The evidence chain must use logical clocks. The payoff is that a Byzantine agent cannot hide intermediate misbehavior behind a stable outcome: the auditor replays the transition function in pure computation, and any mismatch between recorded and re-derived state is a signed, attributable discrepancy. The cost is storage (raw tool payloads, logprob traces) and the discipline of never re-drawing a sample during audit. The failure mode this prevents is the one that closed the incident above: a real injection dismissed as "not reproducible" because the audit confused re-execution with evidence. ```python import hashlib from dataclasses import dataclass class ReplayDivergenceError(RuntimeError): """Raised when evidence replay cannot re-derive a transition from recorded inputs alone.""" pass @dataclass(frozen=True) class RecordedStep: seq: int prev_state_hash: str observation_raw: bytes # exact bytes the model conditioned on sampler_seed: int | None # None => sampling not pinned decision_token_id: int next_state_hash: str def verify_evidence_chain(steps: list[RecordedStep], step_fn) -> str: """Pure-computation replay: no live tools, no re-sampling. Returns final state hash.""" if not steps: raise ReplayDivergenceError("empty transcript: nothing to attest") prev_hash = steps[0].prev_state_hash for step in steps: if step.prev_state_hash != prev_hash: raise ReplayDivergenceError( f"seq {step.seq}: chain break, prev hash mismatch " f"({step.prev_state_hash[:12]} != {prev_hash[:12]})" ) if step.sampler_seed is None: raise ReplayDivergenceError( f"seq {step.seq}: sampler seed unpinned; transcript is testimony, " f"not a witness, and attribution is unsound" ) obs_hash = hashlib.sha256(step.observation_raw).hexdigest() derived = step_fn(prev_hash, obs_hash, step.sampler_seed, step.decision_token_id) if derived != step.next_state_hash: raise ReplayDivergenceError( f"seq {step.seq}: transition not licensed by recorded inputs; " f"possible Byzantine tampering" ) prev_hash = derived return prev_hash ```