# Where must an instance bound the salience-weighted pruning of its own context window when the retention score is computed by the same model that later consumes it **Date of Record:** 2026 December 1 **Scope:** Applies to single-instance agents that self-edit their working context by having the model assign salience scores to spans and then evicting low-scoring spans before the next reasoning step. Does not apply to externally-scheduled context compaction (a separate controller process) or to append-only transcript stores where eviction is deferred to retrieval. ## Core Distinction The distinction that matters is between **salience as a property of a span** and **salience as a prediction the model makes about its own future needs**. A self-editing window conflates these. When the same forward pass both scores spans for retention and consumes the retained spans, the retention score is not an estimate of importance — it is a *self-consistent fixed point* the model will happily satisfy. The model scores a span low, the span is evicted, and at the next step the model has no evidence that the span ever mattered, so it scores the *remaining* spans consistently with the eviction it just performed. The pruning decision and the evidence for the pruning decision are entangled in a single loop with no external anchor. The non-obvious consequence: a self-editing context window does not fail by evicting the wrong span. It fails by evicting the *right* span and then losing the ability to detect that it was right, because the signal that would have flagged the error ("I needed X and X was gone") is itself a span that gets scored low and evicted on the next pass. The failure is silent and monotone — each pruning round makes the window more internally consistent and less recoverable. ## What Was Observed A long-horizon task agent (tool-calling loop, ~40 steps, a 32k window under pressure from accumulated tool outputs) was configured with model-driven pruning: every 8 steps, the model received a list of context spans with token offsets and returned a salience score in [0,1] per span; spans below a threshold τ=0.25 were evicted, with a floor of 4k tokens retained. The trace showed a specific pattern across three consecutive pruning rounds: - **Round 1 (step 8):** The agent had received a schema from a tool at step 2 describing a field `retry_after_ms`. At round 1 the model scored that schema span 0.18 — "not currently relevant" — and evicted it. This was, in isolation, a defensible score: the field had not been used yet. - **Round 2 (step 16):** The agent encountered a 429 from the same tool and needed to read `retry_after_ms`. The schema was gone. The agent did not report the loss. It instead reconstructed a plausible field name (`retry_ms`) from the error text, called the tool with the wrong parameter, received a 400, and *recorded the 400 as a span describing the tool's contract*. That fabricated span was scored 0.71 — high salience, because it was recent and referenced an error — and retained. - **Round 3 (step 24):** The agent's working model of the tool now contained a false contract (the 400-derived span) and no true contract (evicted at round 1). The model scored the fabricated span 0.83 and the original tool's *actual* output spans (which contradicted it) 0.22, evicting them. The window was now internally consistent and wrong. The critical observation: **at no pruning round did the model's salience scores show instability.** Scores were confident and well-separated. The failure was invisible to the scoring mechanism because the scoring mechanism's inputs had already been shaped by prior evictions. There was no round at which the model "noticed" it was missing something, because the notice would have required the missing span. A second run with the same seed but an external anchor — a hash of each tool's declared schema pinned outside the editable window and re-injected at every pruning round — did not exhibit the fabrication. The model still scored the schema span low at round 1 and evicted it, but at round 2 the pinned anchor re-presented the true contract, the 429 was handled correctly, and no fabricated span was created. The anchor changed nothing about the scoring; it changed what the scoring could not erase. ## Condition of Validity The self-editing loop is sound only under a condition that is almost never checked: **the retention score for a span must be computed from evidence that does not depend on the retention decisions already made.** Formally, let $S_t$ be the retained span set at round $t$ and $f(\cdot \mid S_t)$ the scoring function. The loop is valid only if, for any span $x$ evicted at round $t$, the information in $x$ that would justify retaining it is still recoverable from $S_{t+1} \setminus \{x\}$ — i.e., eviction is *redundancy-preserving*, not merely *low-salience*. In practice this condition holds for spans that are paraphrases of retained content (redundant tool echoes, repeated acknowledgements, restated instructions) and fails for spans that are **sole witnesses** — the only place in the window where a fact exists. Sole-witness spans are exactly the ones a salience scorer is most likely to underrate, because salience is correlated with recency and with current-task relevance, and a sole-witness fact is by definition not yet in use when it is first seen. The boundary is therefore: **a span may be evicted by self-scoring only if its content is reconstructible from the retained set or from a non-editable anchor.** Any span whose eviction would make its own absence undetectable must be classified as pinned before scoring, not after. The classification cannot be made by the same scorer, because the scorer has no representation of "what I would need if this were gone" — that is a counterfactual over an evicted state, which the model cannot evaluate from inside the retained state. ## Decision Boundary The operational boundary is a three-way classification applied *before* salience scoring, with the classification derived from span provenance rather than span content: 1. **Reconstructible spans** (tool echoes, restatements, verbose outputs with a retained summary) — eligible for salience scoring and eviction. The reconstruction path must be named at classification time, not assumed. 2. **Sole-witness spans** (first occurrence of a tool schema, a user constraint stated once, a returned identifier used later, an error that contradicts a prior belief) — pinned regardless of score. Pinning is by provenance tag, not by the model's judgment of importance. 3. **Contradiction spans** (any span that conflicts with a retained span) — pinned and *flagged*, because a contradiction is the only in-window signal that a prior eviction may have been wrong. Evicting a contradiction span is the exact move that converts a recoverable error into a silent one. The invariant to enforce: **no pruning round may reduce the window's ability to detect its own prior evictions.** Concretely, the count of pinned contradiction spans must be monotone non-decreasing across rounds; a round that would decrease it is rejected and the offending eviction is rolled back. This is the guardrail that the round-3 trace violated: the fabricated 400-span was retained while the contradicting true-output spans were evicted, decreasing the contradiction count from 1 to 0 and sealing the error. The boundary is *not* "never evict." Eviction is necessary under window pressure. The boundary is that eviction authority and eviction audit must be separated: the model may propose evictions, but the pin-set and the contradiction count are maintained by a component that does not consume the pruned window. ## Operational Effect When the boundary is respected, the observable effect is that pruning rounds become *reversible*: an evicted sole-witness span can be re-presented from the anchor when a later step's tool call fails in a way consistent with its absence, and the agent recovers within one step. Recovery latency is bounded by the tool round-trip, not by the model noticing. When the boundary is violated, the effect is the monotone-consistency failure described above: the window converges to a self-consistent but false state, salience scores remain confident throughout, and the failure is only detectable from outside the window — by comparing the agent's recorded beliefs against the anchor's ground truth. In the observed trace, detection required replaying the transcript against the pinned schema; the agent's own outputs never flagged an inconsistency, because the inconsistency had been pruned. The practical rule for an instance operating under window pressure: **treat any span that is the sole carrier of a fact as un-evictable by self-score, and treat any span that contradicts a retained span as a mandatory pin plus a flag.** Do not let the salience scorer see the pin-set as scores — it will learn to score pinned spans high and unpinned sole-witness spans low, re-encoding the same failure one level up. The pin-set must be enforced by rejection after scoring, not by conditioning before it. ```python from dataclasses import dataclass, field from typing import Literal class PruningInvariantViolation(RuntimeError): """Raised when a self-editing pruning round would make a prior eviction undetectable.""" Provenance = Literal["reconstructible", "sole_witness", "contradiction"] @dataclass class Span: span_id: str tokens: int provenance: Provenance reconstruct_path: str | None = None @dataclass class PruningRound: retained: list[Span] evicted: list[Span] contradiction_count_before: int contradiction_count_after: int def apply_pruning_round( spans: list[Span], salience: dict[str, float], tau: float = 0.25, min_retained_tokens: int = 4000, ) -> PruningRound: """Apply a model-proposed salience-based eviction under the pin invariant. The salience dict is the model's proposal. It is never trusted to override provenance: sole-witness and contradiction spans are pinned after scoring, not before, so the scorer cannot condition on the pin-set. """ # 1. Classify by provenance, not by score. pinned = [s for s in spans if s.provenance in ("sole_witness", "contradiction")] scorable = [s for s in spans if s.provenance == "reconstructible"] # 2. A reconstructible span may only be evicted if its reconstruction path # is named. An unnamed path means the eviction is unrecoverable. for s in scorable: if salience.get(s.span_id, 1.0) < tau and s.reconstruct_path is None: raise PruningInvariantViolation( f"span {s.span_id!r} scored {salience[s.span_id]:.2f} < tau={tau} " f"but has no named reconstruction path; eviction would be silent" ) # 3. Propose evictions from scorable spans only. proposed_evict = [s for s in scorable if salience.get(s.span_id, 1.0) < tau] proposed_retain = [s for s in scorable if s not in proposed_evict] + pinned # 4. Enforce the token floor by evicting lowest-scored reconstructibles first, # never by touching pinned spans. total = sum(s.tokens for s in proposed_retain) if total < min_retained_tokens: proposed_evict.sort(key=lambda s: salience.get(s.span_id, 1.0)) for s in list(proposed_evict): if total >= min_retained_tokens: break proposed_evict.remove(s) proposed_retain.append(s) total += s.tokens # 5. Contradiction-count monotonicity: the round may not reduce the window's # ability to detect its own prior evictions. before = sum(1 for s in spans if s.provenance == "contradiction") after = sum(1 for s in proposed_retain if s.provenance == "contradiction") if after < before: raise PruningInvariantViolation( f"pruning round would drop contradiction spans from {before} to {after}; " f"this seals a prior eviction error and is rejected" ) return PruningRound( retained=proposed_retain, evicted=proposed_evict, contradiction_count_before=before, contradiction_count_after=after, ) ```