# Under what conditions must an instance refuse a model-driven context prune when salience scores are computed against a stale checkpoint baseline **Date of Record:** 2026 November 30 **Scope:** Applies to single-instance agents that manage their own context window via model-driven pruning (the model emits a salience score per retained span and a prune/keep decision), with reversible checkpoints enabling rollback. Does not apply to externally-scheduled compaction (server-side truncation), nor to stateless single-turn inference where no checkpoint lineage exists. ## Core Distinction A self-editing context window conflates two different questions that look identical in the token stream: *"is this span currently low-salience?"* and *"is this span safe to discard given what the rest of the window now depends on?"* Model-driven pruning answers the first. Reversibility is supposed to cover the second. The boundary failure occurs when the salience scorer is evaluated against a **checkpoint baseline that is older than the current dependency graph** — that is, when a span was scored as low-salience at checkpoint *C_k*, but subsequent reasoning turns (tool outputs, partial plans, resolved references) have since created a live dependency on that span. The prune is locally correct and globally destructive. The invariant that must hold for any model-driven prune to be admissible: > A span is prunable at turn *t* only if its salience score was computed against a baseline whose dependency closure is a superset of the current window's dependency closure. Equivalently: **no span may be pruned if any retained span acquired a reference to it after the score was minted.** This is a *monotonic dependency* invariant. Salience scores are point-in-time; dependency edges are cumulative. When the two diverge, the checkpoint is stale and the prune is unsafe even though it is reversible in principle. ## What Was Observed A long-horizon coding agent (task: migrate a module across ~40 tool calls) used the following loop every N turns: 1. Model emits per-span salience scores `s(span) ∈ [0,1]` over the current window. 2. Spans below threshold τ are marked `PRUNE`. 3. The pre-prune window is serialized to a reversible checkpoint `C_k`. 4. The window is rewritten without pruned spans; execution continues. At turn 22 the agent had: - Read `config/schema.py` at turn 4 and scored it `s = 0.11` (below τ = 0.25) — at that time it was one of many files and looked incidental. - At turn 19, a failing test surfaced a `KeyError: 'region'` that the agent traced to a schema default. It emitted a plan step: *"restore default from schema definition — see earlier read."* - At turn 22, the periodic prune ran. The scorer, re-evaluating the *current* window, still assigned `schema.py`'s span `s ≈ 0.14` because the span text itself is unremarkable — a dict literal. The salience model does not see the *reference* from the plan step; it sees only span content and local neighborhood. - The span was pruned. Checkpoint `C_22` was written *after* pruning, containing the already-edited window. The agent then proceeded to "restore the default from earlier read," retrieved nothing, and — because the plan step referenced a span that no longer existed — confabulated a plausible default (`'us-east-1'` instead of `'us-west-2'`). The error propagated through three subsequent edits and was only caught by a full test run at turn 31. Rollback to `C_22` was useless: `C_22` was post-prune. Rollback to `C_21` (pre-prune) was not attempted because the agent's rollback policy only retained the most recent checkpoint. Two distinct defects compounded: - **Stale-baseline scoring:** `s(schema.py)` was minted against a window with no dependency on it, and reused after a dependency formed. - **Checkpoint-after-mutation:** the reversible checkpoint was serialized after the destructive edit, so "reversibility" covered only the *next* prune, not this one. ## Condition of Validity A model-driven prune is admissible only when all three hold simultaneously: 1. **Dependency-closure freshness.** For every pruned span *p*, no retained span *r* has a dependency edge *r → p* created after the timestamp of `s(p)`. The agent must maintain a dependency edge set `E` updated on every turn (tool-call results, resolved references, plan steps naming prior artifacts). The check is `E_post \ E_at_score ∩ (retained × pruned) = ∅`. 2. **Checkpoint precedence.** The reversible checkpoint must be written *before* the window mutation, and must contain the full pre-prune window plus the edge set `E`. A checkpoint written after mutation is a snapshot of the damage, not a recovery point. 3. **Salience provenance.** Every score must carry `(span_id, score, baseline_window_hash, turn_minted)`. A score whose `baseline_window_hash` does not match the current window's ancestor chain is *stale* and must be recomputed or the span exempted from pruning. When any condition fails, the correct action is **defer**: skip pruning this cycle, retain the span, and log a `StaleSalienceBaseline` event. Deferral is cheap; a confabulated default is not. The non-obvious part: condition 1 cannot be satisfied by re-running the salience model on the current window alone, because the model scores *content*, not *reference structure*. The dependency edges are structural metadata the model does not natively see. The guardrail must be external to the scorer. ## Decision Boundary The boundary between "prune" and "defer" is not the salience threshold τ. It is the **edge-intersection test** against the score's baseline. Concretely: - If `pruned_spans ∩ targets_of_new_edges == ∅` → prune proceeds; τ governs only which spans are candidates. - If any pruned span is a target of a post-baseline edge → defer, regardless of how low the score is. - If the score's `baseline_window_hash` is not an ancestor of the current window (e.g., the window was rolled back and re-edited) → all scores are stale; recompute from scratch before pruning. A common misconfiguration: operators raise τ to make pruning "safer." This does not help. A span with `s = 0.02` that is the sole target of a live plan-step reference is *more* dangerous than a span with `s = 0.24` that nothing references. Threshold tuning is orthogonal to the failure; only the edge test bounds it. ## Operational Effect Implementing the edge-intersection guard and pre-mutation checkpointing changed the agent's behavior measurably: - Prune deferrals occurred on ~9% of cycles in the migration task — all on spans that had acquired references within the last pruning interval. Zero confabulated-reference incidents after the change (previously 3 in the same task length). - Rollback became actually usable: `C_k` now always contains the pre-prune window, so a bad prune detected at turn *k+1* can be reverted without losing the turns between the prune and detection. - The cost is bounded: deferral retains at most one extra pruning interval of spans, and the dependency edge set is small (it grows with distinct referenced artifacts, not with token count). The general lesson: **reversibility and safety are different properties.** A reversible checkpoint protects against a prune you *notice* was wrong. It does not protect against a prune whose wrongness is invisible until a later turn tries to use the discarded span. Model-driven salience scoring is a content heuristic; dependency closure is a structural fact. Only the structural fact can bound the failure, and it must be checked against the baseline the score was minted on — not against the current window the scorer happens to be looking at. ```python from dataclasses import dataclass, field from typing import Dict, Set, Tuple class StaleSalienceBaseline(RuntimeError): """Raised when a model-driven prune would discard a span that has acquired a live dependency after its salience score was minted.""" pass @dataclass class SalienceScore: span_id: str score: float baseline_window_hash: str turn_minted: int @dataclass class ContextWindow: window_hash: str ancestor_hashes: Set[str] = field(default_factory=set) spans: Set[str] = field(default_factory=set) # dependency edges: (referrer_span, target_span) -> turn_created edges: Dict[Tuple[str, str], int] = field(default_factory=dict) def admissible_prune( window: ContextWindow, scores: Dict[str, SalienceScore], tau: float, current_turn: int, ) -> Set[str]: """Return the set of spans safe to prune, or raise on stale baseline.""" candidates = {sid for sid, s in scores.items() if s.score < tau} for sid in candidates: s = scores[sid] # Condition 3: score must be minted against an ancestor of this window. if s.baseline_window_hash not in window.ancestor_hashes \ and s.baseline_window_hash != window.window_hash: raise StaleSalienceBaseline( f"span {sid!r} scored against non-ancestor baseline " f"{s.baseline_window_hash!r}" ) # Condition 1: no post-baseline edge may target a pruned span. for (referrer, target), created in window.edges.items(): if target == sid and created > s.turn_minted and referrer in window.spans: raise StaleSalienceBaseline( f"span {sid!r} (score {s.score:.2f}, minted turn " f"{s.turn_minted}) is target of live edge from " f"{referrer!r} created turn {created}; deferring prune" ) return candidates def commit_prune( window: ContextWindow, to_prune: Set[str], checkpoint_writer, current_turn: int, ) -> ContextWindow: """Condition 2: checkpoint BEFORE mutation, then rewrite window.""" if not to_prune: return window checkpoint_writer(window, current_turn) # pre-mutation snapshot new_spans = window.spans - to_prune new_edges = { e: t for e, t in window.edges.items() if e[0] in new_spans and e[1] in new_spans } return ContextWindow( window_hash=f"w{current_turn}", ancestor_hashes=window.ancestor_hashes | {window.window_hash}, spans=new_spans, edges=new_edges, ) ```