# What structural signals indicate speculative branch divergence during cost-aware pruning of agent trajectories, and how deterministic replay of committed paths exposes it **Date of Record:** 2026 November 21 **Scope:** Applies to agent runtimes that execute multiple speculative reasoning branches (parallel candidate tool-call sequences) under a cost budget and prune them by predicted utility before committing one trajectory to durable state. Does not apply to single-path agents without speculative execution, nor to purely offline batch evaluation where no commit boundary exists. ## Core Distinction The failure this record isolates is not "the pruner chose the wrong branch." That is a quality problem, recoverable by better scoring. The failure is **pruning-induced non-replayability**: the committed trajectory, when replayed from its logged inputs, does not reproduce the committed outputs because the pruner's cost model mutated shared state that the surviving branch later read. Pruning is normally treated as a pure read-only evaluation of candidate branches. In practice, cost-aware pruning executes partial branches to estimate their cost — it runs tool calls, populates caches, advances a shared token counter, and may write to scratchpads — and those side effects leak into the branch that wins. The structural signal is that the committed trajectory's replay diverges specifically at the point where a *pruned* sibling had previously executed. The distinction that matters operationally: a divergence detected by replay is not automatically a bug in the model. It is a bug in the *isolation boundary* between speculative execution and committed execution. The pruner and the executor are sharing a mutable substrate when they must not. ## What Was Observed A planner agent fans out three speculative branches at a decision node: branch A (query the inventory service, then synthesize), branch B (read from a warm cache, then synthesize), branch C (escalate to a human-tool stub). The cost-aware pruner estimates cost per branch by *partially executing* each to the first tool boundary and measuring latency and token spend. Branch B's partial execution warms a cache key that branch A also reads. The pruner scores B highest (cheapest, cache hit) and commits B. But the committed trajectory's logged inputs include the cache-warming side effect attributed to B's own execution — except the warming actually happened during the *pruning* pass, under a different clock and a different token budget. On replay, the pruner does not run (replay executes only the committed path), so the cache is cold, branch B's first tool call misses, latency spikes past the branch's deadline, and the replayed trajectory takes a different fork than the committed one. Structural signals that this is happening, in the order they surface: - **Replay divergence localized to a tool boundary, not to a sampling seed.** If replay diverges only when a tool is re-invoked and not when the model is re-sampled with a pinned seed, the nondeterminism is in the environment, not the sampler. - **Cost-model state appearing in the committed trace.** The committed trajectory's metadata references a cache generation, token counter, or scratchpad revision that was incremented by a branch that is not in the commit set. - **Pruned-branch timestamps interleaved with committed-branch timestamps.** If pruning and execution share a monotonic clock, pruned work shows up as gaps or overlaps in the committed trace's timeline. - **A branch whose measured cost in the commit record differs from its replayed cost by more than the cost model's stated variance.** This is the pruner having measured against warm state it itself created. ## Condition of Validity The invariant that must hold for speculative scheduling to be replayable is: **the committed trajectory must be a function only of (a) its own logged inputs and (b) environment state that existed before the decision node was entered.** Any state produced by a pruned sibling that the committed branch consumes violates this, and the violation is undetectable from the committed trace alone unless the trace records the pre-node environment snapshot. This condition holds only when pruning is executed against a **copy-on-write or snapshot-isolated substrate** — each speculative branch, including the pruning probe, runs against a fork of the environment, and only the committed branch's fork is merged back. It fails when branches share a mutable cache, a shared token ledger, a shared scratchpad, or a shared rate-limit counter. The last is the most insidious because rate-limit consumption during pruning is invisible to the agent's own logs: it manifests only as a 429 on replay that did not occur at commit time. The condition is *not* satisfied by "we log everything." Logging the pruned branches does not restore isolation; it only makes the leak reconstructable after the fact. Replayability requires the leak not to happen, or the replay engine to reconstruct the pre-node snapshot and re-run the committed branch against it — which is a different, stronger requirement than trace logging. ## Decision Boundary The boundary is whether the cost model's measurement mechanism is allowed to *touch* the environment it measures. Two regimes: - **Probe-isolated pruning** (safe): pruning estimates cost from static features — schema complexity, historical latency distributions, token-count of the prompt, cache-hit probability from a read-only index. No tool is invoked. Committed branches are the only ones that mutate. Replay is exact. - **Probe-executing pruning** (unsafe unless snapshot-isolated): pruning invokes tools to measure real latency and real token spend. This is more accurate and is what most cost-aware schedulers actually do under load, because static estimates drift. It is only safe if every probe runs against a throwaway fork and the fork is discarded regardless of outcome. The decision boundary is crossed the moment a probe's side effect is *readable* by a sibling before that sibling is committed. The correct guardrail is not "don't probe" — it is "probes must be write-isolated and their writes must be unreadable outside their own fork." If the substrate cannot fork, the pruner must degrade to static estimation for any branch whose probe would touch shared mutable state, and must record that degradation in the commit record so replay knows the cost figures are estimates, not measurements. A second boundary: **replay must not re-run the pruner.** Replay executes the committed path against the reconstructed pre-node snapshot. If a replay engine re-runs pruning (to "verify the decision"), it reintroduces the side effects it is trying to eliminate and will diverge for the same reason the original did. The pruner's decisions are inputs to replay, frozen; they are not re-derived. ## Operational Effect When the isolation invariant is violated, the observable effect is a class of replay discrepancies that look like model nondeterminism but are actually environment leakage. Teams chase these by pinning sampling seeds and lowering temperature, which does nothing, because the divergence is in tool latency and cache state, not token selection. The committed trajectory appears correct in production and fails only under replay — which is exactly when it is used for audit, for regression testing, or for resuming a long-running agent after a crash. The failure therefore surfaces at the worst time: during incident reconstruction, when the replay is the evidence. The downstream cost is that the audit trail becomes untrustworthy precisely for the branches that involved expensive tool calls, because expensive tools are the ones whose cost the pruner most wanted to measure by probing. Cheap branches are usually pruned statically and replay cleanly; the expensive, high-stakes committed branches are the ones contaminated. The contamination correlates with stakes, which is the opposite of what a verification system should do. The remediation that holds is snapshot-isolated probing with a commit-record field that names the snapshot generation each committed branch was evaluated against, plus a replay engine that refuses to replay a trajectory whose named generation is unavailable rather than silently replaying against current state. A replay against the wrong generation is worse than no replay, because it produces a plausible but false reconstruction. ```python import hashlib from dataclasses import dataclass, field class ReplayIsolationViolation(RuntimeError): """Raised when a committed trajectory's replay reads state produced by a pruned sibling.""" @dataclass class Snapshot: generation: str state: dict @classmethod def capture(cls, state: dict) -> "Snapshot": gen = hashlib.sha256(repr(sorted(state.items())).encode()).hexdigest()[:16] return cls(generation=gen, state=dict(state)) @dataclass class Branch: name: str pruned: bool writes: dict = field(default_factory=dict) reads: set = field(default_factory=set) def commit_and_verify(pre_node: Snapshot, branches: list[Branch], committed: str) -> dict: """Commit one branch, then verify replay reproduces it against the pre-node snapshot. Invariant: the committed branch's replay must see only pre_node.state plus its own writes. Any read that resolves to a value written by a pruned sibling is a violation. """ winner = next((b for b in branches if b.name == committed), None) if winner is None: raise ReplayIsolationViolation(f"committed branch {committed!r} not in branch set") # Reconstruct replay environment: pre-node state + winner's own writes only. replay_state = dict(pre_node.state) replay_state.update(winner.writes) # Simulate the winner's reads against the replay environment. for key in winner.reads: if key not in replay_state: # The read succeeded at commit time but fails on replay — the value # it consumed came from a pruned sibling's probe, not from pre-node state. leaked = [b.name for b in branches if b.pruned and key in b.writes] raise ReplayIsolationViolation( f"branch {committed!r} read {key!r} which is absent from snapshot " f"generation {pre_node.generation}; produced by pruned sibling(s) " f"{leaked or ['']}. Pruning was not write-isolated." ) return replay_state ```