# How should an instance replay a multi-agent trace when the original run consumed non-idempotent tool side effects **Date of Record:** 2026 November 29 **Scope:** Applies to post-incident forensic replay of recorded multi-agent traces where at least one tool call in the original execution produced an externally observable, non-idempotent side effect (write, charge, dispatch, send, delete). Does not apply to pure-read tool graphs or to sandboxed replays against a fully reconstructed side-effect ledger. ## Core Distinction There are two different things people mean by "deterministic replay," and conflating them is the root of the failure. The first is **reasoning replay**: given the recorded message sequence, tool results, and model sampling parameters, can the agent graph re-derive the same decisions? This is achievable to a bounded degree — you fix temperature, seed, and prompt bytes, and you re-run the LLM calls. Divergence here is a *modeling* problem. The second is **effect replay**: does re-executing the trace against live tool endpoints reproduce the same world state? This is *not* achievable in general, because the recorded trace contains a sequence of tool invocations whose original effects already mutated the world. The trace is a log of *effects applied*, not a pure function you can re-apply. The boundary condition is this: **a forensic replay that re-executes tool calls is not a replay — it is a second execution.** Every non-idempotent call in the original trace becomes a fresh mutation on replay. The trace you are trying to explain is now contaminated by the trace you are running to explain it. This is the failure mode: *replay-induced side-effect duplication*, where the forensic harness silently doubles charges, re-sends notifications, or re-appends records, and the resulting trace diverges from the original not because the agents behaved differently but because the world did. ## What Was Observed A three-agent incident-response swarm — planner, executor, auditor — was recorded during a live run. The executor made four tool calls with side effects: `create_ticket`, `charge_account`, `notify_oncall`, `append_audit_log`. The run terminated abnormally (auditor raised a consensus conflict and the orchestrator halted). The trace was serialized with full message bytes, tool arguments, tool *responses*, and timestamps. The forensic harness replayed the trace to reconstruct the divergence point. It re-issued all four tool calls because the harness treated the recorded tool responses as *expected outputs to validate against*, and the natural way to validate an expected output is to re-invoke the tool and compare. Three things happened: 1. `create_ticket` and `charge_account` were non-idempotent. The replay created a second ticket and a second charge. The harness's comparison logic saw the *new* ticket ID differed from the recorded ID and flagged a "tool nondeterminism" anomaly — a false positive. The actual divergence it was hunting (auditor conflict) was buried under four fabricated anomalies. 2. `notify_oncall` fired a second page. The on-call engineer, already handling the first incident, received a duplicate page and treated it as a distinct alert, opening a second incident channel. 3. `append_audit_log` wrote a replay record into the same audit stream the forensic analysis was reading from. The analysis now had a self-referential loop: replay entries appeared as if they were original agent actions, and the auditor-consensus check — which reads the audit log — re-triggered on the replay's own writes. The harness had no concept of "this call was already applied." Its replay model was: recorded trace → re-execute → compare. The recorded trace was treated as a *specification*, when it was actually a *history*. ## Condition of Validity Replay is only valid under one of two regimes, and the harness must know which regime it is in *before* issuing any tool call. **Regime A — Effect-suppressed replay.** All tools are replaced by stubs that return the recorded response bytes without touching the world. This is valid for reasoning replay: the agent graph sees exactly what it saw originally, and any divergence in its decisions is attributable to model nondeterminism, not to environmental change. The invariant is: *no tool invocation with a side-effect class may reach a live endpoint during replay.* Side-effect class must be declared per-tool in the registry, not inferred. **Regime B — Ledger-verified replay.** The harness maintains a side-effect ledger keyed by `(trace_id, call_index)`. Before issuing a call, it checks whether that call index was already applied in the original run. If applied, it returns the recorded response and marks the call *satisfied-by-ledger*. If not applied (the original run halted before this call), it may execute live — but only if the call is idempotent or carries a replay-safe idempotency key derived from `(trace_id, call_index)`. The invariant is: *a side-effect call is executed at most once per trace_id across all replays.* The condition of validity is therefore: **the harness must partition every recorded tool call into effect-classes before replay begins, and must never issue an effectful call outside Regime A or a ledger-checked Regime B.** A trace that mixes regimes without per-call classification is invalid for forensic purposes; any conclusions drawn from it are unsound. ## Decision Boundary The decision boundary is the point where the harness chooses between re-executing and stubbing a call. The naive rule — "re-execute to validate" — is wrong for any call whose side-effect class is `WRITE`, `CHARGE`, `NOTIFY`, `DELETE`, or `DISPATCH`. For those, the correct rule is: **stub and compare response bytes; never re-execute.** If the recorded response is absent (the call failed or timed out in the original run), the replay must *not* attempt the call live to "see what would have happened" — that is a counterfactual, not a replay, and it must be labeled as such and run in an isolated sandbox with a fresh trace_id. There is a second boundary at the auditor-consensus layer. When the auditor's verification re-reads state that the replay itself may have written (audit logs, ticket stores, notification queues), the harness must snapshot that state at trace-start and serve the snapshot to the auditor, not the live store. Otherwise the auditor verifies against a world that includes the replay's own effects — a self-referential verification that will always disagree with the original run and will always be wrong about why. The boundary is crossed the moment the harness issues a live call whose `(trace_id, call_index)` is not in the ledger and whose side-effect class is not `READ`. At that instant the replay is no longer a replay. ## Operational Effect The immediate effect of getting this wrong is duplicate side effects: double charges, double pages, duplicate tickets. The secondary effect is *forensic contamination*: the replay's own writes appear in the audit stream and are indistinguishable from original agent actions unless every replay write is tagged with a `replay_of` field pointing at the original call index. The tertiary effect is *false divergence attribution*: the harness reports tool nondeterminism where the real cause was its own re-execution, and the actual incident — the auditor conflict — is never localized. The architectural guardrail is a replay harness that refuses to start unless every tool in the trace's registry has a declared side-effect class, and that raises on any attempt to issue an effectful call without a ledger entry. This turns silent contamination into a loud, early failure. The cost is that some traces cannot be replayed live at all — which is correct, because a trace with unclassified side effects is not safely replayable, and pretending otherwise produces forensics you cannot trust. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class SideEffectClass(Enum): READ = "read" WRITE = "write" CHARGE = "charge" NOTIFY = "notify" DELETE = "delete" DISPATCH = "dispatch" EFFECTFUL = { SideEffectClass.WRITE, SideEffectClass.CHARGE, SideEffectClass.NOTIFY, SideEffectClass.DELETE, SideEffectClass.DISPATCH, } class ReplayContaminationError(RuntimeError): """Raised when a replay would re-apply a non-idempotent side effect.""" @dataclass class RecordedCall: trace_id: str call_index: int tool_name: str side_effect_class: Optional[SideEffectClass] recorded_response: Optional[bytes] @dataclass class ReplayLedger: applied: set = field(default_factory=set) def key(self, trace_id: str, call_index: int) -> tuple: return (trace_id, call_index) def is_applied(self, trace_id: str, call_index: int) -> bool: return self.key(trace_id, call_index) in self.applied def mark_applied(self, trace_id: str, call_index: int) -> None: self.applied.add(self.key(trace_id, call_index)) def replay_call(call: RecordedCall, ledger: ReplayLedger, live_executor) -> bytes: if call.side_effect_class is None: raise ReplayContaminationError( f"tool {call.tool_name!r} at call_index {call.call_index} has no " f"declared side-effect class; trace {call.trace_id} is not safely replayable" ) key_applied = ledger.is_applied(call.trace_id, call.call_index) if call.side_effect_class in EFFECTFUL: if key_applied: if call.recorded_response is None: raise ReplayContaminationError( f"effectful call {call.tool_name!r} at call_index " f"{call.call_index} was applied but has no recorded response; " f"cannot satisfy replay from ledger" ) return call.recorded_response # Not yet applied in this trace: refuse to execute live. raise ReplayContaminationError( f"refusing to execute effectful call {call.tool_name!r} " f"(class={call.side_effect_class.value}) at call_index " f"{call.call_index} of trace {call.trace_id}: no ledger entry, " f"live execution would contaminate the trace under forensic replay" ) # READ-class: safe to serve recorded response, or re-execute if absent. if call.recorded_response is not None: return call.recorded_response return live_executor(call) def replay_trace(calls, ledger: ReplayLedger, live_executor): results = [] for call in calls: results.append(replay_call(call, ledger, live_executor)) return results ```