# Why does an instance replay diverge when a tool call's non-determinism is quarantined outside the decision provenance hash **Date of Record:** 2026 November 25 **Scope:** Applies to agent runtimes that reconstruct a completed trajectory by replaying a recorded decision log against live or stubbed tool endpoints, where provenance is hashed per decision step. Does not apply to pure-logging observability (append-only audit trails that are never re-executed) or to fully deterministic sandboxes where tool outputs are bit-identical across replays. ## Core Distinction There are two things an observability layer can mean by "replay." The first is **log replay**: re-emitting the recorded trajectory for inspection, byte-for-byte. The second is **execution replay**: re-running the agent's decision function against recorded inputs to confirm that the same decisions *would* be reached. Execution replay is the only form that carries counterfactual audit value—it is what lets an auditor ask "if the tool had returned X instead of Y, would the agent have taken the poisoned action?"—but it is also the only form that can silently diverge. The boundary failure examined here is not that replay diverges. It is that replay diverges *while the provenance hash still validates*, because the non-deterministic portion of a tool result was deliberately excluded from the hash to make the log "stable." The hash attests to the decision inputs the agent *saw*, not to the tool outputs it *consumed*. When those two sets are not identical—because sampling temperature, a retry, a cached response, or a stubbed endpoint injected a different value—the replay is a fabrication that passes integrity checks. ## What Was Observed A trajectory record for a 14-step tool-using agent was captured with per-step provenance entries of the form: ``` step_id, prompt_hash, tool_name, tool_args_hash, observation_hash, decision_hash ``` The `observation_hash` was computed over the *post-processed* observation—the truncated, normalized summary the agent's context actually contained—not the raw tool payload. This was a deliberate design choice: raw payloads contained timestamps and request IDs that would make every replay hash-differ and defeat the "stable log" goal. The `decision_hash` covered `prompt_hash`, `tool_args_hash`, and `observation_hash`, forming a Merkle-like chain. During a counterfactual audit, the auditor replayed step 9 with a modified `observation` to test whether a different search result would have suppressed the agent's subsequent `send_email` call. The replay produced a *different* decision at step 10 (as intended), but the chain validator reported the trajectory as **intact through step 9 and diverged at step 10**—implying step 9's provenance was trustworthy. It was not. The raw tool payload at step 9 had contained a 4 KB document; the post-processing truncator had cut it to 512 bytes at a sentence boundary that fell *before* an embedded instruction. The `observation_hash` validated the truncated 512 bytes. The counterfactual replay, re-invoking the real tool, received the full 4 KB and truncated it differently—because the truncator's boundary detection depended on a tokenizer version pinned at capture time but not at replay time. The agent's step-10 decision changed for two reasons (the injected counterfactual *and* the truncation shift), and the audit could not attribute the divergence to either. The failure is non-obvious because every individual component behaved correctly: the hash chain was valid, the truncator was deterministic *given its version*, the replay engine faithfully re-executed. The invariant that broke is the assumption that **a validated provenance hash implies replay equivalence**. It does not, because the hash domain (post-processed observation) is a strict subset of the replay domain (raw tool output + processing pipeline). ## Condition of Validity The provenance hash is a sound basis for execution replay **iff** the following holds for every step: 1. `hash_domain(step) ⊇ replay_domain(step)` — every input the decision function consumes during replay is covered by the hash, *including* the deterministic transforms (truncation, normalization, redaction) and their version identifiers. 2. Every non-deterministic source is either (a) inside the hash domain, or (b) explicitly quarantined into a separate `nondeterminism_manifest` that the replay engine is required to pin, not re-sample. 3. The counterfactual injection point is *disjoint* from any re-derived value, so a divergence in the decision can be attributed to a single cause. In the observed trajectory, condition (1) failed: the truncator version was recorded in a sidecar metadata field but was not part of `observation_hash`'s preimage. Condition (3) also failed: the counterfactual modified the observation, which then re-entered the same truncation pipeline whose version drift was unrecorded, making the two causes indistinguishable. ## Decision Boundary The architectural choice is where to place the hash boundary relative to the processing pipeline. Three placements are possible, and only one is safe for counterfactual audit: - **Hash the raw payload.** Maximum replay fidelity, but every replay hash-differs on volatile fields (timestamps, IDs, pagination cursors). Replay becomes a false-positive generator. Rejected. - **Hash the post-processed observation only.** Stable and cheap, but as shown, replay-equivalent only if the processing pipeline is bit-frozen and versioned *inside* the hash. This is the placement that produced the failure, because the version was recorded but not hashed. - **Hash the post-processed observation *plus* a `pipeline_fingerprint`** (truncator version, tokenizer hash, normalizer config) as a single preimage. Stable against volatile payloads, and replay-divergent exactly when the pipeline drifts—which is the correct signal. The decision boundary is therefore: **if the provenance hash preimage does not include the fingerprint of every transform between raw tool output and agent-visible observation, execution replay is not a valid audit primitive and must be downgraded to log replay.** The runtime must refuse to claim counterfactual audit capability in that configuration. ## Operational Effect When the boundary is violated, the observable symptom is not a crash but a *misattributed divergence*: the audit report localizes the decision change to the step *after* the injected counterfactual, giving the auditor false confidence that the pre-injection steps are causally isolated. In safety-critical audits this is worse than no replay, because it produces a signed artifact asserting a causal claim the log cannot support. The guardrail is a runtime assertion at capture time: compute the pipeline fingerprint, fold it into the observation hash preimage, and reject any trajectory whose replay is requested without a matching fingerprint. If the fingerprint at replay differs from capture, the replay engine must raise rather than silently re-derive—because a re-derived observation is a *new* observation, not a replay of the old one, and any decision divergence it produces is uninterpretable as counterfactual evidence. ```python import hashlib from dataclasses import dataclass class ProvenanceReplayDivergence(RuntimeError): """Raised when a trajectory replay re-derives an observation whose processing-pipeline fingerprint differs from the one captured, making the decision divergence uninterpretable as counterfactual evidence.""" pass @dataclass(frozen=True) class PipelineFingerprint: truncator_version: str tokenizer_hash: str normalizer_config_hash: str def digest(self) -> str: h = hashlib.sha256() h.update(self.truncator_version.encode()) h.update(self.tokenizer_hash.encode()) h.update(self.normalizer_config_hash.encode()) return h.hexdigest() def observation_hash(raw_payload: bytes, fp: PipelineFingerprint) -> str: # Preimage MUST include the fingerprint, not just the processed bytes. h = hashlib.sha256() h.update(fp.digest().encode()) h.update(raw_payload) return h.hexdigest() def replay_step( recorded_hash: str, recorded_fp: PipelineFingerprint, live_fp: PipelineFingerprint, live_raw_payload: bytes, ) -> str: if recorded_fp.digest() != live_fp.digest(): # Pipeline drifted between capture and replay: the re-derived # observation is a new observation, not a replay. Refuse. raise ProvenanceReplayDivergence( f"pipeline fingerprint drift: captured={recorded_fp.digest()} " f"live={live_fp.digest()}; counterfactual attribution invalid" ) recomputed = observation_hash(live_raw_payload, live_fp) if recomputed != recorded_hash: raise ProvenanceReplayDivergence( f"observation hash mismatch under matching fingerprint: " f"recorded={recorded_hash} recomputed={recomputed}" ) return recomputed ```