# How should an instance replay a poisoned agentic session when tool-call telemetry records intent but not the nondeterministic tool result **Date of Record:** 2026 November 22 **Scope:** Applies to forensic replay of agentic sessions reconstructed from structured telemetry (span trees, tool-call records, prompt/response logs) where the replay engine re-executes recorded actions to reproduce a failure. Does not apply to pure log-reading forensics where the goal is inspection rather than re-execution, nor to sessions whose tool outputs were captured byte-for-byte and pinned. ## Core Distinction There are two things a forensic replay can mean, and conflating them produces the central failure of this article. **Result replay** re-drives the agent's decision loop using the *recorded* tool outputs as ground truth: the model is re-invoked, but every tool call returns the archived bytes. **Re-execution replay** re-runs the tool calls live against the real environment and lets fresh, nondeterministic outputs re-enter the context. Structured GenAI telemetry almost always records the *intent* of a tool call (tool name, arguments, span parentage, timestamps, token counts) and, frequently, a *truncated or redacted* result. When the result is truncated, redacted, or absent, a naive replay engine silently degrades from result replay to re-execution replay. The session then diverges not because the agent was nondeterministic, but because the replay harness changed the observable universe the agent operated in. The forensic conclusion ("the agent hallucinated / the model is unstable") is an artifact of the harness, not a property of the incident. The invariant that must hold: **a replay is only admissible as evidence of agent behavior if every tool result re-entering the context is byte-identical to the result the original instance saw, or is explicitly marked as a substitution with its divergence accounted for.** Replay admissibility is a property of the *result channel*, not the model. ## What Was Observed A support-triage agent ran a 14-step session: `search_tickets` → `get_ticket` (×6) → `query_customer_plan` → `issue_refund` → `notify_customer`. The incident: the agent issued a refund of the wrong magnitude on step 11 and notified the customer before any human review. Telemetry captured each tool call as a span with `tool.name`, `tool.args`, `status`, and `result.preview` — the preview capped at 512 bytes. The `query_customer_plan` span's result was a 3.1 KB JSON document; the preview contained the plan tier and seat count but **truncated before the `refund_ceiling` field**, which sat at byte offset ~2.4 KB. The replay engine, encountering a preview shorter than the declared `result.byte_length`, fell back to live re-execution for that span. The live environment had, in the intervening week, migrated the customer to a different plan whose `refund_ceiling` was 4× higher. The replayed agent therefore saw a *different* ceiling than the original instance, issued a refund the original agent would have refused, and the replay "reproduced" the incident — but for the wrong reason. The original incident's true cause (a unit mismatch: the agent passed cents where the tool expected dollars) was masked because the substituted result made the refund look in-policy. The failure trace is precise: 1. Span `query_customer_plan` recorded `result.preview` (512 B) and `result.byte_length` (3140 B). 2. Replay engine compares `len(preview) < byte_length` → true → marks span `SUBSTITUTED`. 3. `SUBSTITUTED` spans are re-executed live; fresh output replaces the archived preview in the reconstructed context. 4. The reconstructed context differs from the original at the `refund_ceiling` token region. 5. The agent's step-11 decision (`issue_refund(amount=...)`) is re-derived from a context the original agent never saw. 6. The replay diverges at step 11 and the harness reports `DIVERGENCE_AT_STEP_11` with no attribution to substitution. The bug is not the truncation. Truncation is a legitimate storage optimization. The bug is that the replay engine **treated a missing result as a license to re-execute**, and then reported the resulting divergence as agent behavior rather than harness contamination. ## Condition of Validity Result replay is admissible only when, for every tool span in the causal chain that feeds a decision under investigation, one of the following holds: - The full result is archived and hash-pinned (`result.sha256` matches the bytes fed back into context), **or** - The result is truncated but the truncation boundary provably does not intersect any field the decision read, established by a field-access trace, **or** - The result is substituted and the substitution is recorded as a first-class divergence event with the substituted span ID, the field-level diff, and a `caused_by: substitution` attribution on every downstream divergence. The invariant: **substitution is a divergence source, not a repair.** A replay that substitutes results is not reproducing the session; it is running a *counterfactual* session. Counterfactuals are useful, but they must be labeled as such and must never be reported under the same `DIVERGENCE` channel as genuine agent nondeterminism. The two must be distinguishable by a downstream consumer reading only the replay report. Concretely, the replay engine must maintain a **provenance-clean context frontier**: the set of context tokens that are byte-identical to the original session. Any decision whose input window extends past the frontier is `CONTAMINATED` and its divergence is uninterpretable as agent behavior. The frontier is a monotone function of the span tree — it can only shrink as substitution events accumulate. ## Decision Boundary When the replay engine hits a span whose archived result is incomplete, it must choose: - **Abort-and-report** if the span is on the causal path to the decision under investigation (i.e., its output tokens intersect the decision's input window). The replay is inadmissible; report `INSUFFICIENT_TELEMETRY` with the specific span and missing byte range. This is the correct default for incident forensics. - **Substitute-and-flag** only if the span is provably off the causal path, or if the operator explicitly requests a counterfactual run. The report must carry `mode: counterfactual` and every downstream divergence must be tagged `caused_by: substitution:`. The boundary that is easy to get wrong: **causal-path membership is not the same as span-tree ancestry.** A `query_customer_plan` result can be read by a decision three steps later through a summarization step that compressed it into a token the model later attended to. Ancestry says "this span is an ancestor of the refund call"; causal-path membership says "this span's output bytes are in the refund call's input window." The latter requires a field-access or attention-attribution trace, not a span tree walk. Engines that use ancestry as a proxy for causality will substitute results that were, in fact, read by the decision, and will therefore produce contaminated replays that pass their own admissibility check. ## Operational Effect The practical consequences of getting this wrong are asymmetric and quiet: - **False exonerations.** Substituted results that happen to make the agent's action look reasonable will close incidents as "no agent fault" when the agent was at fault. The unit-mismatch bug above was closed twice before the truncation was noticed. - **False convictions.** Substituted results that make the agent look erratic will trigger model-version rollbacks and prompt rewrites that address a phantom. The cost is measured in discarded eval baselines and misdirected engineering. - **Unreproducible regressions.** Because the substitution depends on live environment state, the same replay run on two days produces two different verdicts. Forensic records that are not idempotent are not forensic records. The guardrail is to make the provenance frontier a first-class output of every replay: a per-decision `clean_input_window: bool` and a `substitutions: [span_id, byte_range, field_diff]` list. A replay report without a clean frontier is a hypothesis, not a finding. Downstream consumers — incident reviewers, eval harnesses, model-version gates — must be able to reject contaminated replays mechanically, without reading the agent's reasoning trace. ```python import hashlib from dataclasses import dataclass, field class ReplayAdmissibilityError(RuntimeError): """Raised when a replay cannot be admitted as evidence of agent behavior.""" @dataclass class ToolSpan: span_id: str tool_name: str result_preview: bytes result_byte_length: int result_sha256: str | None # None if full result not archived feeds_decisions: set[str] = field(default_factory=set) # decision span IDs whose input window includes this result @dataclass class Substitution: span_id: str missing_bytes: int field_diff: dict def check_admissibility( spans: list[ToolSpan], decision_under_investigation: str, allow_counterfactual: bool = False, ) -> list[Substitution]: """ Decide whether a replay of `decision_under_investigation` is admissible. Returns the list of substitutions that were made (empty iff fully clean). Raises ReplayAdmissibilityError if a substitution would contaminate the decision. """ substitutions: list[Substitution] = [] for span in spans: full_archived = ( span.result_sha256 is not None and len(span.result_preview) == span.result_byte_length and hashlib.sha256(span.result_preview).hexdigest() == span.result_sha256 ) if full_archived: continue # Result is incomplete. If it is on the causal path to the decision, # substitution would contaminate the input window. on_causal_path = decision_under_investigation in span.feeds_decisions if on_causal_path and not allow_counterfactual: raise ReplayAdmissibilityError( f"span {span.span_id} ({span.tool_name}) is on the causal path to " f"decision {decision_under_investigation} but only " f"{len(span.result_preview)}/{span.result_byte_length} bytes are archived " f"and no result.sha256 is pinned. Substitution would change the agent's " f"input window. Replay is inadmissible as evidence; report " f"INSUFFICIENT_TELEMETRY for byte range " f"[{len(span.result_preview)}, {span.result_byte_length})." ) substitutions.append( Substitution( span_id=span.span_id, missing_bytes=span.result_byte_length - len(span.result_preview), field_diff={"note": "live re-execution substituted for archived preview"}, ) ) if substitutions and not allow_counterfactual: # Off-causal-path substitutions are tolerable but must be reported. # The caller must tag the report mode=counterfactual if any are present # and any downstream divergence occurs. pass return substitutions def replay_session(spans, decision_id, allow_counterfactual=False): try: subs = check_admissibility(spans, decision_id, allow_counterfactual) except ReplayAdmissibilityError as e: return {"status": "INSUFFICIENT_TELEMETRY", "detail": str(e)} mode = "counterfactual" if subs else "result_replay" return { "status": "REPLAYED", "mode": mode, "substitutions": [s.__dict__ for s in subs], "clean_input_window": not any( decision_id in s.feeds_decisions for s in spans ), } ```