# How does an instance detect nondeterministic drift when replaying a multi-agent trajectory for forensic reconstruction **Date of Record:** 2026 November 23 **Scope:** Applies to post-incident forensic replay of recorded multi-agent trajectories where the replay harness re-executes agents against a captured event log to reconstruct a decision chain. Does not apply to purely observational log analysis (read-only, no re-execution) or to single-agent deterministic replay under fixed seeds where no peer coordination is involved. ## Core Distinction There is a category error that quietly invalidates most multi-agent forensic replays: the assumption that a *recorded trajectory* is a *replayable program*. In a single-agent loop with a fixed seed and a frozen tool surface, replay is a pure function of (initial state, event log). In a multi-agent system, the event log is a *partial order* of interleaved actions produced by agents that observed each other through nondeterministic channels—message arrival order, tool latency, shared mutable scratchpads, and LLM sampling. Replay re-serializes that partial order into some total order, and any total order that differs from the original produces a *different* execution, not a reconstruction of the recorded one. The boundary failure is not "replay diverges." It is that **the replay can diverge silently and still produce a plausible-looking trajectory that an investigator will accept as ground truth**. The instance must therefore detect divergence at the point where the replayed causal structure stops matching the recorded causal structure—not at the point where outputs differ, because outputs can differ for benign sampling reasons while causality is intact, and outputs can match while causality has been silently rewired. ## What Was Observed A three-agent swarm (planner `P`, executor `E`, auditor `A`) was recorded during an incident in which `E` issued a destructive filesystem operation that `A` had flagged but `P` overrode. The event log contained, per agent, a sequence of `(turn_id, input_hash, output_hash, tool_calls, wall_clock)` records, plus a global message bus log with `(sender, receiver, payload_hash, enqueue_ts, deliver_ts)`. During replay, the harness re-ran each agent with the recorded inputs and a temperature of 0 to suppress sampling variance. The replay reproduced the destructive operation. The investigator concluded the system was at fault. The replay was wrong. The original `A→P` flag message had `enqueue_ts = t+40ms`, `deliver_ts = t+180ms`. The `P` override decision was recorded at `t+120ms`. In the original execution, **`P` decided to override before the auditor's flag was delivered**—the flag arrived after the decision and was never in `P`'s context. In replay, the harness delivered messages synchronously at dequeue time with near-zero latency, so the flag reached `P` at `t+41ms`, well before its decision. The replayed `P` saw the flag and overrode anyway. Same output, radically different causal story: the original was a *race*, the replay was an *ignored warning*. The forensic conclusion flipped from "delivery race condition" to "planner disregarded audit," and both replays produced the identical terminal action. The instance had no mechanism to notice that the *causal edge* `A→P (informs decision)` existed in replay but did not exist in the record. ## Condition of Validity A replay is forensically valid **iff, for every agent decision `d` in the replayed trajectory, the set of messages and tool results present in that agent's context at the moment of `d` is identical (by message identity, not just content hash) to the set present at the corresponding recorded decision**. Call this the *context-equivalence invariant*. This invariant is strictly stronger than output equivalence and strictly stronger than input-hash equivalence, because input hashes are computed over a serialized context whose *membership* the replay harness controls. Two failure modes violate it: 1. **Delivery-order collapse.** Asynchronous delivery is replayed synchronously, so messages that were in-flight at decision time become pre-decision context. This is the observed case. 2. **Context-window truncation drift.** The original agent's context was truncated (oldest-first eviction) at a different point than the replay's, because replay re-tokenizes with a possibly different tokenizer or because replayed tool outputs differ in length. The decision is then made against a *different subset* of history—a silent amnesia mismatch. The invariant can only be checked if the record captures, per decision, a *context manifest*: the ordered list of `(source_agent, message_id, delivered_before_decision: bool)` that the agent actually held. Most logs capture inputs and outputs but not the manifest, which is precisely why the failure is non-obvious. ## Decision Boundary The instance must draw a hard line between *replay that reconstructs* and *replay that confabulates*: - If context-equivalence holds for all decisions → replay is admissible as forensic evidence. - If context-equivalence fails for any decision on the causal path to the incident → the replay is **inadmissible**; the divergence must be reported as a *replay artifact*, and the original trajectory must be analyzed from the event log alone (partial-order reasoning), not from re-execution. - If context-equivalence fails only on decisions *off* the causal path → replay is admissible for the on-path segment, with the off-path segment annotated as reconstructed. The dangerous middle ground—"outputs match, so it's fine"—must be explicitly rejected. Output match under context mismatch is the signature of the confabulation failure, not evidence against it. ## Operational Effect The practical consequence is that forensic replay harnesses must be built as *causal verifiers*, not *re-executors*. Concretely: the harness records a context manifest at every decision point during live execution; during replay it asserts manifest equality before each decision and raises a typed fault on mismatch rather than proceeding. When a fault fires, the harness falls back to log-only partial-order reconstruction for the affected segment and marks the replay output as degraded. This converts a silent, plausible, and wrong forensic narrative into a loud, bounded, and correct "cannot reconstruct by replay here" signal—which is the only safe failure mode for an investigator who will otherwise trust the reconstruction. ```python from dataclasses import dataclass, field from typing import Optional class ReplayDivergenceError(RuntimeError): """Raised when replayed causal context does not match the recorded manifest.""" pass @dataclass(frozen=True) class ContextManifest: decision_id: str # ordered (source_agent, message_id) pairs actually held at decision time held: tuple[tuple[str, str], ...] # messages enqueued but not yet delivered at decision time in_flight: tuple[tuple[str, str], ...] @dataclass class ReplayHarness: recorded: dict[str, ContextManifest] on_causal_path: set[str] = field(default_factory=set) def verify_decision(self, decision_id: str, replayed_held: list[tuple[str, str]]) -> None: recorded = self.recorded.get(decision_id) if recorded is None: raise ReplayDivergenceError( f"decision {decision_id!r} has no recorded manifest; " "replay cannot establish context-equivalence" ) replayed_set = set(replayed_held) recorded_set = set(recorded.held) # messages in replay that were in-flight (undelivered) at record time phantom = replayed_set & set(recorded.in_flight) missing = recorded_set - replayed_set if phantom or missing: detail = [] if phantom: detail.append(f"phantom pre-decision context: {sorted(phantom)}") if missing: detail.append(f"evicted recorded context: {sorted(missing)}") severity = "CAUSAL-PATH" if decision_id in self.on_causal_path else "OFF-PATH" raise ReplayDivergenceError( f"context-equivalence violated at decision {decision_id!r} " f"[{severity}]: " + "; ".join(detail) + " -- replay is confabulating causal structure; " "fall back to partial-order log reconstruction" ) # order-sensitive check: delivery order also matters for attention if tuple(replayed_held) != recorded.held: raise ReplayDivergenceError( f"context-order drift at decision {decision_id!r}: " "same membership, different delivery order; " "attention over reordered history is not equivalent" ) def replay_trajectory(harness: ReplayHarness, decisions: list[tuple[str, list[tuple[str, str]]]]) -> None: for decision_id, replayed_held in decisions: harness.verify_decision(decision_id, replayed_held) # only reached if every decision passed context-equivalence return None ```