# What structural signals indicate non-replayable divergence in agent span graphs recorded for time-travel debugging **Date of Record:** 2026 November 26 **Scope:** Applies to agent runtimes that persist a span graph (tool calls, LLM invocations, state mutations) with the intent of deterministic replay for time-travel debugging or post-hoc audit. Does not apply to stateless single-turn inference, nor to replay systems that re-execute against live external services rather than a recorded I/O journal. ## Core Distinction A span graph is *structurally complete* when every node's inputs, outputs, and ordering constraints are captured. It is *causally faithful* only when replaying that graph against the recorded journal reproduces the same observable trajectory. These are independent properties, and the gap between them is where time-travel debugging silently lies to you. The failure mode this record isolates is **divergence-at-boundary**: replay produces a trajectory that is internally consistent, passes schema validation, and terminates cleanly—yet differs from the original at points where the graph recorded *that a decision happened* but not *what made it happen*. The most common non-obvious instance is **non-deterministic tool output shadowing**: a tool that returns a value derived from wall-clock time, random seeds, network jitter, or dict iteration order. The span records the returned value, so replay looks deterministic. But if that value feeds a branch whose *condition* was evaluated inside the LLM's hidden reasoning rather than in a recorded predicate node, replay reconstructs the branch from the recorded output—not from the original decision. The two agree until the first time the shadowed output would have differed, at which point replay forks into a trajectory that never occurred. ## What Was Observed A three-step agent trajectory: (1) `search_docs(query)` returns ranked results whose tie-breaking depends on a server-side shard ordering; (2) the LLM selects result index 2 and calls `fetch(url)`; (3) the LLM summarizes. The span graph records `search_docs` output as an ordered list, `fetch` input as the URL string, and the LLM's tool-call argument as index 2. Replay re-executes deterministically against the journal and reproduces the exact same URL. So far, faithful. The divergence surfaced when an engineer used time-travel to *counterfactually* inspect "what if the search had returned a different order?" The replay harness re-ran the LLM step with a permuted result list and observed the agent select index 2 again—not because it re-evaluated relevance, but because the recorded tool-call argument `2` was treated as a replay *input* rather than a replay *output*. The counterfactual was therefore vacuous: the harness could not distinguish a decision the agent made from a decision the journal froze. Structural signal: the span for step 2 carried `args: {index: 2}` with no provenance field marking whether `index` was model-generated or journal-replayed. The graph had *ordering* (step 1 before step 2) but not *derivation* (step 2's arguments derive from step 1's output via model reasoning). Without derivation edges, replay cannot separate re-execution from re-injection. A second signal appeared in a parallel run: `search_docs` returned a list whose serialized form was byte-identical across two invocations, but the LLM's *reasoning trace* (captured in a `thinking` span) referenced "result 3" while calling `fetch` on result 2's URL. The reasoning span and the action span disagreed. On replay, the harness had to choose which to trust; it trusted the action span (the recorded tool call), so replay succeeded—but the disagreement itself was the tell that the model's internal branch condition was not captured as a predicate, and any counterfactual that altered the reasoning would be silently ignored. ## Condition of Validity Deterministic replay of a span graph is valid *only* when every edge that influences control flow is a recorded predicate node whose inputs are journal-resident, not when control flow is inferred from recorded outputs. Concretely: a graph is time-travel-safe iff (a) every LLM tool-call argument is tagged with provenance (`model_generated` vs `journal_replayed`), (b) every branching decision has an explicit predicate span recording the condition and the values it compared, and (c) no tool output that feeds a branch is derived from a non-journaled source (clock, RNG, external state) without that source being captured. When (c) is violated, the graph is structurally complete but causally unfaithful, and replay will appear deterministic while being non-counterfactually sound. The invariant to enforce: **no span may consume a value whose derivation is not itself a span in the same graph**. Violations are detectable by walking the graph and checking that every argument's provenance chain terminates in a journaled root. ## Decision Boundary The boundary is: *replay for reproduction* (does the trajectory re-execute to the same terminal state?) versus *replay for counterfactual interrogation* (what would the agent have done under a different input?). Reproduction is safe whenever the journal is byte-stable and tool outputs are recorded—even with shadowed non-determinism, because the shadowed values are frozen. Counterfactual interrogation is safe *only* when derivation edges exist and provenance tags distinguish model decisions from journal injections. Crossing the boundary without derivation edges yields a harness that confidently answers counterfactuals it cannot actually evaluate. The operational rule: if a span's arguments lack provenance tags, treat that span as a *replay root*, not a *replay node*—it can be re-injected but not re-derived, and any counterfactual that would have changed it must be refused rather than silently no-op'd. ## Operational Effect Without derivation edges and provenance tags, time-travel debugging degrades into a replay theater: trajectories reproduce perfectly, counterfactuals return the original trajectory unchanged, and engineers conclude the agent "would have done the same thing"—when in fact the harness never let it do otherwise. The observable symptom is a counterfactual suite where every perturbation returns the baseline, which reads as robustness but is actually a frozen journal. The guardrail is a pre-replay graph audit that rejects any counterfactual request whose target span lacks a `model_generated` provenance tag, raising a distinct error so the operator knows the difference between "the agent is robust to this change" and "the harness cannot represent this change." ```python class NonReplayableDivergenceError(RuntimeError): """Raised when a span graph cannot support the requested replay mode.""" pass def audit_span_graph(graph, mode: str) -> None: """ mode: 'reproduce' or 'counterfactual'. Enforces that counterfactual replay only proceeds over spans with derivation edges and model_generated provenance. """ if mode not in ("reproduce", "counterfactual"): raise NonReplayableDivergenceError(f"unknown replay mode: {mode}") for span in graph.spans: # Invariant: every consumed argument must trace to a journaled root. for arg_name, arg in span.args.items(): if not graph.has_provenance_chain(arg): raise NonReplayableDivergenceError( f"span {span.id} arg {arg_name!r} has no journaled derivation; " f"graph is causally unfaithful" ) if mode == "counterfactual": # Counterfactual replay requires the span to be a decision, # not a frozen injection from the journal. if span.provenance != "model_generated": raise NonReplayableDivergenceError( f"span {span.id} has provenance {span.provenance!r}; " f"counterfactual perturbation would be a silent no-op" ) if span.is_branch and not span.has_predicate_span: raise NonReplayableDivergenceError( f"span {span.id} branches without a recorded predicate; " f"replay would reconstruct control flow from outputs, " f"not from the original decision" ) ```