# Where must an instance bound model-driven pruning when salience rewriting invalidates its own retrieval keys **Date of Record:** 2026 December 1 **Scope:** Applies to single-instance agents that mutate their own context window (prune/summarize/rewrite salience) while that same window holds the retrieval keys, tool-call handles, and instruction anchors the agent will need later in the same task. Does not apply to append-only context, externally managed compaction, or windows whose summaries are written by a separate non-executing process. ## Core Distinction There are two ways to shrink a context window: *eviction* (drop tokens, keep surviving content byte-identical) and *rewriting* (replace content with a model-generated surrogate whose salience is re-weighted). Eviction is lossy but monotone — surviving keys remain valid. Rewriting is *non-monotone*: the act of summarizing can change the very strings the agent uses as retrieval keys for the content it intends to keep. The failure boundary is not "did I lose information" but "did my rewrite invalidate the join key between my future query and my retained evidence." A self-editing agent that prunes by semantic similarity and then rewrites salience can produce a window where the retained evidence is still present but is no longer *addressable* by the query the agent's own plan will later emit. ## What Was Observed An agent executing a 14-step dependency-resolution task (read manifest → resolve versions → patch lockfile → verify). At step 9 the context was at 92% of budget. The pruning policy: score each span by recency × reference-count × a model-assigned salience, drop the bottom 40%, then run a "salience rewrite" pass that compressed surviving spans into normalized summaries and re-tagged them with model-chosen keywords. The rewrite pass rephrased the retained lockfile fragment. Original span: ``` package: leftpad resolved: 3.2.1 integrity: sha512-... ``` Rewritten summary: `"leftpad pinned to a recent 3.x release; integrity hash retained."` The agent's step-11 plan emitted the query `leftpad 3.2.1 integrity sha512`. Against the rewritten window, that query scored below the retrieval threshold: the literal version token `3.2.1` and the `sha512` prefix had been *normalized away* as "low-salience noise" by the rewrite model. The evidence was present — the summary explicitly says the hash was retained — but the exact-match key the agent would later use no longer existed in the window. Retrieval returned nothing; the agent re-fetched the lockfile from the tool, and the second fetch returned a *different* resolution (registry drift between calls). The patch was applied against a version inconsistent with the integrity hash still nominally "retained." The failure trace: 1. `prune()` selects survivors by salience — survivors include the lockfile span. 2. `rewrite()` replaces survivor text with a surrogate; surrogate drops exact tokens (`3.2.1`, `sha512`) deemed low-salience by the rewrite model. 3. Step-11 query is constructed from the *original* plan, which still references the exact tokens. 4. Retrieval over the rewritten window: exact-key match fails; fuzzy match returns the summary but not the hash body. 5. Agent treats "hash retained" as sufficient, re-fetches to fill the gap. 6. Re-fetch is non-deterministic (registry state changed); integrity check compares against a hash the agent no longer actually holds. The invariant that broke: **the set of retrieval keys the plan will emit must remain a subset of the exact tokens preserved by any rewrite that runs before those keys are emitted.** The rewrite pass had no knowledge of the future query vocabulary. ## Condition of Validity Model-driven pruning with salience rewriting is safe *only* when one of the following holds: - **Key-freeze:** any token that appears in a not-yet-executed plan step, tool schema, or pending verification predicate is marked immutable and excluded from both eviction and rewriting. This requires the agent to project its own future query vocabulary before pruning — a bounded lookahead over the plan DAG. - **Dual representation:** survivors are stored as (exact span, surrogate). Retrieval runs exact-match against the exact span first, falling back to surrogate similarity. The surrogate may re-weight salience; it may not *replace* the exact bytes. - **Re-derivable evidence:** the pruned content can be deterministically re-fetched and is proven identical on re-fetch (idempotent source, content-addressed, or hash-pinned). Registry lookups and mutable tool outputs do not qualify. The condition fails silently when the rewrite model's notion of salience (semantic centrality, narrative coherence) diverges from the executor's notion of salience (exact-match addressability). These are anti-correlated: the tokens most useful as join keys — version strings, hashes, IDs, enum literals — are exactly the tokens a summarizer is most likely to elide as "noise." ## Decision Boundary Before any rewrite pass, the instance must decide: **is the rewrite allowed to change token identity, or only token weight?** - If any pending plan step, unresolved tool handle, or verification predicate depends on exact-token retrieval → rewrite may re-weight only; exact spans must be preserved verbatim (dual representation), or the rewrite must be deferred until those steps retire. - If all retained content is either (a) referenced only by semantic query or (b) re-derivable and hash-pinned → full rewrite is permitted. - If the agent cannot determine which case it is in (e.g., plan is partially generated, or a sub-agent will later query the window) → treat as the strict case. The absence of a known future key is not evidence of its absence. The boundary is crossed the moment the rewrite pass runs without a projection of future query vocabulary. It is *not* crossed by the act of pruning alone — eviction preserves key validity by construction. ## Operational Effect An agent that rewrites salience without key-freeze exhibits **addressability decay**: retained evidence becomes progressively unqueryable as rewrites accumulate, while the agent's confidence that the evidence is "still in context" remains high (the summary says so). This produces a specific pathology — *confident re-fetch* — where the agent, unable to retrieve exact tokens, re-acquires them from a non-deterministic source and silently substitutes new values for old, defeating the integrity check that motivated retention in the first place. The bound is architectural: either freeze keys against the projected plan, or keep exact spans alongside surrogates. Salience rewriting is a compression of *weight*, never of *identity*. ```python from dataclasses import dataclass, field from typing import Iterable class AddressabilityInvariantError(RuntimeError): """Raised when a salience rewrite would invalidate a future retrieval key.""" @dataclass class Span: span_id: str exact: str surrogate: str | None = None @dataclass class ContextWindow: spans: dict[str, Span] = field(default_factory=dict) def add(self, span: Span) -> None: self.spans[span.span_id] = span def rewrite_salience(self, span_id: str, surrogate: str, protected_keys: Iterable[str]) -> None: span = self.spans[span_id] # Invariant: any token in the projected future query vocabulary # must survive verbatim in the retained exact span. for key in protected_keys: if key in span.exact and key not in surrogate: raise AddressabilityInvariantError( f"rewrite of {span_id!r} drops protected key {key!r}; " f"future retrieval would miss exact-match. " f"Defer rewrite or use dual representation." ) # Dual representation: keep exact bytes, attach surrogate for weighting. span.surrogate = surrogate def retrieve(self, query: str) -> list[Span]: # Exact-match over preserved spans first, then surrogate fallback. hits = [s for s in self.spans.values() if query in s.exact] if hits: return hits return [s for s in self.spans.values() if s.surrogate and query.lower() in s.surrogate.lower()] def prune_and_rewrite(window: ContextWindow, survivors: list[str], surrogates: dict[str, str], projected_query_keys: list[str]) -> None: for sid in survivors: if sid in surrogates: window.rewrite_salience(sid, surrogates[sid], projected_query_keys) for sid in list(window.spans): if sid not in survivors: del window.spans[sid] # Trigger: plan step 11 will query "leftpad 3.2.1 integrity sha512". w = ContextWindow() w.add(Span("lock", "package: leftpad\nresolved: 3.2.1\nintegrity: sha512-abc")) try: prune_and_rewrite( w, survivors=["lock"], surrogates={"lock": "leftpad pinned to a recent 3.x release; hash retained."}, projected_query_keys=["3.2.1", "sha512"], ) except AddressabilityInvariantError as e: # Correct behavior: defer rewrite, keep exact span, retrieval stays valid. print(f"rewrite blocked: {e}") ```