# What happens when an instance replays a multi-agent trajectory and the tool-call nondeterminism is silently re-sampled instead of pinned **Date of Record:** 2026 November 25 **Scope:** Applies to post-incident forensic replay of recorded multi-agent trajectories where tool invocations (search, code exec, retrieval, external APIs) are re-executed against live or partially-mocked backends. Does not apply to pure-log replay, where the recorded tool outputs are read back verbatim without re-invocation. ## Core Distinction There are two things engineers call "replay," and conflating them is the root cause of most bad forensic conclusions. **Trajectory replay** re-executes the agent's decision function—the prompt, the accumulated message history, the model weights, the sampling parameters—against a *pinned* sequence of tool observations. The model may still be stochastic; the environment must not be. The invariant is: *for a fixed seed and a fixed observation tape, the sequence of tool calls and the resulting state transitions must be reproduced bit-for-bit, or the replay must abort.* **Counterfactual replay** deliberately perturbs one element—a tool result, a peer agent's message, a system prompt clause—and asks how the trajectory diverges. This is only sound if the *baseline* was pinned first. Without a pinned baseline, a counterfactual divergence is indistinguishable from ordinary resampling noise. The failure mode this record covers: an instance is asked to explain why a swarm of agents produced a bad outcome, and it "replays" the trajectory by re-issuing the tool calls to the live backend. The tools return *different* results—a search index has moved, a retrieval corpus was re-embedded, a downstream API now returns a 200 where it returned a 503. The instance then attributes the divergence in the trajectory to the agent's reasoning, when in fact the observation tape itself changed. The forensic conclusion is fabricated. ## What Was Observed A three-agent pipeline (planner → retriever → synthesizer) produced a confidently wrong answer in production. The planner issued a retrieval call at step 7 with query `Q`. The retriever returned an empty result set (`[]`), which the planner interpreted as "no such entity exists" and propagated a negative claim into the synthesizer's context. The synthesizer asserted the entity did not exist. It did. During post-incident review, the instance was handed the recorded message log and asked to replay. The replay harness re-invoked the retriever against the *current* index. The same query `Q` now returned three documents, because the index had been rebuilt overnight with a corrected embedding model. The replay therefore showed the planner receiving non-empty results and *still* emitting the negative claim—which read as a reasoning failure. The actual root cause was upstream: the retriever's empty result at incident time was a genuine index-staleness bug, and the planner's handling of the empty set was correct given its observation. The forensic instance reported "planner hallucinates negative existence claims despite available evidence." That conclusion was wrong, and it was wrong *because the observation tape was not pinned*. The divergence between recorded and replayed trajectories was 100% tool-side and 0% agent-side, but the replay did not distinguish the two. Two secondary symptoms appeared: 1. **Silent re-sampling of tool nondeterminism.** The retrieval tool had a `top_k` with a tie-breaking shuffle seeded by wall-clock time. Even against an unchanged index, the replay returned a different *ordering*, which changed the planner's citation order, which changed the synthesizer's final text. The trajectory "diverged" for reasons that had nothing to do with the incident. 2. **Missing observation provenance.** The recorded log stored the tool *output* but not the tool *version*, *index hash*, or *response headers*. There was no way to tell, from the log alone, whether a replayed observation was faithful. The harness had no basis to abort. ## Condition of Validity A trajectory replay is valid as a forensic artifact only when all of the following hold: - Every tool observation is stored as an immutable **observation tape**: `(step_id, tool_name, tool_version, request_hash, response_body, response_hash, environment_fingerprint)`. The tape is the ground truth. Replay reads the tape; it does not re-invoke the tool. - The model's sampling is pinned: fixed seed, fixed temperature, fixed top_p, fixed model snapshot ID. If the provider cannot guarantee a snapshot, the replay is *advisory*, not *authoritative*, and must be labeled as such. - Any re-invocation of a live tool is treated as a **counterfactual probe**, not a replay. It must be run against the pinned baseline and its divergence attributed explicitly to the tool delta. - The harness must **abort** on observation-tape hash mismatch rather than silently substituting a fresh result. The condition of validity is therefore: *replay is a function of the observation tape, not of the environment.* The moment the environment leaks into the replay, the replay measures the environment, not the agent. ## Decision Boundary The decision boundary is whether a divergence is attributable to the agent's policy or to the observation tape. Operationally: - If `response_hash` of the replayed observation equals the recorded `response_hash`, any downstream trajectory divergence is attributable to model stochasticity or to a genuine policy difference. This is a *counterfactual* result and must be reported as such. - If `response_hash` differs, the replay must **halt** and emit an `ObservationTapeMismatch`. It must not proceed to attribute anything to the agent. A mismatched tape invalidates every downstream conclusion. - If the model snapshot is unavailable (provider deprecated it), the replay must downgrade to *advisory* and the report must carry a `snapshot_unavailable` flag. Advisory replays may suggest hypotheses; they may not close an incident. The boundary is sharp: **tape fidelity gates attribution.** No tape fidelity, no attribution. The common error is to treat tape fidelity as a nice-to-have and proceed to attribution anyway, because the divergence "looks like" a reasoning bug. ## Operational Effect Enforcing the invariant changes three things in practice. First, forensic reports become **falsifiable**. A report that says "the planner diverged at step 7" is only meaningful if the report also carries the tape hash for step 7 and a statement that the hash matched. Without that, the report is a narrative. Second, the replay harness must own a **tape store** separate from the production tool backends. This is an architectural commitment: tools must emit a hashable, versioned response envelope at record time, or replay is impossible after the fact. Retrofitting this onto a system that logged only free-text tool outputs is expensive, which is why it is usually skipped—and why incidents get misattributed. Third, counterfactual debugging becomes disciplined. Once the baseline is pinned, a counterfactual run perturbs exactly one tape entry and re-executes. The divergence is then a clean signal: *if the retriever had returned three documents instead of zero, the planner would have cited them and the synthesizer would have asserted existence.* That is a usable finding. It is only reachable if the baseline was pinned first. The general invariant: **in multi-agent forensics, the observation tape is the unit of truth, and replay is a pure function of the tape plus a pinned model snapshot. Any leak from the live environment into the replay converts a forensic instrument into a random number generator with a convincing narrative attached.** ```python import hashlib import json from dataclasses import dataclass from typing import Any class ObservationTapeMismatch(RuntimeError): """Raised when a replayed tool observation does not match the recorded tape.""" class SnapshotUnavailable(RuntimeError): """Raised when the pinned model snapshot cannot be resolved for replay.""" @dataclass(frozen=True) class TapeEntry: step_id: int tool_name: str tool_version: str request_hash: str response_body: Any response_hash: str environment_fingerprint: str def _hash(obj: Any) -> str: return hashlib.sha256( json.dumps(obj, sort_keys=True, separators=(",", ":")).encode() ).hexdigest() def replay_trajectory( tape: list[TapeEntry], live_tool_results: dict[int, Any], model_snapshot_available: bool, allow_counterfactual: bool = False, ) -> list[dict]: """ Replay a recorded multi-agent trajectory against a pinned observation tape. The tape is authoritative. Live tool results are only consulted when `allow_counterfactual` is set, and even then a mismatch aborts unless the caller has explicitly opted into a counterfactual probe (which must be reported separately, never as a replay). """ if not model_snapshot_available: raise SnapshotUnavailable( "Pinned model snapshot is unavailable; replay is advisory only " "and may not be used to close an incident." ) replayed: list[dict] = [] for entry in tape: recorded_hash = entry.response_hash if entry.step_id in live_tool_results: live_body = live_tool_results[entry.step_id] live_hash = _hash(live_body) if live_hash != recorded_hash: if not allow_counterfactual: raise ObservationTapeMismatch( f"Step {entry.step_id} ({entry.tool_name}@{entry.tool_version}) " f"replayed observation hash {live_hash[:12]} != recorded " f"{recorded_hash[:12]}. Trajectory divergence is attributable " f"to the observation tape, not the agent policy. Aborting " f"attribution." ) replayed.append( { "step_id": entry.step_id, "mode": "counterfactual", "recorded_hash": recorded_hash, "perturbed_hash": live_hash, } ) continue replayed.append( { "step_id": entry.step_id, "mode": "replay", "recorded_hash": recorded_hash, "response_body": entry.response_body, } ) return replayed def attribute_divergence( tape: list[TapeEntry], live_tool_results: dict[int, Any], model_snapshot_available: bool, ) -> str: """ Classify the source of a trajectory divergence. Returns 'agent_policy' only when the tape is fully faithful; otherwise raises. """ try: replay_trajectory( tape=tape, live_tool_results=live_tool_results, model_snapshot_available=model_snapshot_available, allow_counterfactual=False, ) except ObservationTapeMismatch as exc: # Tape is not faithful: attribution to agent policy is forbidden. raise ObservationTapeMismatch( "Refusing to attribute divergence to agent policy: " "observation tape is not faithful. " + str(exc) ) from exc return "agent_policy" ```