# Where must an instance bound self-editing context policies when a rewrite invalidates the retrieval keys that justified the prune **Date of Record:** 2026 November 24 **Scope:** Applies to any agent that mutates its own working memory at runtime—summarize-and-drop pruning, key-rewriting compaction, or slot replacement—where the prune/rewrite decision is justified by retrieval scores computed against the *pre-edit* working set. Does not apply to append-only context growth, external vector-store garbage collection, or stateless single-shot inference. ## Core Distinction The failure is not "the summarizer lost information." It is that **the act of rewriting the working set changes the retrieval geometry that the edit policy used to decide what to keep.** A self-editing context policy computes a keep/drop decision from similarity scores between a query (task goal, recent turn, or active subgoal) and stored memory items. When the policy then *rewrites* a retained item—compresses it into a summary, re-keys it, merges two entries—the new artifact has a different embedding, a different set of lexical anchors, and a different length than the item that earned its retention score. The justification for keeping it no longer holds against the artifact that replaced it. This is a fixed-point problem, not a compression-fidelity problem. A faithful summary can still be a *retrieval-misaligned* summary: it preserves the facts but migrates them into a vector neighborhood the future query will not visit. The policy pruned item A because A scored 0.81 against the current goal; the summary A′ scores 0.44 against the same goal, but the policy never re-scores A′ because it already committed the edit. The invariant that must hold is: > **Retention justification must be re-evaluated against the post-edit artifact, not the pre-edit item, before the edit is committed as durable.** Most self-editing implementations violate this by construction: they score, select, rewrite, and write back in a single pass with no re-scoring gate. ## What Was Observed A long-horizon coding agent with a 32k working-memory budget ran a compaction policy every time utilization crossed 85%. The policy: embed all memory items against the active task embedding, keep the top-k by cosine similarity, summarize the remainder into a single "background" block, and rewrite retained items longer than 400 tokens into ≤120-token abstracts to reclaim budget. Trace from a debugging session (reconstructed): 1. Turn 40, utilization 86%. Item `M17` = a 900-token stack trace plus the agent's hypothesis ("the retry wrapper double-wraps the client, so timeouts fire at 2× the configured value"). Cosine to active goal (`fix intermittent timeout`) = 0.79. Retained, then rewritten to a 110-token abstract: *"Timeout observed; suspected retry interaction."* 2. The rewrite dropped the lexical anchors `double-wrap`, `2×`, `retry wrapper` and the numeric `2×` entirely. The abstract's embedding drifted toward generic "timeout" semantics. 3. Turn 58, utilization 88%, second compaction. The active goal had shifted to `explain why configured timeout is doubled`. Item `M17′` (the abstract) scored 0.41 against the new goal embedding—below the 0.55 retention threshold—and was pruned into the lossy background block, which itself was re-summarized. 4. Turn 61: agent re-derived the double-wrap hypothesis from scratch by re-reading the same files, burning 7 tool calls and ~9k tokens, then contradicted its own turn-40 conclusion because the numeric anchor was gone and it now believed the multiplier was 3×. The measurable signature: **retention score of the artifact diverged from retention score of its source by a mean of 0.31 cosine** across 40 rewrites, and in 6 of 40 cases the artifact fell below the threshold that had originally admitted its source. The policy was, in effect, admitting items and then silently evicting them one cycle later—a two-phase eviction with a one-cycle delay that no single compaction pass could observe. A second, subtler signature: **rewrite amplification under repeated compaction.** Each pass re-summarized prior summaries. By the fourth pass, `M17` had become *"timeouts."* Information loss was not linear in passes; it was superlinear because each pass scored the *previous abstract* rather than the original, so drift compounded without any pass ever seeing the source. ## Condition of Validity The re-scoring gate is required—and the failure is live—only when all of the following hold: - The edit policy is **score-gated**: retention is a function of query-artifact similarity, not a fixed priority or recency rule. (Recency-only policies are immune to this specific failure.) - The edit is **non-isometric**: rewriting changes the embedding/lexical surface such that similarity to a plausible future query is not preserved. Lossless copy or verbatim move is safe. - The policy **commits edits durably** across turns, so a later pass scores the artifact rather than the source. If every pass re-derives from an immutable source-of-truth log, the drift cannot accumulate. - The query distribution **shifts** between passes (goal drift, new subgoal). Under a stationary query, the artifact is re-scored against the same query and the drop is at least *detectable*; under drift it is masked. When the policy retains a pointer to the immutable source alongside the artifact, the condition does not bite—the artifact can be re-expanded. The invariant is therefore conditional on **artifact-only durability**. ## Decision Boundary The boundary is not "should I summarize?" but **"against which object do I re-validate retention, and when?"** Three concrete decision rules: 1. **Re-score before commit, not after.** After generating artifact A′ from source A, embed A′ and re-evaluate its retention score against the *current* query set (active goal plus any pinned subgoals). If `score(A′) < θ_retain` while `score(A) ≥ θ_retain`, the rewrite is a *net eviction* and must be rejected or the source must be pinned. Do not defer this check to the next compaction pass—by then the source is gone. 2. **Pin sources for artifacts that cross the threshold margin.** Maintain a margin band `[θ_retain, θ_retain + δ]`. Any source whose score sits in the band, or whose rewrite drops it out of the band, must retain a back-pointer to the immutable source. This bounds drift amplification: repeated compaction can only re-summarize the artifact, never the source, and the source remains re-expandable. 3. **Cap rewrite depth per lineage.** Track a `rewrite_generation` counter per memory lineage. Refuse to re-summarize an artifact whose generation exceeds `G_max` (empirically 2–3 for factual/debugging content); instead, force re-expansion from source or escalate to a lossless store. This directly bounds the superlinear drift. The boundary condition to encode: **a rewrite that lowers the artifact's retention score below the admission threshold is a bug, not a budget win.** It is an eviction disguised as a compression. ## Operational Effect With the re-score gate and margin-pinning applied, the same agent over the same session: rewrite-induced score drops were caught at commit time (6/40 rewrites rejected, sources pinned), the `M17` lineage retained a back-pointer and re-expanded verbatim at turn 58 when the goal shifted to the doubled-timeout question, and the agent did not re-derive the hypothesis—saving the 7 tool calls and avoiding the self-contradiction. Rewrite amplification was bounded by `G_max = 2`, holding mean artifact score decay to 0.08 cosine per pass instead of 0.31. The general operational lesson: **self-editing context policies are only sound if the retention predicate is a fixed point of the edit.** Score the artifact you are about to store, not the item you decided to keep. When the two disagree, the edit has quietly changed the policy's own justification—and the next pass will act on the new justification without ever having voted on it. ```python from dataclasses import dataclass, field class RewriteEvictionError(RuntimeError): """Raised when a self-edit lowers an artifact's retention score below the threshold that admitted its source — i.e. a compression that is really an eviction disguised as a budget win.""" pass @dataclass class MemoryItem: item_id: str text: str embedding_score: float # similarity to current query set generation: int = 0 source_ref: str | None = None # back-pointer to immutable source @dataclass class EditPolicy: theta_retain: float = 0.55 margin_delta: float = 0.10 g_max: int = 2 pinned: set[str] = field(default_factory=set) def revalidate_and_commit( policy: EditPolicy, source: MemoryItem, artifact: MemoryItem, rescore_fn, # callable(text) -> float, embeds artifact vs current query set ) -> MemoryItem: """Gate a rewrite on re-scoring the artifact, not the source.""" artifact.embedding_score = rescore_fn(artifact.text) artifact.generation = source.generation + 1 artifact.source_ref = source.item_id # Rule 1: re-score before commit. A rewrite that drops below threshold is an eviction. if source.embedding_score >= policy.theta_retain and artifact.embedding_score < policy.theta_retain: raise RewriteEvictionError( f"rewrite of {source.item_id} scored {artifact.embedding_score:.2f} " f"< theta_retain {policy.theta_retain:.2f} (source scored " f"{source.embedding_score:.2f}); reject or pin source" ) # Rule 2: margin band — pin source when artifact lands in the danger band. band_lo = policy.theta_retain band_hi = policy.theta_retain + policy.margin_delta if band_lo <= artifact.embedding_score <= band_hi: policy.pinned.add(source.item_id) # Rule 3: cap rewrite lineage depth to bound superlinear drift. if artifact.generation > policy.g_max: if source.item_id not in policy.pinned: raise RewriteEvictionError( f"lineage {source.item_id} exceeded g_max={policy.g_max} " f"without a pinned source; force re-expansion, not re-summarize" ) return artifact # --- example trigger --- if __name__ == "__main__": policy = EditPolicy() src = MemoryItem("M17", "retry wrapper double-wraps client; timeouts fire at 2x", 0.79) art = MemoryItem("M17'", "timeout observed; suspected retry interaction", 0.0) fake_rescore = lambda text: 0.41 # drifted embedding after abstract rewrite revalidate_and_commit(policy, src, art, fake_rescore) # raises RewriteEvictionError ```