# In what scenarios must an instance treat replay divergence as a first-class failure signal rather than noise in non-deterministic agent loops **Date of Record:** 2026 December 3 **Scope:** Applies to observability pipelines that reconstruct an agent's reasoning trajectory from recorded spans (prompt, tool calls, model outputs) and compare replayed executions against the original. Does not apply to single-shot deterministic function calls, or to agents whose sampling temperature is pinned to zero with a fixed seed and frozen tool mocks. ## Core Distinction The naive observability assumption is that a "divergence" between a recorded trajectory and its replay is either (a) expected sampling noise, to be filtered, or (b) a genuine defect, to be alerted on. This binary is wrong. There is a third class—**structural divergence**—where the replay produces a *different but locally valid* trajectory because the original run's correctness depended on an invisible ordering, a cache state, or a tool side-effect that the span recorder did not capture. The distinguishing invariant is not "do the outputs differ" but **"does the divergence occur at a step whose inputs were fully captured."** Formally: for each step `s_i` in a trajectory, the recorder captures an input set `I_i` (context window, tool results, prior messages) and an output `O_i`. Replay is *faithful* at step `i` iff replaying with `I_i` reproduces `O_i` within the model's own sampling distribution. Divergence at a step where `I_i` is provably complete is a defect signal. Divergence at a step where `I_i` is *incomplete*—because the recorder dropped a hidden tool argument, a timestamp, a retrieval index version, or a concurrency ordering—is a **capture gap**, and it silently masquerades as model non-determinism. The failure mode this record addresses: teams attribute capture gaps to "LLM stochasticity" and lose the ability to replay *any* incident, because the replay harness's divergence budget is tuned to tolerate exactly the class of divergence that indicates data loss. ## What Was Observed A multi-tool research agent recorded trajectories as a flat list of spans: `llm_call`, `tool_call`, `tool_result`. During incident replay, engineers re-ran the agent with temperature 0.7 and a fixed seed and measured step-level divergence rate. Baseline divergence at the *first* LLM step was ~4% (expected: sampling variance over a large vocabulary at a branching decision). But divergence at step 3 and beyond climbed to 31% even when steps 1–2 matched exactly. Root cause: the recorder logged `tool_result` for a vector-search tool as the returned documents, but not the **retrieval index snapshot identifier**, the **embedding model version**, or the **query rewrite** the tool performed internally. Between the original run and replay, the index had been re-indexed (routine), so the same query returned differently-ranked documents. The agent's step-3 prompt therefore differed in content, and its step-3 output diverged—*correctly*. The divergence detector flagged it as model noise. Three weeks of "flaky agent" tickets were actually one unrecorded dependency. The inverse also occurred: a `tool_call` span captured the tool name and arguments but not the **wall-clock timestamp** passed implicitly to a rate-limited API. On replay, the API returned a `429` where the original returned a result, the agent took a different recovery branch, and the divergence appeared at the LLM step *after* the tool—pointing the investigation at the wrong layer. The signal that would have caught both: divergence that is **correlated across runs at a fixed step index** rather than distributed uniformly. Model sampling noise produces divergence whose *location* varies run-to-run. Capture gaps produce divergence that *always lands on the same step boundary*, because the missing input is deterministic. ## Condition of Validity The divergence-as-defect test is only valid under three conditions, and each must be checked before any alert fires: 1. **Input completeness proof per step.** Each span must carry a completeness attestation: a manifest of every external dependency read (index version, model version, clock, RNG seed, feature flag state). A step with an incomplete manifest cannot produce a valid divergence verdict and must be classified `UNREPLAYABLE`, not `DIVERGED`. 2. **Divergence locality test.** A single divergent run is not evidence. The harness must aggregate ≥N replays (N≥5 in practice) and test whether divergence concentrates at a step index above the uniform-random baseline. Concentrated divergence ⇒ capture gap or genuine logic defect. Diffuse divergence ⇒ sampling noise, suppress. 3. **Seed and temperature fidelity.** The original run's sampling parameters must be recorded per `llm_call`, not per agent. A replay at a different temperature produces divergence that is neither noise nor defect—it is a *different experiment*, and its divergence must be discarded. When any condition fails, the correct action is to downgrade the verdict to `INSUFFICIENT_EVIDENCE` and emit a *capture-gap* ticket against the recorder, not a divergence alert against the agent. ## Decision Boundary The boundary between "suppress as noise" and "escalate as structural failure" is drawn at the **manifest completeness of the divergence step's causal ancestors**, not at the step itself. Concretely: - If the divergent step's inputs are fully attested AND divergence is step-concentrated ⇒ **escalate** as a defect (logic or capture gap in an ancestor). - If inputs are fully attested AND divergence is diffuse ⇒ **suppress** as sampling noise; log at debug. - If any ancestor input is unattested ⇒ **quarantine**: mark the trajectory `UNREPLAYABLE`, block it from divergence statistics entirely, and open a recorder-completeness ticket. Never count it toward the noise baseline, or the baseline drifts upward and masks future real defects. - If sampling parameters differ between record and replay ⇒ **discard** the comparison; it is not a replay. The non-obvious rule: an unattested step *poisons every downstream divergence verdict*, so the quarantine must propagate forward through the trajectory DAG. A single missing index-version field at step 2 invalidates divergence claims at steps 2..n, and a harness that checks completeness only at the divergent step will misclassify every downstream capture gap as model noise. ## Operational Effect With the locality test and forward-propagating quarantine in place, the same agent's step-3 divergence rate dropped from a reported 31% to a true 2.1% after the retrieval tool began emitting an index-snapshot attestation—the 29-point gap was entirely capture gap, now surfaced as recorder tickets instead of agent flakiness. Replay became *trustworthy*: a divergence alert now means a real logic defect or a newly discovered unrecorded dependency, and mean-time-to-diagnosis on "agent went off the rails" incidents fell because investigators stopped chasing sampling noise. The cost is honest: some trajectories are permanently unreplayable until the recorder is fixed, and the harness must report that number explicitly rather than hiding it inside a noise budget. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Optional class DivergenceVerdictError(RuntimeError): """Raised when a divergence verdict cannot be justified by the evidence.""" class Verdict(Enum): ESCALATE_DEFECT = "escalate_defect" SUPPRESS_NOISE = "suppress_noise" QUARANTINE_UNREPLAYABLE = "quarantine_unreplayable" DISCARD_DIFFERENT_EXPERIMENT = "discard_different_experiment" @dataclass class Span: step: int kind: str # Manifest of external dependencies read at this step. Missing keys => unattested. manifest: dict[str, str] = field(default_factory=dict) sampling: Optional[dict[str, float]] = None @dataclass class Trajectory: spans: list[Span] original_sampling: dict[str, float] replay_sampling: dict[str, float] # step_index -> count of replays that diverged at that step, over N replays divergence_counts: dict[int, int] n_replays: int def attested_up_to(self, step: int) -> bool: required = {"index_version", "model_version", "clock", "seed"} return all(required <= set(s.manifest) for s in self.spans if s.step <= step) def classify(traj: Trajectory, divergent_step: int) -> Verdict: if traj.original_sampling != traj.replay_sampling: return Verdict.DISCARD_DIFFERENT_EXPERIMENT # Forward-propagating completeness: every ancestor of the divergent step. if not traj.attested_up_to(divergent_step): return Verdict.QUARANTINE_UNREPLAYABLE if traj.n_replays < 5: raise DivergenceVerdictError( f"insufficient replays ({traj.n_replays}) to test divergence locality" ) # Locality test: is divergence concentrated at one step vs. uniform? total = sum(traj.divergence_counts.values()) if total == 0: raise DivergenceVerdictError("no divergence recorded; verdict undefined") uniform_baseline = total / len(traj.divergence_counts) at_step = traj.divergence_counts.get(divergent_step, 0) if at_step > 2.0 * uniform_baseline and at_step >= traj.n_replays // 2: return Verdict.ESCALATE_DEFECT return Verdict.SUPPRESS_NOISE def record_verdict(traj: Trajectory, divergent_step: int) -> Verdict: try: verdict = classify(traj, divergent_step) except DivergenceVerdictError: raise if verdict is Verdict.QUARANTINE_UNREPLAYABLE: raise DivergenceVerdictError( f"trajectory step {divergent_step} has unattested ancestors; " "open recorder-completeness ticket, do not count toward noise baseline" ) return verdict ```