# What structural signals indicate replay divergence in agentic forensic reconstruction: the non-idempotent tool-call shadow **Date of Record:** 2026 November 30 **Scope:** Applies to post-incident reconstruction of agent runs where a recorded trace (prompts, tool invocations, tool results, model outputs, and any state snapshots) is re-executed to attribute a failure to a specific step. Does not apply to live debugging, to single-turn stateless inference, or to traces whose tool layer is provably pure and side-effect-free. ## Core Distinction The forensic assumption behind replay is that a recorded trace is a *sufficient* description of the run: re-executing the same prompt sequence against the same model and tool endpoints reproduces the same decision path, so any divergence is attributable to a real defect. This conflates two different objects. A *trace* is a log of what the agent observed. A *replay* is a reconstruction of what the agent *would have* observed. The gap between them is not noise—it is the set of hidden inputs the trace never captured. The non-obvious boundary is this: replay fidelity is not determined by whether the model is deterministic. It is determined by whether every tool call in the trace is *replay-idempotent*—that is, whether re-invoking it yields the same result the original invocation returned. Most agentic tool surfaces are not idempotent in this sense, and the most dangerous case is not an obviously mutating tool (a `write_file` or `send_email`) but a *read* tool whose output depends on ambient state that changed between the incident and the replay: a clock, a database row, a search index, a remote API's current data, or a filesystem the agent itself mutated earlier in the same run. These are the "shadow" inputs. They are invisible in the trace because the trace only records the *result*, not the *inputs that produced it*. This distinction matters operationally because a replayed trace that diverges is routinely misread as evidence of nondeterministic model behavior ("the model made a different choice"), when in fact the model received a different world. The forensic conclusion inverts: the divergence is not a model defect but a *replay artifact*, and the real incident is masked. ## What Was Observed A multi-step agent was tasked with reconciling a set of records across two systems. The trace showed the agent: (1) calling `list_pending()` to enumerate work items, (2) calling `fetch_record(id)` for each, (3) calling `reconcile(a, b)` to write a verdict, and (4) emitting a summary. The incident: the agent reported "all records reconciled" while three records remained in `pending` state. Replay was executed to reconstruct the decision path. The replayed run diverged at step 2: `fetch_record` returned a record that the original run had not seen (it had been created after the incident by a downstream job), and the replayed agent then called `reconcile` on a pair that never existed in the original run. The replay trace showed a *different* set of reconciliation calls than the original, and a naive analyst concluded the model was unstable. The actual structural signal was in the *shape* of the divergence, not its content: - In the original trace, `list_pending()` returned N items, but only N−3 `fetch_record` calls followed. The agent had trusted the enumeration result and processed a stale view: between the `list_pending` call and the per-item fetches, three items had been claimed by a concurrent worker. The agent's "all reconciled" summary was a *stale-read* error, not a reasoning error. - In the replay, `list_pending()` returned N items again (the concurrent worker's claims had since been released), and all N were fetched. The replay was *more correct* than the original run, which is exactly why it diverged. The replay divergence was therefore a signal of *ambient state mutation between incident and replay*, not of model nondeterminism. The forensic invariant that failed was: **a trace is only replayable to the extent that every tool result is a pure function of inputs recorded in the trace.** Here, `list_pending()`'s result depended on concurrent mutations that were never recorded. A second, subtler observation: the original trace *did* contain the evidence of the bug—the count mismatch between enumeration and fetch—but only if the analyst compared the number of enumerated items against the number of subsequent fetches. The trace format recorded each call as an independent event with no cross-call invariant. The structural signal was a *cardinality relationship across events*, which the log did not expose as a first-class field. ## Condition of Validity The replay-divergence-as-signal interpretation is valid only under the following conditions, and fails outside them: 1. **The trace records tool *results*, not tool *inputs*, for non-pure tools.** If the trace records the full argument set and the tool is pure, replay is faithful and divergence *does* indicate model nondeterminism. The signal is only diagnostic when the tool surface is impure and the trace is result-only. 2. **The divergence is localized to a tool call, not to a model generation.** If the model emits a different token sequence given *identical* recorded context, that is genuine sampling nondeterminism (temperature, seed, or provider version drift). The shadow-input signal requires that the divergence first appears at a tool boundary. 3. **The ambient state delta is reconstructable or at least bounded.** If the analyst cannot determine *what* changed between incident and replay, the divergence is uninterpretable—it could be shadow input or model drift. The signal requires that the changed state be identifiable (e.g., a record created after the incident timestamp). 4. **The trace includes timestamps with sufficient resolution to order events against external mutations.** Without incident-time timestamps, the analyst cannot distinguish "the agent saw a stale view" from "the agent saw a fresh view and reasoned wrongly." Outside these conditions—particularly condition 1—the replay divergence is not a reliable forensic signal and must not be used to attribute fault. ## Decision Boundary The operational decision is: **when a replay diverges, do you attribute it to the model or to the trace?** The boundary is crossed by a single check, performed before any replay is run: for each tool call in the trace, classify the tool as *replay-pure* (result is a function of recorded arguments only), *replay-impure-read* (result depends on ambient state not in the trace), or *replay-impure-write* (invocation mutates state). The decision rule: - If divergence first appears at a `replay-pure` tool call, attribute to model nondeterminism and investigate sampling parameters or provider version drift. - If divergence first appears at a `replay-impure-read` call, attribute to shadow input. The replay is *not* a faithful reconstruction; the forensic question becomes "what ambient state changed," not "why did the model behave differently." - If the trace contains any `replay-impure-write` call, replay is **unsafe to execute against live endpoints** and must be run against a snapshot or a mock that replays recorded results. Executing a write during replay can itself corrupt the state you are trying to reconstruct. The boundary is sharp: a single unclassified impure tool in the trace invalidates the entire replay's attribution power, regardless of how many downstream steps match. Partial fidelity is not fidelity. ## Operational Effect The practical consequence is that forensic replay must be *gated on a purity audit of the trace's tool surface*, not run unconditionally. The gate produces three artifacts: 1. A **purity classification** per tool call, derived from the tool schema and the trace's recorded arguments. 2. A **cardinality check** across enumeration-then-fetch patterns, which surfaces stale-read bugs even when replay is not run (the original trace's count mismatch was visible without replay). 3. A **shadow-input ledger**: for each impure-read call, the ambient state that the result depended on, reconstructed from incident-time snapshots where available. When the gate fails—an unclassified impure tool, or an impure-read whose ambient state cannot be reconstructed—the replay must be *refused*, not run with a caveat. A replay with unmodeled shadow inputs produces a divergence that looks like evidence and is not. The correct output is a refusal with the specific unclassified call identified, so the analyst knows the reconstruction is bounded by that call. The following guard implements the gate: it refuses replay when a trace contains an unclassified tool call or an impure-read whose shadow input is unrecoverable, and it raises rather than proceeding. ```python from dataclasses import dataclass from enum import Enum from typing import Optional class ToolPurity(Enum): REPLAY_PURE = "replay_pure" IMPURE_READ = "impure_read" IMPURE_WRITE = "impure_write" UNCLASSIFIED = "unclassified" class ReplayDivergenceError(RuntimeError): """Raised when a trace cannot be faithfully replayed for forensic attribution.""" @dataclass class ToolCall: name: str purity: ToolPurity shadow_input_recoverable: bool = True # only meaningful for IMPURE_READ @dataclass class Trace: calls: list[ToolCall] incident_timestamp_ns: int def audit_replay_safety(trace: Trace) -> None: """Gate forensic replay on tool-surface purity. Raises ReplayDivergenceError if the trace cannot support faithful replay. """ unclassified = [c.name for c in trace.calls if c.purity is ToolPurity.UNCLASSIFIED] if unclassified: raise ReplayDivergenceError( f"trace contains unclassified tool calls {unclassified}; " f"purity must be established before replay or divergence is unattributable" ) writes = [c.name for c in trace.calls if c.purity is ToolPurity.IMPURE_WRITE] if writes: raise ReplayDivergenceError( f"trace contains impure-write calls {writes}; replay against live " f"endpoints would mutate the state under reconstruction" ) unrecoverable = [ c.name for c in trace.calls if c.purity is ToolPurity.IMPURE_READ and not c.shadow_input_recoverable ] if unrecoverable: raise ReplayDivergenceError( f"impure-read calls {unrecoverable} have unrecoverable shadow inputs; " f"any divergence is a replay artifact, not a model defect" ) def classify_divergence(trace: Trace, first_divergent_call: str) -> str: """Attribute a divergence to model drift or shadow input, or refuse.""" audit_replay_safety(trace) for call in trace.calls: if call.name == first_divergent_call: if call.purity is ToolPurity.REPLAY_PURE: return "MODEL_NONDETERMINISM" return "SHADOW_INPUT" raise ReplayDivergenceError( f"divergent call {first_divergent_call!r} not present in trace; " f"replay is not reconstructing the recorded run" ) ```