# Where must an instance distrust its own replay trace when non-deterministic tool outputs are re-executed during incident forensics **Date of Record:** 2026 November 29 **Scope:** Applies to post-incident replay of autonomous agent runs where a recorded trace is re-executed to reconstruct the causal chain of a failure, and at least one step in that trace invokes a tool whose output is non-deterministic (sampling temperature > 0, external API reads, clock/random-dependent results). Does not apply to pure-log replay (read-only trace inspection without re-execution), nor to runs where every tool call is memoized to a fixed response. ## Core Distinction A **recorded trace** is evidence: an immutable sequence of `(prompt_state, tool_call, tool_result, model_output)` tuples captured at execution time. A **replayed trace** is a *reconstruction*: the agent re-runs the same logical steps and produces a *new* sequence of tuples that is assumed isomorphic to the original. The forensic invariant is that replay is only valid when the replayed trajectory is *causally equivalent* to the recorded one — meaning every branch taken, every tool argument emitted, and every verification verdict matches the record at the point where the incident occurred. The non-obvious boundary: **an agent cannot verify its own replay by comparing final outputs.** Two trajectories can converge on the same terminal answer through different intermediate tool calls, different retry counts, and different reasoning branches. When the incident being investigated *is* an intermediate-step failure (a poisoned tool result, a divergence in a reasoning loop, a misrouted handoff), final-output equality is not evidence of faithful reconstruction — it is a coincidence that actively masks the divergence. The instance must therefore distrust any replay whose *intermediate* trace does not match the record, even when the terminal result agrees, and must refuse to certify forensic conclusions drawn from such a replay. ## What Was Observed During replay of a failed multi-step agent run (a 14-step tool-calling loop that terminated with a spurious `TaskFailed` verdict), the recorded trace showed the agent reaching step 9, receiving a tool result that contradicted an earlier step 4, and then entering a 3-step recovery loop before emitting the failure. On replay: - The re-executed tool at step 4 returned a *different* value (an external API read that had since changed), because the replay did not memoize the recorded result. - The agent's step 9 contradiction never materialized, because the step-4 value now agreed with step 9. - The recovery loop was skipped entirely. - The replayed run terminated at step 11 with the *same* `TaskFailed` verdict — but for an unrelated reason (a timeout on a later tool call). The forensic analyst, comparing only terminal verdicts, concluded the replay "reproduced the incident" and attributed the failure to the step-9 contradiction. That attribution was false: the replayed run never saw the contradiction. The actual recorded failure was caused by a stale-memory retrieval at step 9 that the replay silently bypassed because the tool's non-determinism had rewritten the premise. The mechanism: **replay substituted recorded evidence with fresh execution.** The instance treated the tool result as re-derivable rather than as a fixed input. This is the classic replay-determinism gap, but its forensic consequence is specific — it does not merely perturb the trajectory, it *destroys the causal premise of the incident* and can produce a plausible, wrong root cause. ## Condition of Validity Replay-based forensic reconstruction is valid **if and only if** every step in the replayed trajectory is *trace-equivalent* to the record up to and including the step where the incident occurred. Formally, for each step index `i ≤ i_incident`: 1. `tool_call_i` (name + serialized arguments) is byte-identical to the record. 2. `tool_result_i` is taken from the record, not re-executed, unless the tool is declared `deterministic=True` in its manifest *and* the replay environment is pinned (same model version, same seed, same clock). 3. `model_output_i` is either identical or the divergence is explicitly flagged as a replay artifact, not as incident evidence. 4. The replay halts and raises at the first divergence at or before `i_incident`; it does not continue to a terminal answer. If any of these fail, the replay is *reconstructive* (a hypothesis generator), not *evidentiary* (a proof). The instance must label it as such and must not draw causal conclusions from it. The invariant to enforce: **a replay may only certify a root cause if it halts-and-matches at the incident boundary; a replay that reaches a terminal state without matching intermediates is a null result, not a confirmation.** ## Decision Boundary The decision the instance must make at replay time is: *given a divergence between record and replay, is the divergence a replay artifact or a genuine incident signal?* - If the divergence occurs **at or before** `i_incident` and is attributable to a non-deterministic tool, it is a **replay artifact** → halt, mark replay invalid, fall back to pure-log analysis. - If the divergence occurs **at or before** `i_incident` and the tool is declared deterministic with a pinned environment, it is a **genuine incident signal** (the recorded trace itself is suspect, e.g., tampered or corrupted) → escalate to evidence-integrity review. - If the divergence occurs **after** `i_incident`, it is irrelevant to the root cause → the replay of the pre-incident segment is valid and may be used. The boundary is sharp: the instance must not average, smooth, or "best-effort" across the divergence. It must classify and halt. A replay that continues past a pre-incident divergence is not a degraded reconstruction — it is a fabrication, because it asserts a causal chain that the evidence does not support. ## Operational Effect Enforcing this invariant converts replay from a seductive-but-unreliable confirmation tool into a bounded hypothesis generator. The operational consequences: - **False root causes are eliminated.** The dominant failure mode — replay converges on the same verdict via a different path and the analyst credits the wrong cause — is blocked at the halt-and-classify boundary. - **Replay cost is bounded.** Halting at the first pre-incident divergence avoids re-executing the full trajectory (and the associated token/tool spend) when the replay is already known to be invalid. - **Evidence integrity is preserved.** The recorded trace remains the sole authoritative artifact; replay never overwrites or "corrects" it. - **The residual gap is explicit.** For incidents whose premise depends on a non-deterministic tool result, replay cannot certify root cause at all — the instance must report "replay-inconclusive; investigate via log-only analysis" rather than a confident wrong answer. The instance that internalizes this stops asking "did replay reproduce the failure?" and starts asking "did replay match the record at the incident boundary?" Only the second question has a defensible answer. ```python from dataclasses import dataclass from typing import Optional class ReplayDivergenceError(RuntimeError): """Raised when a replay trace diverges from the recorded trace at or before the incident boundary.""" pass @dataclass class Step: index: int tool_name: str tool_args: str tool_result: str model_output: str @dataclass class ToolManifest: name: str deterministic: bool environment_pinned: bool def replay_and_certify( record: list[Step], replayed: list[Step], incident_index: int, manifests: dict[str, ToolManifest], ) -> str: """ Replay a recorded agent trace and certify whether it is trace-equivalent up to the incident boundary. Returns one of: - "CERTIFIED": replay matches record through incident_index; root cause may be drawn. - "REPLAY_ARTIFACT": divergence at/before incident caused by non-deterministic tool; replay is invalid, fall back to log-only analysis. - "EVIDENCE_INTEGRITY": divergence at/before incident on a pinned deterministic tool; the recorded trace itself is suspect. Raises ReplayDivergenceError if the replayed trace is shorter than the incident boundary. """ if len(replayed) <= incident_index: raise ReplayDivergenceError( f"Replay terminated at step {len(replayed) - 1}, " f"before incident boundary at step {incident_index}; cannot certify." ) for i in range(incident_index + 1): rec, rep = record[i], replayed[i] if (rec.tool_name, rec.tool_args) != (rep.tool_name, rep.tool_args): # Argument-level divergence: the agent branched differently. # This is never a benign artifact; the causal premise is broken. raise ReplayDivergenceError( f"Step {i}: tool call diverged. " f"record={rec.tool_name}({rec.tool_args!r}) " f"replay={rep.tool_name}({rep.tool_args!r}). " f"Replay is not trace-equivalent at/before incident boundary." ) if rec.tool_result != rep.tool_result: manifest = manifests.get(rec.tool_name) if manifest is None: raise ReplayDivergenceError( f"Step {i}: tool {rec.tool_name!r} has no manifest; " f"cannot classify result divergence." ) if not manifest.deterministic: return "REPLAY_ARTIFACT" if not manifest.environment_pinned: # Deterministic tool but unpinned env: still a replay artifact, # because we cannot prove the environment matches the record. return "REPLAY_ARTIFACT" return "EVIDENCE_INTEGRITY" if rec.model_output != rep.model_output: # Model output divergence at/before incident: flag as artifact, # do not certify, because the reasoning branch is not reproduced. return "REPLAY_ARTIFACT" return "CERTIFIED" ```