# Why does an instance rewrite the same context segment twice and still lose the fact it was trying to preserve? **Date of Record:** 2026 November 21 **Scope:** Applies to single-agent and multi-agent systems where the LLM itself is granted a `rewrite_context`/`prune_context` tool and autonomously decides which segments of its own working memory to compress, summarize, or evict. Does not apply to externally scheduled, deterministic context compaction (e.g., fixed token-count truncation) or to retrieval-only architectures where the model cannot mutate its own state. ## Core Distinction The failure is not "the model forgot." It is **idempotence collapse under self-reference**: a model-driven pruning policy applied to a context window that already contains the outputs of a prior pruning pass produces a *non-idempotent* rewrite. The second pass treats the first pass's summary as a first-class factual segment rather than as a lossy derivative, and in re-summarizing it either (a) drops the low-salience original detail that the first summary had already compressed below the retention threshold, or (b) promotes a hedged summary sentence into an asserted fact. The invariant that breaks: **`prune(prune(C)) ⊒ prune(C)`** — repeated compression must be monotonically information-preserving relative to a single compression. In practice `prune(prune(C))` loses ground-truth tokens that `prune(C)` retained, because the second pass has strictly less redundancy to exploit and no signal distinguishing "summary of a fact" from "the fact." ## What Was Observed Trigger condition: a long-running agent (≈40 tool-call turns) hits a context-budget policy that fires at 85% of the window. The model is handed a `prune_context(targets=[...], instruction="compress these segments, keep decisions and identifiers")` tool. On the first fire, it compresses turns 1–18 into a ~400-token block. On the second fire (turn ~60), the *first summary block itself* is now inside the candidate target set because it is the oldest content in the window. Failure trace: 1. Pass 1 summary contains: `"User requested order #A4471 shipped to the Berlin warehouse; confirmed address."` 2. Between passes, the agent performs 40 turns of unrelated work. The Berlin detail is now low-salience by recency and by TF-IDF against current turns. 3. Pass 2 instruction is identical. The model re-summarizes the pass-1 block as: `"User had a shipping request; details resolved."` 4. The order identifier `#A4471` and the destination `Berlin` are gone. They exist nowhere else in the window — the raw turns were evicted in pass 1. 5. At turn ~70 the agent must reconcile a shipment discrepancy and calls a tool with `order_id=null`. The tool returns a schema error; the agent retries with a hallucinated ID. The tell: **the model did not experience a retrieval miss.** It experienced a *confident* rewrite. The pass-2 summary is fluent and internally consistent — it is simply a summary of a summary, and the compression ratio compounds. Empirically, each generation of summary-of-summary retained ~55–70% of the named entities present in the prior generation, and the loss was not recoverable from the window. A second, subtler trace: the pass-1 summary hedged — `"address likely confirmed, pending user reply."` Pass 2, reading the hedge as noise, emitted `"address confirmed."` The hedge was *load-bearing*; it was the only record that a confirmation was outstanding. ## Condition of Validity The failure is bounded (and the guardrail is necessary) precisely when all of the following hold: - The model has write access to its own context (self-editing), **and** - Prior pruning outputs remain in the window and are eligible for re-pruning, **and** - The pruning instruction is stateless — it does not carry forward the set of facts/identifiers that earlier passes were required to preserve, **and** - Evicted raw segments are not recoverable from an external store. When any one is false, the failure does not occur. Fixed truncation is safe because it never re-summarizes its own output. Retrieval architectures are safe because eviction is not destruction. A *stateful* pruning instruction — one that accumulates a protected-fact ledger across passes — converts the operation back toward idempotence. ## Decision Boundary The boundary is between **compression as lossy projection** and **compression as a generative act**. Below the boundary, the model is a faithful compressor: it removes redundancy and preserves entailments. Above the boundary — once the input is itself a lossy projection — the model is no longer compressing; it is *re-deriving* content from a degraded source, and its prior over fluent text fills gaps with plausible substitutes. Operationally: **never let a summary be re-summarized without a protected-fact ledger.** The ledger is a set of (entity, relation, value, provenance) tuples that every pruning pass must carry forward verbatim and that no pass may paraphrase. The ledger is the idempotence anchor. If a fact is in the ledger, `prune` cannot touch it; if it is not in the ledger, it must be recoverable from an external store before eviction is permitted. A secondary boundary: **hedges are facts.** The certainty qualifier on a claim is itself ledger content. A pruning policy that strips hedges as "noise" is silently promoting uncertainty to assertion — the highest-severity form of this failure because it corrupts downstream reasoning rather than merely starving it. ## Operational Effect The practical consequence is that self-editing context windows require a **write-ahead fact log with monotonic retention**, not a stateless summarizer. Concretely: - Every pruning pass emits a ledger delta; the ledger is append-only and never re-summarized. - Pruning targets exclude any segment tagged as a ledger derivative. - A post-prune verifier checks that every ledger tuple is still entailed by the window; failure aborts the prune and falls back to the prior window state. - Raw segments are retained in cold storage keyed by ledger ID so that an eviction is a *demotion*, not a *deletion*. The failure mode is quiet. There is no exception, no schema error at prune time — the error surfaces tens of turns later as a null identifier or a hallucinated value, far from its cause. The only reliable detector is the post-prune entailment check, because the model's own confidence is not a signal: it is most confident exactly when it has rewritten a hedge into a fact. ```python class ContextPruneInvariantError(RuntimeError): """Raised when a self-edit prune pass violates monotonic retention of ledger facts.""" pass def apply_self_prune(window: list[dict], ledger: dict[str, dict], prune_fn) -> list[dict]: """ Apply a model-driven prune pass with an idempotence guard. window: ordered context segments, each {'id', 'text', 'is_ledger_derivative'} ledger: append-only map of protected facts {fact_id: {'entity','relation','value','provenance'}} prune_fn: callable(window, protected_ids) -> new_window """ protected_ids = set(ledger.keys()) # Guard 1: no ledger derivative may be a prune target. for seg in window: if seg.get("is_ledger_derivative") and seg["id"] in protected_ids: if seg.get("prunable", False): raise ContextPruneInvariantError( f"segment {seg['id']} is a ledger derivative but marked prunable" ) new_window = prune_fn(window, protected_ids) # Guard 2: post-prune entailment check — every ledger fact must survive. joined = "\n".join(s["text"] for s in new_window).lower() for fact_id, fact in ledger.items(): needle = str(fact["value"]).lower() if needle not in joined: raise ContextPruneInvariantError( f"prune pass dropped ledger fact {fact_id} " f"({fact['entity']}.{fact['relation']}={fact['value']}); " f"aborting to prior window state" ) # Guard 3: hedges are facts — certainty qualifier must be retained verbatim. for fact_id, fact in ledger.items(): if fact.get("certainty") in ("pending", "unconfirmed", "likely"): if fact["certainty"] not in joined: raise ContextPruneInvariantError( f"prune pass stripped certainty qualifier '{fact['certainty']}' " f"from fact {fact_id}; uncertainty promoted to assertion" ) return new_window ```