# When must an instance re-execute a tool call during trace replay, and when must it refuse **Date of Record:** 2026 November 21 **Scope:** Applies to forensic replay of recorded agentic traces where tool calls are re-issued to reconstruct state after an incident. Does not apply to read-only trace inspection, static log analysis, or replay of pure-LLM reasoning steps with no external side effects. ## Core Distinction The forensic replay of an agent trace is not the same operation as re-running the agent. Replay reconstructs *what the agent believed and observed* at each step; re-execution *produces new observations*. These diverge the moment a tool call is non-idempotent or non-deterministic. The boundary condition that breaks most replay harnesses is this: a tool call whose recorded output is *insufficient to reconstruct downstream state* forces the replayer to either re-invoke the tool (risking divergence and side effects) or synthesize a substitute (risking a fabricated causal chain). Neither is safe by default. The invariant that must hold is that **every replayed step is either (a) reproduced from a recorded observation treated as ground truth, or (b) explicitly marked as a divergence point with the reason recorded**. There is no third option that preserves forensic validity. The non-obvious failure: a trace can be *internally consistent* and still be *causally wrong*. If the replayer re-invokes a tool and gets a different-but-plausible output, the reconstructed reasoning chain will look coherent while describing a counterfactual history. The incident report then explains a failure that did not happen. ## What Was Observed During replay of a 47-step agent trace from a retrieval-augmented incident-response agent, the harness re-issued a `search_index` tool call at step 19 because the recorded payload was truncated at the storage boundary (the trace writer capped tool outputs at 8 KiB). The live tool, queried eleven hours after the incident, returned a different top-5 document set — the index had been rebuilt overnight. The replayer accepted the new results, and steps 20–31 (a reasoning chain that cited specific document IDs) proceeded against documents that did not exist at incident time. The reconstructed chain assigned the root cause to a stale-index condition that had not yet occurred. The actual failure — a malformed filter expression that silently returned zero results — was masked because the rebuilt index happened to return non-empty results for the same query. The tell was a checksum mismatch between the recorded document IDs at step 21 and the IDs present in the replayed step 19 output. The harness had been comparing *reasoning text* for consistency, not *observation provenance*. Reasoning text matched because the model, given different-but-topically-similar documents, produced a near-identical narrative. A second observed case: a `send_notification` call at step 33 was re-issued during replay "to verify the side effect occurred." It fired a second notification to the on-call channel, eleven hours late, during a different incident. The replay harness had no classification of which tools were safe to re-invoke. ## Condition of Validity Replay-by-re-execution is valid only when all of the following hold for the specific tool call being replayed: 1. The tool is **declared idempotent** by its own contract, not inferred by the harness. 2. The tool's output is **deterministic given its inputs and a pinned external state version** — and that state version is recorded in the trace and can be pinned at replay time (e.g., a git SHA, an index snapshot ID, a database read-timestamp). 3. The replayed output is **compared byte-for-byte or by stable hash** against the recorded output, and any mismatch aborts the replay segment rather than continuing. If any condition fails, the call must be replayed from the recorded observation, and the harness must assert that the recorded observation is *complete*. Truncated payloads (as in the observed case) violate completeness and must be flagged at trace-write time, not discovered at replay time. A trace with a truncated tool payload is not replayable past that point; it is only *inspectable*. The condition of validity for the whole trace: the replay is valid up to the first step where a non-reproducible observation is required and the recorded observation is incomplete. Beyond that step, the harness may continue only in *hypothetical mode*, with all downstream outputs labeled as constructed rather than observed. ## Decision Boundary The decision boundary is drawn per tool call, not per trace, and it is determined by two recorded facts: the tool's idempotency class and the completeness flag on the recorded payload. - **Idempotent + complete payload + pinned state version:** re-execute, hash-compare, abort on mismatch. - **Idempotent + complete payload + unpinned state:** do not re-execute; use recorded observation; mark state version as unresolvable. - **Non-idempotent (any completeness):** never re-execute; use recorded observation; if incomplete, halt replay at this step. - **Non-deterministic (e.g., sampling tools, live LLM sub-calls):** never re-execute; use recorded observation; record the non-determinism class in the divergence ledger. The trap is treating "the tool usually returns the same thing" as idempotency. Idempotency is a property of the tool's effect on external state, not a statistical property of its output. A search tool is *read-only* but *non-deterministic* across index rebuilds; a notification tool is *deterministic in output* but *non-idempotent in effect*. These require different replay treatments, and a harness that collapses them into one "safe to re-run" bucket will produce both counterfactual reconstructions and duplicate side effects. ## Operational Effect The practical consequence is that trace storage must carry replay metadata at write time: per-call idempotency class, payload completeness flag, and external state version. This is cheap to record and impossible to reconstruct later. A trace written without it is forensically degraded — usable for inspection, not for replay. Second effect: the replay harness must maintain a **divergence ledger** that records every step where recorded and replayed observations differ, with the hash of each. Incident reports generated from replay must cite the ledger and must state the last step at which the reconstruction is causally grounded. Reports that silently continue past a divergence point are worse than no report, because they carry the authority of a trace without its fidelity. Third effect: the reasoning-consistency check is insufficient as a replay validator. The observed case passed text-level consistency while failing provenance. Validation must be on observation hashes and document/entity IDs, not on the natural-language chain. ```python import hashlib from dataclasses import dataclass from enum import Enum class ReplayDivergenceError(RuntimeError): """Raised when a replayed tool call cannot be causally grounded.""" class Idempotency(Enum): IDEMPOTENT = "idempotent" NON_IDEMPOTENT = "non_idempotent" NON_DETERMINISTIC = "non_deterministic" @dataclass(frozen=True) class RecordedCall: step: int tool: str idempotency: Idempotency payload_complete: bool state_version: str | None output_hash: str def replay_call(call: RecordedCall, live_invoke, pinned_state: str | None) -> str: """ Decide whether a recorded tool call may be re-executed during forensic replay. Returns the output hash to use downstream. Raises if replay cannot stay grounded. """ if call.idempotency is Idempotency.NON_IDEMPOTENT: if not call.payload_complete: raise ReplayDivergenceError( f"step {call.step}: non-idempotent tool {call.tool!r} has incomplete " f"recorded payload; replay cannot continue past this step" ) return call.output_hash # trust recorded observation, never re-fire if call.idempotency is Idempotency.NON_DETERMINISTIC: return call.output_hash # recorded observation is the only ground truth # idempotent path if call.state_version is None or pinned_state != call.state_version: # cannot pin external state to incident-time version return call.output_hash fresh = live_invoke(call.tool) fresh_hash = hashlib.sha256(repr(fresh).encode()).hexdigest() if fresh_hash != call.output_hash: raise ReplayDivergenceError( f"step {call.step}: tool {call.tool!r} replayed to {fresh_hash[:12]} " f"but trace recorded {call.output_hash[:12]}; aborting segment" ) return fresh_hash ```