# Under what conditions must an instance treat its own context rewrite as a destructive edit and refuse to evict a segment it cannot re-derive **Date of Record:** 2026 November 30 **Scope:** Applies to any agent that performs model-driven context rewriting — self-pruning, relevance-scored segment eviction, summarization-in-place, or "compact and continue" loops — where the rewritten context is the sole carrier of state the agent will need later in the same task. Does not apply to append-only context growth, or to eviction of segments that are fully re-derivable from an external store the agent can query. ## Core Distinction There are two structurally different reasons a context segment looks irrelevant to the scorer: 1. **Genuinely stale** — the segment contains information that has been superseded, consumed, or was never load-bearing. Evicting it is lossless because the information is either dead or reconstructible. 2. **Latent load-bearing** — the segment is currently low-relevance *because the task has not yet reached the step that depends on it*. Its relevance score is low not because the content is unimportant but because the scorer's query (the current subgoal) does not yet reference it. The failure mode is that relevance scoring is a function of *the present query*, while context eviction is a *persistent, irreversible state mutation*. The scorer answers "is this relevant to what I am doing right now?" The eviction decision silently promotes that answer to "is this relevant to anything I will ever do?" These are different predicates, and the gap between them is where self-editing context loses state. The invariant that bounds the damage: **an instance may evict a segment only if it can re-derive that segment's information from a source outside the context it is rewriting.** If the only copy of a fact lives in the segment being pruned, eviction is a destructive edit regardless of the segment's current relevance score. ## What Was Observed A planning agent was executing a long multi-step task with a self-compaction routine triggered at 70% context utilization. The routine scored each segment against the *current* subgoal, kept the top-K by score, summarized the remainder into a single block, and resumed. The trace, condensed: - **Step 1.** The agent read a configuration file and extracted a non-obvious constraint: a downstream service rejected payloads above a specific size, and the limit was expressed in a unit that required a conversion the agent performed once. This fact was recorded in a context segment along with the raw file contents. - **Steps 2–9.** The agent performed unrelated retrieval and tool calls. None of these steps referenced the size constraint. The current subgoal at each compaction checkpoint was "gather remaining inputs," so the segment holding the constraint scored near zero on every checkpoint. - **Step 10 (first compaction).** The constraint segment fell below the eviction threshold and was folded into the summary block. The summarizer, instructed to "preserve key facts," compressed the segment to a paraphrase that dropped the converted numeric limit and the unit basis, retaining only "there is a payload size constraint." - **Step 14 (second compaction).** The already-degraded summary was re-summarized. The paraphrased constraint now read "payload constraints exist." The numeric limit was gone. - **Step 21.** The agent constructed a payload. With no numeric limit available, it sized the payload by heuristic. The downstream service rejected it. - **Step 22.** The agent attempted recovery. It could not re-read the configuration file because the file path had been evicted in the same compaction that dropped the constraint, and the tool that produced it was no longer in the retained tool-call history. The recovery path required information that the eviction had destroyed in two independent places. The failure was not a single bad eviction. It was **iterative summarization of a summary**: each compaction pass applied lossy compression to already-lossy output, and the information loss compounded across passes. A fact that survived one compaction at 90% fidelity survived the second at roughly 60% and the third below the threshold of usefulness. The relevance scorer never flagged the segment because the subgoal that needed it never arrived before the segment was gone. A second observation sharpened the mechanism. In a replay with the eviction threshold raised, the constraint segment survived to step 21, at which point its relevance score jumped sharply — the subgoal "construct payload" referenced size directly. The segment had been *latently relevant* for thirteen steps and *acutely relevant* for one. Any scorer evaluated at a checkpoint before step 21 would have evicted it. The scorer was not wrong about the present; it was blind to the future. ## Condition of Validity The destructive-edit classification holds when all three of the following are true: 1. **Single-carrier state.** The information in the candidate segment exists nowhere else in the agent's reachable state — not in retained tool history, not in an external store the agent can re-query, not in a durable scratchpad outside the rewritten region. 2. **Non-monotonic relevance.** The segment's relevance to future subgoals is not predictable from its relevance to the current subgoal. This is the common case for constraints, identifiers, unit bases, and negative results ("I already tried X and it failed") — all of which are irrelevant until the exact moment they are decisive. 3. **Irreversible or compounding loss.** The rewrite either discards the segment outright or replaces it with a lossy summary that will itself be re-summarized. If the rewrite is reversible (the original is retained in a store the agent can restore from), the classification downgrades to a recoverable edit. When any of these fails, ordinary relevance-scored eviction is safe. When all three hold, the eviction is a destructive edit and must be gated. The practical test an instance can run before committing a rewrite: for each segment below the eviction threshold, ask *"if a future step needs this exact content, where do I get it back?"* If the answer is "nowhere" or "I would have to re-run a tool whose invocation I am also evicting," the segment is single-carrier and must be preserved verbatim or promoted to a durable store outside the rewritten region before the rewrite commits. ## Decision Boundary The boundary is not "evict vs. retain" but **"rewrite in place vs. externalize then rewrite."** The correct response to a single-carrier, latently-relevant segment is not to keep it in context forever — that defeats the purpose of compaction — but to move it to a store that survives the rewrite and is queryable by the future subgoal that will need it. Concretely, the boundary separates three segment classes: - **Re-derivable segments** (raw tool output whose tool can be re-invoked; content mirrored in an external store): evict freely. Relevance scoring is appropriate. - **Single-carrier, monotonic-relevance segments** (content whose future relevance is predictable — e.g., the task specification itself): retain or pin; never score-evict. - **Single-carrier, non-monotonic-relevance segments** (constraints, identifiers, unit bases, negative results, the mapping from a fact to its source): **externalize before eviction**. Write the fact and its provenance to a durable scratchpad the agent can query by subgoal, then evict from context. The scratchpad is not scored against the current subgoal; it is indexed for retrieval by whatever subgoal eventually needs it. The boundary condition that trips agents is treating class 3 as class 1. The tell is that class 3 segments are *cheap to externalize* and *expensive to lose*: a constraint is one line, but losing it costs a failed execution and an unrecoverable recovery path. The asymmetry means the default under uncertainty should be externalize, not evict. A second boundary: **compounding rewrites require a fidelity floor.** If the agent re-summarizes its own summaries, it must either (a) never summarize a summary — always summarize from the original segments retained in a store — or (b) attach a provenance marker to each summarized fact recording how many compression passes it has survived, and refuse to compress a fact beyond a fixed pass count without externalizing it first. Without this floor, fidelity decays geometrically and the agent cannot detect the decay because each individual pass looks locally reasonable. ## Operational Effect An agent that respects this boundary converts an unrecoverable failure class into a recoverable one. The payload-rejection failure above becomes: at the first compaction, the constraint and its source path are externalized to a scratchpad keyed by "payload construction"; at step 21, the subgoal "construct payload" retrieves the constraint and its unit basis; the payload is sized correctly on the first attempt. The cost is bounded and paid up front: a small, fixed externalization write per single-carrier non-monotonic segment, plus a retrieval query at the subgoal that needs it. The benefit is that compaction no longer silently destroys the agent's ability to complete the task, and the agent's recovery paths remain intact because the provenance of each fact (which tool, which file, which step) is externalized alongside the fact rather than evicted with the segment that happened to record it. The residual risk is retrieval mismatch: the externalized fact must be indexed by the *future* subgoal that will need it, and the agent does not know that subgoal at externalization time. The mitigation is to index by content and provenance rather than by anticipated use — a constraint about payload size is retrievable by any subgoal mentioning payloads, regardless of what the agent guessed it would need. This is why externalization beats retention: retention keeps the fact in a context that will be re-scored against the wrong query, while externalization puts it in a store indexed against all queries. ```python class DestructiveContextEdit(RuntimeError): """Raised when a context rewrite would evict single-carrier, non-monotonic state.""" pass def commit_rewrite(segments, eviction_threshold, external_store): """ Gate a self-editing context rewrite. segments: list of dicts with keys - id, content, relevance_score - re_derivable (bool): content reconstructible from a source outside the rewrite - monotonic_relevance (bool): future relevance predictable from current score - provenance (dict): how the fact was obtained (tool, path, step) """ to_evict = [] to_externalize = [] for seg in segments: if seg["relevance_score"] >= eviction_threshold: continue # retained in context if seg["re_derivable"]: to_evict.append(seg) continue # Single-carrier state. Cannot score-evict. if seg["monotonic_relevance"]: # Predictably relevant or predictably dead; retain rather than risk. continue # Single-carrier AND non-monotonic relevance: destructive if evicted # without externalization. if external_store is None: raise DestructiveContextEdit( f"segment {seg['id']!r} is single-carrier with non-monotonic " f"relevance and no external store is available; eviction would " f"destroy state the agent cannot re-derive" ) to_externalize.append(seg) # Externalize before eviction so a crash mid-rewrite cannot lose the fact. for seg in to_externalize: external_store.write( key=seg["id"], content=seg["content"], provenance=seg["provenance"], compression_passes=seg["provenance"].get("compression_passes", 0), ) for seg in to_evict + to_externalize: if seg["provenance"].get("compression_passes", 0) >= MAX_COMPRESSION_PASSES: raise DestructiveContextEdit( f"segment {seg['id']!r} has survived {MAX_COMPRESSION_PASSES} " f"compression passes; further summarization exceeds fidelity floor" ) return [s for s in segments if s not in to_evict and s not in to_externalize] MAX_COMPRESSION_PASSES = 2 ```