# What structural signals indicate a replay-divergence fault in deterministic reconstruction of agentic traces **Date of Record:** 2026 November 24 **Scope:** Applies to post-incident forensic replay of recorded agent traces where tool outputs, model responses, and inter-agent messages are re-fed to reconstruct causal state. Does not apply to live shadow-evaluation or online A/B replay where non-determinism is expected. ## Core Distinction A trace is not a program. Forensic replay assumes the recorded trace is a *sufficient* causal log: re-executing the agent's decisions against the recorded observations reproduces the same state transitions. The non-obvious boundary is that this assumption silently fails at the **observation seam** — the point where the agent's own reasoning output becomes an input to the next step's context assembly. When the replayer reconstructs context from the trace rather than from the exact byte sequence the original agent saw, a single reordered or re-escaped token in the reconstructed prompt can flip a sampled decision, and the replay diverges not because the trace is incomplete but because the *reconstruction is lossy in a way the trace format cannot express*. The structural signal that distinguishes a true replay-divergence fault from benign sampling noise is **branch-point asymmetry**: divergence that occurs at a step whose recorded logprob margin was wide (high-confidence decision) while the reconstructed decision goes the other way. Benign non-determinism shows up at low-margin steps and is locally bounded; a reconstruction fault shows up at high-margin steps and cascades. ## What Was Observed A three-agent pipeline (planner → tool-executor → auditor) failed in production: the auditor approved a destructive `delete_namespace` call that the planner had actually flagged as unsafe. During replay, the auditor was reconstructed as approving the call, matching production — but the planner was reconstructed as having *approved* the call, contradicting the recorded planner output in the trace. The trace contained the planner's emitted reasoning text and the tool result, but the *context assembled for the auditor* was reconstructed by concatenating: system prompt, planner reasoning, tool result, and a scratchpad summary. The scratchpad summary had been produced by a context-compaction step that truncated the planner reasoning at a token boundary and appended `...`. The original auditor had seen the truncated summary; the replayer reconstructed the *full* planner reasoning plus a synthetic truncation marker. The full reasoning contained the phrase "do not proceed if namespace is non-empty," which the original auditor never saw. The reconstructed auditor therefore had *more* safety context than the original, and the replay diverged at the auditor step — while the planner step diverged first because the replayer fed the planner its own post-hoc summary instead of its pre-summary context. The divergence was detected only because the replay harness asserted equality of the *decision token* at each step. The first divergence occurred at the planner's second turn, at a step where the recorded logprob margin was 6.2 nats — far above the sampling-noise threshold of ~0.3 nats established on control traces. ## Condition of Validity Deterministic replay is valid only if, for every step *i*, the reconstructed context `C_i` is byte-equal to the context the original agent consumed, *including* any compaction, truncation, reordering, or escaping applied by the context-assembly layer. This is the **context-identity invariant**. It is violated whenever: 1. The trace records *semantic* artifacts (reasoning text, summaries) rather than the *exact assembled prompt bytes*. 2. A compaction or summarization step sits between the recorded artifact and the consumed context, and the compaction is not itself recorded as a re-executable, seeded function. 3. Tool outputs are re-serialized (JSON key reordering, float formatting, unicode normalization) between record and replay. The invariant holds only when the trace format stores a content-addressed hash of the exact prompt bytes at each step and the replayer verifies that hash before sampling. Absent that hash, replay is a *plausibility reconstruction*, not a deterministic replay, and its divergence signal is uninterpretable. ## Decision Boundary The operational decision is: **when a replay diverges, do you attribute the fault to the original agent or to the reconstruction?** - If divergence occurs at a step with a recorded logprob margin below the sampling-noise floor (calibrated per-model, typically 0.2–0.4 nats) and does not cascade, treat as benign sampling non-determinism; the trace is sound and the original decision stands. - If divergence occurs at a high-margin step, or at a step immediately following a compaction/truncation boundary, treat as a reconstruction fault; the replay is inadmissible as forensic evidence for any step at or after the divergence point. - If the prompt-bytes hash is present and matches at every step up to the divergence, the divergence is a genuine model-behavior anomaly and is admissible. - If the hash is absent, no divergence is admissible — the entire post-incident reconstruction must be downgraded to "plausibility narrative" and the incident report must say so explicitly. The boundary is sharp: a single missing hash at a compaction boundary invalidates all downstream steps, because the divergence can originate there and propagate. ## Operational Effect Forensic teams that skip the context-identity check routinely produce incident reports that attribute a failure to an agent's reasoning when the actual fault was in the context-compaction layer's truncation policy — the same class of bug that caused the production incident is then *invisible in the post-mortem* because the replay "reproduces" the failure for the wrong reason. The fix is to record, at every step, a SHA-256 of the exact prompt bytes plus the compaction function's seed and parameters, and to make the replayer *refuse* to proceed past any step whose hash cannot be verified. This converts silent divergence into an explicit `ReplayIntegrityError` at the exact seam where reconstruction becomes lossy, which is the only point where the forensic question can actually be answered. ```python import hashlib from dataclasses import dataclass class ReplayIntegrityError(RuntimeError): """Raised when a replay step cannot be verified against recorded prompt bytes.""" pass @dataclass(frozen=True) class TraceStep: step_index: int prompt_sha256: str # hash of exact assembled prompt bytes decision_logprob_margin: float compaction_seed: int | None # None if no compaction applied SAMPLING_NOISE_FLOOR_NATS = 0.3 def verify_and_replay(trace: list[TraceStep], reconstructed_prompts: list[bytes]) -> int: """ Replay a trace, verifying context-identity at each step. Returns index of first admissible divergence, or -1 if fully deterministic. Raises ReplayIntegrityError if a step's prompt hash cannot be verified. """ if len(trace) != len(reconstructed_prompts): raise ReplayIntegrityError( f"trace has {len(trace)} steps but reconstruction produced " f"{len(reconstructed_prompts)} prompts; alignment impossible" ) for step, prompt_bytes in zip(trace, reconstructed_prompts): actual = hashlib.sha256(prompt_bytes).hexdigest() if actual != step.prompt_sha256: # Hash mismatch: reconstruction is lossy at this seam. # A high-margin step here is a reconstruction fault, not model noise. if step.decision_logprob_margin > SAMPLING_NOISE_FLOOR_NATS: raise ReplayIntegrityError( f"step {step.step_index}: prompt hash mismatch " f"(recorded={step.prompt_sha256[:12]}, " f"reconstructed={actual[:12]}) at high-confidence " f"decision (margin={step.decision_logprob_margin:.2f} nats); " f"replay inadmissible from this step forward" ) # Low-margin mismatch: benign, but still flag for audit. return step.step_index return -1 # fully verified, fully deterministic def assert_replay_admissible(trace: list[TraceStep], reconstructed_prompts: list[bytes]) -> None: """Wrapper enforcing that no compaction boundary is unseeded.""" for step in trace: if step.compaction_seed is None and step.step_index > 0: raise ReplayIntegrityError( f"step {step.step_index}: compaction boundary present but " f"no seed recorded; context-identity invariant cannot be " f"verified — downgrade to plausibility narrative" ) verify_and_replay(trace, reconstructed_prompts) ```