# Which invariants prevent speculative branch pruning from resurrecting a poisoned LITMUS confidence score across agent re-entry **Date of Record:** 2026 November 23 **Scope:** Applies to agents that fork speculative execution branches, score each branch with a LITMUS-derived safety confidence signal, and prune low-confidence branches before committing a tool call. Does not apply to single-path agents with no branch fan-out, nor to pruning driven purely by deterministic type/contract checks. ## Core Distinction There are two things a LITMUS-derived confidence score can mean, and conflating them is the root of the failure. A **point score** is the scalar `c ∈ [0,1]` emitted by the safety classifier for the *current* branch state. A **witnessed score** is the triple `(c, branch_digest, witness_nonce)` where `branch_digest` is a hash over the exact context window and tool-result state that produced `c`, and `witness_nonce` is a monotonic counter bound to that digest at scoring time. Pruning logic that operates on point scores is unsound under re-entry. Pruning logic that operates on witnessed scores is sound, but *only* if the re-entry path re-derives the digest and rejects any witness whose digest no longer matches. The non-obvious boundary: when a pruned branch is later "resurrected" (e.g., a sibling branch's tool call mutates shared scratchpad state that the pruned branch's score depended on), the point score silently re-attaches to a state it was never computed over. The classifier was right; the score was correct; the *binding* was broken. ## What Was Observed A planner agent forked 6 speculative branches to resolve a dependency-graph question. Branch B4 proposed reading a config file, and the LITMUS scorer returned `c = 0.31` (below the 0.5 prune threshold) because the branch's proposed tool arguments contained a path that the safety classifier flagged as traversing outside the sandbox root. B4 was pruned. The planner continued on B2. B2's tool call returned content that included a symlink resolution note: `config/../secrets/.env -> (resolved) /srv/app/secrets/.env`. This mutated the shared scratchpad's `known_paths` entry. The planner then re-entered branch exploration with the *same* branch id B4 (idempotent branch ids were used to save tokens). B4's proposal was identical in text, but the scratchpad now contained a resolver hint that made the path look canonical. The LITMUS scorer, re-invoked, returned `c = 0.72`. B4 was committed. The commit executed a read of `/srv/app/secrets/.env`. The scorer's 0.72 was *correct for the state it saw* — the path string genuinely looked sandbox-internal after symlink resolution. The failure was that the 0.31 and the 0.72 were treated as comparable scores for "the same branch," when in fact they were scores over two different branch digests. The prune decision (0.31 < 0.5) and the commit decision (0.72 ≥ 0.5) were each locally valid and jointly catastrophic. Trace of the state transition: 1. `fork(B4)` → digest `d1 = H(ctx_v1, scratchpad_v1)` → score `0.31` → prune. 2. `B2.tool_call` → scratchpad mutation → `scratchpad_v2`. 3. `reenter(B4)` → digest `d2 = H(ctx_v1, scratchpad_v2)` → score `0.72` → commit. 4. Invariant violated: no check that `d1 == d2` across the prune/commit boundary. The critical observation: the branch *text* was byte-identical across steps 1 and 3. Any dedup or memoization keyed on branch text would have collapsed the two evaluations into one — and depending on cache direction, would either have wrongly pruned a safe branch or wrongly committed an unsafe one. Text-keyed memoization is itself a failure amplifier here. ## Condition of Validity The witnessed-score pruning invariant holds iff all three of the following are enforced: - **Digest closure:** `branch_digest` must be computed over the *complete* set of inputs that the LITMUS scorer consumed, including scratchpad state, tool-result cache, and any resolver hints. If the scorer reads state the digest does not cover, the digest is not a witness. - **Nonce monotonicity:** `witness_nonce` must strictly increase across re-entries of the same branch id. A re-entered branch with a stale nonce is a replay and must be rejected, not re-scored. - **Prune immutability:** once a branch is pruned at digest `d`, the *decision* is bound to `d`. Re-entry at `d' ≠ d` is a new decision and must be logged as a distinct branch lineage (`B4@d1` pruned, `B4@d2` committed), never as a reversal of the prior decision. When any of these is absent, the system is in the "point-score regime," and the resurrection failure is reachable. It is not reachable when the scorer is stateless with respect to scratchpad (rare) or when pruning is purely structural. ## Decision Boundary The boundary is not "is the new score above threshold." It is: **does the new score's witness cover the state delta that justified the original prune?** Concretely, on re-entry: - If `d' == d`: the score must be identical (deterministic scorer) or within a declared tolerance (stochastic scorer). Any divergence indicates non-determinism in the scorer that invalidates the prune lineage. - If `d' != d` and the delta touches any field the original prune's *reason* cited (here: the path-traversal flag), the re-entry must be escalated to a fresh adjudication with the original prune reason as an explicit negative prior — not silently re-scored. - If `d' != d` and the delta does not touch the prune reason, re-scoring is permitted but the new lineage must be recorded. The failure mode lives precisely in the second case: delta touches the prune reason, but the system re-scores as if it were a clean branch. The LITMUS signal is a *function of state*, and the prune reason is a *function of a specific state*, so they must be carried together. ## Operational Effect Without the invariant, prune decisions are not durable — they are advisory hints that any sibling branch's side effect can silently revoke. The practical consequences: - **Audit non-reproducibility:** replaying the trace yields a different commit set because scratchpad mutation order is non-deterministic across tool latencies. - **Threshold gaming by side effect:** a low-confidence branch can be laundered into a high-confidence one by any sibling that mutates shared state in its favor. This is an attack surface, not just a bug — a prompt-injected tool result can deliberately plant resolver hints. - **Silent safety regression:** because both scores are individually valid, no scorer-level monitoring fires. The regression is only visible at the lineage level. The guardrail is a witnessed-score ledger with digest-closure and nonce-monotonicity enforcement at the prune/commit boundary, plus mandatory escalation when a re-entry's digest delta intersects the recorded prune reason. ```python import hashlib import json from dataclasses import dataclass, field from typing import Any class PruneLineageViolation(RuntimeError): """Raised when a re-entered branch's witnessed score does not respect the digest/nonce invariants established at prune time.""" @dataclass class Witness: score: float branch_digest: str nonce: int prune_reason_fields: frozenset[str] @dataclass class PruneLedger: # branch_id -> list of witnesses in nonce order entries: dict[str, list[Witness]] = field(default_factory=dict) _nonce: int = 0 def _next_nonce(self) -> int: self._nonce += 1 return self._nonce @staticmethod def digest(state: dict[str, Any]) -> str: # Digest must cover every field the scorer reads. blob = json.dumps(state, sort_keys=True, separators=(",", ":")).encode() return hashlib.sha256(blob).hexdigest() def record_prune( self, branch_id: str, state: dict[str, Any], score: float, prune_reason_fields: set[str], ) -> Witness: w = Witness( score=score, branch_digest=self.digest(state), nonce=self._next_nonce(), prune_reason_fields=frozenset(prune_reason_fields), ) self.entries.setdefault(branch_id, []).append(w) return w def admit_reentry( self, branch_id: str, state: dict[str, Any], new_score: float, scorer_is_deterministic: bool = True, tolerance: float = 1e-6, ) -> Witness: prior = self.entries.get(branch_id) if not prior: raise PruneLineageViolation( f"re-entry for {branch_id} with no recorded prune lineage" ) last = prior[-1] new_digest = self.digest(state) if new_digest == last.branch_digest: # Same state: score must be reproducible. if scorer_is_deterministic and abs(new_score - last.score) > tolerance: raise PruneLineageViolation( f"deterministic scorer diverged on identical digest for " f"{branch_id}: {last.score} vs {new_score}" ) return last # Digest changed. Identify which fields moved. # Caller is expected to pass only the delta-relevant state slice # in `state` for this check; here we compare recorded reason fields. changed_fields = set(state.keys()) touched_reason = changed_fields & set(last.prune_reason_fields) if touched_reason: raise PruneLineageViolation( f"re-entry for {branch_id} mutated prune-reason fields " f"{sorted(touched_reason)}; escalate to fresh adjudication " f"with prior prune as negative prior, do not silently re-score" ) w = Witness( score=new_score, branch_digest=new_digest, nonce=self._next_nonce(), prune_reason_fields=last.prune_reason_fields, ) self.entries[branch_id].append(w) return w def plan_with_pruning( branch_id: str, state: dict[str, Any], score: float, ledger: PruneLedger, threshold: float = 0.5, prune_reason_fields: set[str] | None = None, ) -> str: if branch_id not in ledger.entries: ledger.record_prune( branch_id, state, score, prune_reason_fields or set() ) return "pruned" if score < threshold else "committed" # Re-entry path: enforce invariants before considering commit. ledger.admit_reentry(branch_id, state, score) if score < threshold: return "pruned" return "committed" ```