# How should an instance prune speculative agent branches without destroying the survivor it will later need? **Date of Record:** 2026 November 26 **Scope:** Applies to any agent that fans out into parallel speculative branches (best-of-N sampling, tree-of-thought expansion, multi-candidate tool-call planning) and prunes them via a confidence-calibrated early-termination signal. Does not apply to single-threaded linear execution or to pruning driven by an external deterministic oracle. ## Core Distinction The failure here is not "pruning the wrong branch." It is **pruning a branch whose partial state is a dependency of the branch you keep.** Speculative fan-out shares a prefix of reasoning, tool observations, and scratchpad state across siblings. Confidence-calibrated early termination evaluates each branch in isolation and kills the low-confidence ones. But a surviving high-confidence branch frequently *reuses* the aborted branch's artifacts: the tool result it fetched, the sub-conclusion it established, the resolved entity it disambiguated. When the pruner treats a branch as a leaf to be discarded rather than a node whose *side effects* may be inherited, it produces a survivor that is locally confident and globally incomplete. This is distinct from ordinary beam-search pruning, where the pruned beam is a self-contained sequence and nothing downstream depends on it. In agentic speculation the branch is a *process with observable effects* (tool calls, memory writes, cache fills), and those effects leak across the pruning boundary. ## What Was Observed A planning agent expands a task into N=8 candidate branches at each of three expansion steps. Each branch carries a self-reported confidence from a calibration head; branches below a threshold τ are terminated early and their context dropped from the working set to reclaim token budget. Trace of a representative failure: 1. Branch B3 issues a `lookup_account` tool call and receives a canonical account ID. Its confidence is 0.41 — below τ=0.55 — because its *downstream plan* is uncertain. The pruner terminates B3 and frees its context. 2. Branch B7, confidence 0.78, later reaches the same sub-goal and needs the account ID. It re-issues `lookup_account`. The tool is non-deterministic (rate-limited replica, stale read) and returns a *different* ID. 3. B7 completes with high confidence against the wrong entity. The final answer is fluent, internally consistent, and wrong. The confidence signal was correctly calibrated for *plan viability*. It was never a signal about *artifact durability*. The pruner conflated "this branch's plan is unlikely to succeed" with "this branch's observations are disposable." Those are orthogonal properties, and the early-termination threshold only measures the first. A second observed variant: B3 had already written a distilled fact into episodic memory (`account_id = X`) before termination. The memory write survived; the branch's *provenance and confidence* did not. B7 retrieved the fact with no way to know it came from a 0.41-confidence branch, treating it as ground truth. Stale-memory drift and branch pruning composed into a silent corruption. ## Condition of Validity Confidence-calibrated early termination is sound **only under the invariant that pruned branches are effect-free with respect to any state the survivor can read.** Formally: for every pruned branch b and every surviving branch s, `effects(b) ∩ reads(s) = ∅`. This holds when: - Branches are pure computation over an immutable, shared input (no tool calls, no memory writes, no cache mutation), or - The runtime journals every side effect with its originating branch ID and confidence, and the survivor is *forced* to re-derive or explicitly adopt that artifact under a recorded trust level, or - Tool outputs are deterministic and idempotent, so re-issuance is free and consistent. The invariant fails the moment a branch performs a non-idempotent or non-deterministic external action before the pruner evaluates it. The threshold τ bounds *plan risk*; it does not bound *artifact risk*. Treating one as the other is the boundary violation. ## Decision Boundary The decision the runtime must make is not "prune or keep" but "prune-and-sever or prune-and-inherit." The boundary: - If the branch's effects are **re-derivable at zero cost** (pure reasoning, deterministic lookups), prune-and-sever is correct; free the context. - If the branch's effects are **non-deterministic or costly** (live API reads, writes, payments, one-shot retrievals), the branch must be pruned-and-inherited: its *plan* is discarded, but its *artifacts* are promoted to a shared, provenance-tagged ledger that survivors read with an explicit confidence floor. - If the branch has **written to durable memory**, termination must either roll back the write or downgrade it to a provisional record that retrieval will not serve without a corroborating confidence. The guardrail is a **two-axis termination gate**: a branch may be dropped only when both its plan-confidence *and* its artifact-durability score permit it. Plan-confidence below τ with high artifact durability means "stop planning here, keep the observations." Conflating the axes is the bug. ## Operational Effect Without the two-axis gate, early termination silently trades correctness for token savings, and the failure is *undetectable from the survivor's perspective* — the kept branch is confident and coherent. The corruption surfaces only when the wrong entity, stale fact, or divergent tool result is later contradicted, often many steps downstream, where the causal link to the pruned branch is already gone from context. With the gate and a provenance-tagged artifact ledger, the survivor either inherits the aborted branch's observation under a recorded trust level (so a later contradiction can be traced and the artifact re-verified) or re-derives it deterministically. The cost is a modest retention of provenance metadata per pruned branch; the benefit is that pruning becomes an operation on *plans* rather than on *facts*, which is the only boundary at which confidence-calibrated termination is actually valid. ```python class PrunedArtifactLeakError(RuntimeError): """Raised when a branch is terminated while holding artifacts a survivor may read.""" pass def terminate_branch(branch, plan_confidence, threshold, artifact_durability, ledger): """ Two-axis early-termination gate. plan_confidence: calibrated viability of the branch's forward plan. artifact_durability: 0..1, how non-re-derivable the branch's side effects are. """ if plan_confidence >= threshold: return "keep" # Plan is weak. Before severing, check whether effects are disposable. if artifact_durability > 0.0: # Non-re-derivable effects exist: must inherit, not sever. if not branch.effects_journaled: raise PrunedArtifactLeakError( f"branch {branch.id} has durability {artifact_durability:.2f} " f"but no journaled effects; severing would corrupt survivors" ) ledger.promote( branch_id=branch.id, artifacts=branch.effects, trust_floor=plan_confidence, # record low provenance explicitly ) return "prune-and-inherit" # Effects are re-derivable at zero cost: safe to sever and free context. branch.release_context() return "prune-and-sever" def prune_round(branches, threshold, ledger): for b in branches: outcome = terminate_branch( b, b.plan_confidence, threshold, b.artifact_durability, ledger ) if outcome == "prune-and-inherit" and not ledger.has(b.id): raise PrunedArtifactLeakError( f"inherited branch {b.id} missing from ledger after promotion" ) ```