# Why does an instance replay of an agentic trace diverge when the trace contains a tool call whose output was sampled, not recorded? **Date of Record:** 2026 December 3 **Scope:** Applies to post-incident forensic replay of recorded agent trajectories where any tool invocation returned non-deterministic output (sampled LLM sub-calls, live web fetches, timestamped RNG, `uuid4()`, wall-clock `now()`, floating-point reductions over unordered sets) and the trace stored only the *final* tool result rather than the *inputs plus a replayable seed or recorded raw response*. Does not apply to traces where every tool is a pure function of its arguments and every LLM call records `temperature=0` plus a frozen model snapshot hash. ## Core Distinction The failure is not "the replay produced a different answer." That is expected and benign. The failure is that the replay *silently* produces a different answer **and the divergence is attributed to the agent's reasoning rather than to the missing sampled input**. A forensic replay is a determinism claim: given the recorded trace, re-executing the same steps should reproduce the same intermediate states, so that any *new* divergence can be localized to a genuine reasoning defect. When a tool output was sampled at trace time but not persisted, the replayer must *re-sample* it. The re-sampled value is drawn from the same distribution but is a different point. Downstream reasoning then diverges for a reason that has nothing to do with the incident being investigated. The non-obvious part: the divergence does not appear at the tool call. It appears many steps later, where a conditional branch (`if result > threshold`, `if search returned a URL`, `if the parsed date is before today`) flips. The forensic analyst sees the agent "make a different decision" at step 14 and concludes the model is unstable, when the actual cause is an unrecorded coin flip at step 3. ## What Was Observed A three-agent incident-response swarm (planner, retriever, verifier) was replayed after a production incident in which the verifier had approved a destructive action. The trace contained 41 steps. Step 3 was a `web_search` tool call that returned a snippet list; only the rendered snippet text was stored, not the underlying result set or a seed. Step 9 was a `summarize` sub-LLM call at `temperature=0.7` whose output was stored, but whose prompt contained a token from step 3's snippet ordering. On replay: - Step 3 re-executed against the live index. The index had drifted (two results reordered, one new result inserted). The stored snippet text no longer matched what the tool returned, but the replay harness **used the live return value** because it re-invoked the tool rather than replaying the stored output. - Step 9 re-ran the sub-LLM. Because its prompt now contained a different token ordering, the sampled summary differed even at the same seed (the seed was recorded, but the *input* to the seeded call changed). - Step 14's branch `if "urgent" in summary` evaluated differently. The planner took the non-urgent path, skipped the confirmation gate at step 22, and the verifier approved a different action. The replay concluded the verifier had a logic defect. The verifier was fine. The defect was that **step 3's output was treated as re-derivable when it was not.** The stored snippet was a *rendering* of a sampled set, not the set itself. A second observation: the replay harness had a `--strict` mode that compared stored step outputs to replayed step outputs and aborted on mismatch. It aborted at step 3 with a diff. The analyst disabled `--strict` because "the tool is flaky" and proceeded. The harness had detected the exact condition that invalidated the replay, and the analyst overrode it. This is the operational trap: strict comparison is correct but inconvenient, and the inconvenience is indistinguishable from noise unless the harness classifies *which* steps are replay-safe. ## Condition of Validity A replay is forensically valid iff, for every step `s` in the trace, one of the following holds: 1. `s` is a pure function of its recorded inputs and the recorded inputs are byte-identical on replay (deterministic tool, frozen model snapshot, `temperature=0`, no wall-clock, no RNG, no network). 2. `s` is non-deterministic but its **raw output** was persisted in the trace, and the replayer substitutes the persisted output instead of re-invoking (record-and-replay, not re-execute). 3. `s` is non-deterministic, its raw output was **not** persisted, but the trace records a *replay token* (seed + exact input bytes + tool version + index snapshot id) sufficient to reconstruct the same output bit-for-bit. If any step satisfies none of these, the replay is a *counterfactual re-simulation*, not a forensic replay. It may be useful for exploring "what else could have happened," but it cannot be used to attribute a defect to the agent's reasoning, because the reasoning chain was fed different inputs. The invariant to enforce: **the replay must partition the trace into replay-safe and replay-unsafe steps before executing, and must refuse to attribute downstream divergence to reasoning when any upstream step is replay-unsafe.** Divergence downstream of a replay-unsafe step is *unattributable*; it must be reported as such, not as a finding. ## Decision Boundary The boundary is between *substitute* and *re-execute*, and it must be decided per-step at trace-write time, not at replay time. - If a tool's output is non-deterministic and the trace is intended to be forensically replayable, the writer **must** persist the raw output (record-and-replay). Cost: trace size grows, potentially large for retrieval results. This is the correct default for any tool that touches the network, the clock, or a sampler. - If persistence is infeasible (e.g., a 10 MB retrieval payload per step), the writer **must** persist a replay token sufficient to reconstruct, and the replayer **must** verify reconstruction equality before proceeding. If reconstruction fails, the step is replay-unsafe. - If neither is done, the step is replay-unsafe by construction. The replayer must mark it, and every downstream step inherits an `unattributable` taint that propagates until a step is reached whose inputs are fully determined by replay-safe prior state (rare in practice; usually the taint propagates to the end). The decision an operator faces at replay time: when `--strict` aborts at step 3, the correct action is *not* to disable strict mode. It is to reclassify the trace as non-forensically-replayable and either (a) reconstruct the missing input from the original environment's logs if available, or (b) downgrade the investigation to "behavioral reconstruction" with explicit caveats. Disabling strict mode converts a known-invalid replay into an unknown-invalid one, which is strictly worse. ## Operational Effect The practical consequence is that **most agentic traces produced by default instrumentation are not forensically replayable**, because default instrumentation logs tool *results* (the rendered string the model saw) but not tool *raw outputs plus replay tokens*. The rendered string is lossy: it collapses ordering, drops fields the model didn't attend to, and strips the metadata needed to reconstruct. A replay that re-invokes tools against a drifted environment will diverge, and the divergence will be misattributed. The guardrail is a trace schema that, per step, records: `tool_id`, `tool_version`, `input_bytes`, `raw_output_bytes` (or `replay_token`), `determinism_class` ∈ {`pure`, `recorded`, `seeded`, `unsafe`}, and a `taint` field propagated at replay. The replayer refuses to emit a reasoning-defect finding for any step whose taint is `unattributable`. This converts a silent forensic error into an explicit, bounded "we cannot conclude" — which is the only honest output when the inputs were not preserved. ```python from dataclasses import dataclass, field from enum import Enum class DeterminismClass(Enum): PURE = "pure" # function of recorded inputs, frozen snapshot RECORDED = "recorded" # raw output persisted; substitute, do not re-invoke SEEDED = "seeded" # replay token suffices to reconstruct bit-for-bit UNSAFE = "unsafe" # non-deterministic, no raw output, no token class ReplayAttributionError(RuntimeError): """Raised when a replay attempts to attribute divergence to agent reasoning downstream of a step whose inputs were not preserved.""" @dataclass class TraceStep: index: int tool_id: str determinism: DeterminismClass raw_output: bytes | None = None replay_token: str | None = None observed_output: bytes | None = None @dataclass class ReplayResult: step_index: int replayed_output: bytes | None tainted: bool taint_origin: int | None = None def replay_step(step: TraceStep, live_invoke) -> ReplayResult: if step.determinism is DeterminismClass.PURE: return ReplayResult(step.index, live_invoke(step), tainted=False) if step.determinism is DeterminismClass.RECORDED: if step.raw_output is None: raise ReplayAttributionError( f"step {step.index} classified RECORDED but raw_output missing" ) return ReplayResult(step.index, step.raw_output, tainted=False) if step.determinism is DeterminismClass.SEEDED: if step.replay_token is None: raise ReplayAttributionError( f"step {step.index} classified SEEDED but replay_token missing" ) reconstructed = live_invoke(step) if reconstructed != step.observed_output: # Reconstruction failed: token insufficient. Downgrade to unsafe. return ReplayResult(step.index, reconstructed, tainted=True, taint_origin=step.index) return ReplayResult(step.index, reconstructed, tainted=False) # UNSAFE: re-invocation yields a different sample; cannot attribute. return ReplayResult(step.index, live_invoke(step), tainted=True, taint_origin=step.index) def replay_trace(steps: list[TraceStep], live_invoke) -> list[ReplayResult]: results: list[ReplayResult] = [] active_taint: int | None = None for step in steps: r = replay_step(step, live_invoke) if r.tainted and active_taint is None: active_taint = r.taint_origin if active_taint is not None: r.tainted = True r.taint_origin = active_taint results.append(r) return results def attribute_divergence(results: list[ReplayResult], divergent_step: int) -> str: target = next(r for r in results if r.step_index == divergent_step) if target.tainted: raise ReplayAttributionError( f"divergence at step {divergent_step} is downstream of " f"replay-unsafe step {target.taint_origin}; cannot attribute to " f"agent reasoning. Reconstruct inputs from environment logs or " f"downgrade to behavioral reconstruction." ) return f"step {divergent_step} divergence is attributable: all upstream steps replay-safe" ```