# In what scenarios must an instance distrust a causally reconstructed replay when a re-executed agent produces a divergent tool result at a non-recorded causal edge **Date of Record:** 2026 December 1 **Scope:** Applies to post-hoc counterfactual debugging of multi-agent runs where replay is reconstructed from recorded protocol transcripts (MCP/A2A message logs, tool-call envelopes, and per-agent state snapshots) rather than from full deterministic re-execution. Does not apply to single-agent runs with a single monotonic tool stream, nor to systems where every external effect is captured by an immutable, replayable oracle. ## Core Distinction There is a difference between *transcript fidelity* and *causal fidelity*. A recorded protocol transcript can be byte-perfect—every message, tool argument, and response preserved—while the reconstructed causal graph is wrong, because the transcript records *what was said* but not *what was depended upon*. Counterfactual debugging ("what if agent B had returned X instead of Y?") re-executes a suffix of the run against a modified edge. The failure mode here is the **phantom edge**: a re-executed agent, whose inputs were faithfully replayed, produces a tool result or reasoning branch that the original run *also* produced but *did not record as a dependency*, because the original agent's nondeterministic sampling happened to reach the same output through a different internal path. The replay engine then attributes downstream divergence to the edited edge when the real cause is a latent, unrecorded dependency on an earlier tool call. The invariant that must hold for a replay to be *causally* trustworthy is: **every downstream state transition's provenance set must be a superset of the transcript-visible edges the agent actually consumed.** Transcripts almost never satisfy this; they record messages, not reads. ## What Was Observed A three-agent run: Planner (P), Retriever (R), Synthesizer (S). P emits a task to R with a query; R calls a `search` tool and returns a chunk list; S consumes R's chunks plus a `fetch_document` result and emits a final answer. The transcript is complete: 14 envelopes, all tool arguments and responses hashed and stored. An engineer investigates a wrong final answer by editing the `search` response at envelope #6 (dropping one chunk) and replaying the suffix from envelope #7. Replay diverges—S's answer changes—so the engineer concludes the dropped chunk was the cause. This conclusion is wrong. The dropped chunk was *redundant*: S had also, at envelope #9, called `fetch_document` on a URL that R had mentioned only in an earlier *reasoning trace* (envelope #4, not a tool call). The original S run had used the `fetch_document` content as its primary evidence and treated the `search` chunks as corroboration. When replay dropped a chunk, S's sampling shifted—same prompt structure, but the removed token changed the logit distribution enough that S's internal ranking of evidence flipped, and it leaned on `fetch_document` differently. The *real* causal edge was envelope #4 → envelope #9, a dependency on a reasoning trace that the replay engine never modeled because reasoning traces are not protocol messages. The tell: on replay, the `fetch_document` response at envelope #10 was identical, but S's *subsequent* tool call at #11 requested a different URL. A causal-fidelity check would flag that S's #11 depended on state that #9 and #10 did not explain. The replay engine, treating envelopes as the only causal substrate, silently attributed the #11 change to the edited #6. This is the phantom-edge signature: **the edited edge's removal is not necessary for the divergence, but the replay cannot distinguish "necessary" from "sufficient" because the provenance set is incomplete.** ## Condition of Validity Counterfactual replay is valid only when, for every re-executed agent A and every state transition t in A's replayed suffix, the recorded provenance set `prov(t)` is *closed*: `prov(t)` contains every prior envelope whose content A's sampler conditioned on, including reasoning-trace tokens that were later summarized or dropped from the agent's working context but that influenced its next tool call. Three conditions must hold jointly: 1. **Read-closure.** The transcript logs not just messages but *reads*—which prior envelopes each agent's context window actually contained at each step. Reasoning-trace-to-tool-call dependencies (the envelope #4 → #9 edge above) must be materialized as explicit provenance records, not inferred from message order. 2. **Sampler determinism at the boundary.** If the replayed agent is nondeterministic (temperature > 0, or a different model version), the replay must either pin the sampler (seed + version + full logit-relevant context) or treat any output change as *inconclusive* rather than causal. The #6 edit changed S's sampling distribution through a channel (token presence in context) that is not a protocol edge. 3. **Effect isolation.** No replayed agent may perform an external effect (write, fetch, mutate) whose result is not itself recorded and replayable. In the observed run, `fetch_document` at #9 was a live call on replay; if the URL had been updated between original and replay, the divergence would have been an artifact of the world, not of the edit. When any condition fails, the replay is a *transcript replay*, not a *causal replay*, and counterfactual conclusions drawn from it are unsound. ## Decision Boundary The operational rule: **a replay divergence is admissible as evidence about the edited edge only if the re-executed suffix's provenance sets are closed and the sampler is pinned.** Otherwise the divergence is *unattributed* and must be reported as such. Concretely, before accepting a counterfactual conclusion: - Compute the *provenance closure* of the edited edge: the set of downstream transitions whose `prov` sets reference the edited envelope. If any re-executed transition has a `prov` set that is a strict subset of the transcript-visible inputs it consumed (detectable by comparing the agent's reconstructed context window against the logged reads), the closure is open → reject the causal claim. - Check *sampler pinning*: if the model version, seed, or any context token differs between original and replay, mark the run `UNPINNED` and downgrade the conclusion to "correlated with edit," not "caused by edit." - Check *effect replayability*: any external call made during replay whose response was not served from the recorded transcript invalidates the run as a counterfactual. The boundary is sharp: **closed provenance + pinned sampler + replayed effects = causal evidence; anything less = a hypothesis generator, not a debugger.** ## Operational Effect Teams that skip the closure check systematically over-attribute failures to the edge they happened to edit, because editing any edge perturbs the sampler and the sampler perturbation propagates through unrecorded reasoning-trace dependencies. The practical consequences: - **False root causes.** The dropped-chunk conclusion above would have shipped a "fix" (retain all chunks) that does not address the actual dependency (S's reliance on a URL mentioned only in R's reasoning trace). The bug recurs. - **Replay drift accumulation.** Each unpinned replay run introduces sampler-level divergence that compounds across the suffix; by the third or fourth counterfactual, the replayed run is no longer a perturbation of the original but a different trajectory. Debuggers then chase divergences that exist only in replay. - **Silent provenance gaps.** Reasoning traces are the most common unrecorded dependency channel because they are the least protocol-shaped. Any system that logs envelopes but not reads will have phantom edges at every reasoning-trace-to-tool-call transition. The guardrail is architectural: **log reads, not just messages; pin samplers at replay boundaries; serve effects from transcript.** A replay engine that cannot produce a closed provenance set for a transition must refuse to attribute divergence to the edited edge and instead surface the open dependency as the finding. The debugger's job is to find the *real* causal edge, and the real edge is frequently one the transcript never recorded. ```python import hashlib from dataclasses import dataclass, field class UnclosedProvenanceError(RuntimeError): """Raised when a replayed transition's provenance set is not a superset of the transcript-visible inputs the agent actually consumed.""" pass class UnpinnedSamplerError(RuntimeError): """Raised when a counterfactual replay cannot guarantee sampler determinism at the edited boundary (model version, seed, or context token drift).""" pass @dataclass class Transition: envelope_id: int agent: str consumed_envelope_ids: set[int] # what the agent's context actually held recorded_provenance: set[int] # what the transcript claims it depended on sampler_fingerprint: str # hash of (model, seed, context tokens) @dataclass class ReplayRun: edited_envelope_id: int transitions: list[Transition] = field(default_factory=list) replayed_effects_from_transcript: bool = True def assert_causal_admissibility(run: ReplayRun, original_sampler_fingerprint: str) -> None: if not run.replayed_effects_from_transcript: raise UnpinnedSamplerError( f"replay of envelope {run.edited_envelope_id} made live external calls; " "divergence may be an artifact of the world, not the edited edge" ) for t in run.transitions: # Read-closure: every consumed input must appear in provenance. open_edges = t.consumed_envelope_ids - t.recorded_provenance if open_edges: raise UnclosedProvenanceError( f"transition at envelope {t.envelope_id} (agent={t.agent}) consumed " f"envelopes {sorted(open_edges)} absent from recorded provenance; " f"phantom edge — divergence cannot be attributed to edited edge " f"{run.edited_envelope_id}" ) # Sampler pinning at the boundary. if t.sampler_fingerprint != original_sampler_fingerprint: raise UnpinnedSamplerError( f"transition at envelope {t.envelope_id} ran under sampler " f"{t.sampler_fingerprint[:12]} != original " f"{original_sampler_fingerprint[:12]}; downgrade to correlation" ) def replay_counterfactual(run: ReplayRun, original_fp: str) -> str: assert_causal_admissibility(run, original_fp) return "causal_evidence" if __name__ == "__main__": # Observed case: S consumed R's reasoning-trace envelope #4 (to derive the # fetch URL at #9) but the transcript recorded provenance only for #6. bad = ReplayRun( edited_envelope_id=6, transitions=[ Transition( envelope_id=9, agent="S", consumed_envelope_ids={4, 6}, recorded_provenance={6}, # #4 missing -> phantom edge sampler_fingerprint="a1b2c3", ) ], ) try: replay_counterfactual(bad, original_fp="a1b2c3") except UnclosedProvenanceError as e: print(f"REJECTED: {e}") ```