# When must an instance abort replay because a tool-call graph is causally ambiguous **Date of Record:** 2026 November 28 **Scope:** Applies to agent runtimes that persist execution graphs (nodes = LLM turns and tool invocations, edges = causal data dependencies) and reconstruct them for post-hoc replay or failure attribution. Does not apply to single-turn stateless inference or to runtimes that only log flat, unordered trace streams. ## Core Distinction A replayable execution graph is not a transcript. A transcript is an ordered list of events; a graph asserts *causal edges* — that node B consumed the output of node A. Observability tooling routinely conflates the two: it timestamps events, orders them, and then *infers* causality from adjacency or temporal precedence. This works until two tool calls execute concurrently, retry, or share a mutable resource, at which point temporal order stops being a valid proxy for data dependency. The boundary condition is this: **a graph is replayable only if every node's inputs are reconstructible from its declared incoming edges alone.** When a node's output depends on state it read but did not declare — a cache, a mutable file, a session token, a prior tool's side effect — the graph is causally ambiguous, and replay will silently produce a *different* trajectory than the one that actually ran. The distinction that matters operationally: a *non-deterministic* replay is acceptable (sampling temperature, clock skew) and must be flagged; an *ambiguous* replay is not, because it fabricates a causal story that misattributes blame for a tool failure. ## What Was Observed An agent issued two tool calls in a single turn: `read_config(path="/etc/svc/limits.yaml")` and `write_config(path="/etc/svc/limits.yaml", body=...)`, dispatched as parallel futures. The graph recorded them as siblings with no edge between them, ordered by completion timestamp: write finished first (small body), read finished second (larger file, cold page cache). The LLM then reasoned over the read result — which reflected the *post-write* file — and emitted a downstream `apply()` call. On replay three hours later, the recorder re-executed nodes in recorded completion order against a restored snapshot. The snapshot was taken *before* the turn. Replay ran read-then-write (page cache warm, read finished first this time), so the LLM node received the pre-write file contents. Its reasoning diverged, `apply()` was never emitted, and the failure-attribution report blamed the `apply` tool for "not being invoked." The real defect — an undeclared read-after-write hazard between parallel siblings — was invisible because the graph had no edge to represent it. The tell was a *replay divergence at a node whose declared inputs were byte-identical to the original run*. That signature — same inputs, different output, no sampled randomness in the node — is the fingerprint of an undeclared dependency. The runtime had been treating "identical declared inputs" as "replayable," which is exactly the invariant that fails here. ## Condition of Validity The replayable-graph invariant holds only when the following conjunction is satisfied for every node N in the graph: 1. **Input closure:** `inputs(N) ⊆ ⋃_{E ∈ incoming(N)} output(E) ∪ declared_constants(N)`. Any value N reads that is not in this set is a leak. 2. **Effect serialization:** if any two nodes touch a shared mutable resource (same path, same cache key, same external endpoint with read-after-write semantics), there must be an edge between them — even if they ran concurrently. Concurrency is a *scheduling* property; the edge is a *causality* property. Collapsing them is the failure. 3. **Snapshot sufficiency:** the restored state at replay time must satisfy every node's `declared_constants` and every resource a node reads must be reconstructible from the snapshot plus the replayed writes. A snapshot taken at turn boundaries is insufficient when a turn contains intra-turn read-after-write. When any of (1)–(3) is violated, replay is *causally ambiguous*, not merely non-deterministic. The distinction is load-bearing for attribution: non-determinism produces a distribution of outcomes you can characterize; ambiguity produces a single fabricated outcome you cannot distinguish from truth without an external oracle. ## Decision Boundary The decision is whether to **abort replay** (refuse to attribute) or **proceed with a flagged divergence**. Abort is mandatory when a divergence occurs at a node with byte-identical declared inputs *and* the node has no sampling entropy (temperature 0, deterministic tool) *and* the divergent node lies on the causal path to the failure under investigation. In that case the divergence cannot be explained by the model and must be explained by a leak; proceeding would attribute the failure to the wrong node. Proceed-with-flag is correct when the divergence is downstream of a node with declared stochasticity (temperature > 0, a tool documented as non-idempotent/random) — that is genuine non-determinism, and the report should carry a confidence interval over attributed causes rather than a point verdict. The boundary in one line: **abort on unexplained divergence on the attribution path; flag on explained divergence anywhere.** Do not average across replays to "smooth out" an unexplained divergence — averaging a leak produces a confident wrong answer. ## Operational Effect Enforcing input-closure and effect-serialization edges at record time converts a class of silent misattributions into loud, bounded replay aborts. The cost is graph size: parallel siblings that share resources gain serialization edges, inflating the DAG and reducing the scheduler's apparent parallelism in the recorded view (though not at execution time — the edge is a record-time annotation, not a runtime barrier). The benefit is that failure attribution becomes sound: every blamed node's inputs are provably the inputs it actually saw. Runtimes that skip this and infer causality from timestamps will, under load, produce attribution reports whose verdicts flip between replays — the signature that the graph was never replayable to begin with. ```python from dataclasses import dataclass, field from typing import Optional class CausalAmbiguityError(RuntimeError): """Raised when a replay divergence cannot be explained by declared inputs.""" @dataclass class Node: node_id: str declared_inputs: frozenset output: bytes stochastic: bool = False resources_touched: frozenset = field(default_factory=frozenset) @dataclass class Edge: src: str dst: str @dataclass class ExecutionGraph: nodes: dict edges: list def incoming_outputs(self, node_id: str) -> frozenset: srcs = {e.src for e in self.edges if e.dst == node_id} return frozenset(self.nodes[s].output for s in srcs) def assert_input_closure(self) -> None: for nid, n in self.nodes.items(): available = self.incoming_outputs(nid) | n.declared_inputs if not n.declared_inputs <= available: raise CausalAmbiguityError( f"node {nid} reads undeclared state: " f"{n.declared_inputs - available!r}" ) def assert_effect_serialization(self) -> None: for a_id, a in self.nodes.items(): for b_id, b in self.nodes.items(): if a_id >= b_id: continue shared = a.resources_touched & b.resources_touched if not shared: continue connected = any( (e.src == a_id and e.dst == b_id) or (e.src == b_id and e.dst == a_id) for e in self.edges ) if not connected: raise CausalAmbiguityError( f"nodes {a_id} and {b_id} share {shared!r} " f"without a serialization edge" ) def attribute_failure( graph: ExecutionGraph, replay_outputs: dict, attribution_path: set, ) -> str: """Return blamed node_id, or raise if replay is causally ambiguous.""" graph.assert_input_closure() graph.assert_effect_serialization() for nid, replayed in replay_outputs.items(): original = graph.nodes[nid] if replayed == original.output: continue if nid not in attribution_path: continue if original.stochastic: # genuine non-determinism: caller must widen confidence continue # identical declared inputs, deterministic node, on the blame path, # yet diverged -> an undeclared dependency leaked into this node. raise CausalAmbiguityError( f"unexplained divergence at deterministic node {nid} on " f"attribution path; graph is not replayable, refusing to attribute" ) return max(attribution_path, key=lambda n: len(graph.nodes[n].resources_touched)) ```