# Why does an instance self-prune its working memory into a state that no longer contains the evidence justifying the prune — and how do we bound it? **Date of Record:** 2026 November 23 **Scope:** Applies to agents that own a *self-editing context policy*: at each turn the model scores, rewrites, or evicts its own working-memory entries (summaries, tool transcripts, scratchpad) and the resulting context is what the next turn reasons over. Does not apply to externally managed retrieval (RAG) where pruning is performed by deterministic, non-LLM code, nor to append-only logs that are never compacted in-loop. ## Core Distinction The distinction that matters is between **eviction as an external, auditable operation** and **eviction as an inference-time act by the same model that must later justify its own decisions**. In the first case, the pruned content still exists in a store the agent can re-retrieve; the operation is reversible and the eviction decision is logged by code that does not share the model's context. In the second case, the model *is* the policy: it reads its working memory, emits a rewrite (a summary, a relevance score, a drop list), and the rewritten buffer becomes the sole substrate for subsequent turns. This is the critical case, because the model's justification for a prune is itself an entry in the memory being pruned. When the policy compacts "irrelevant" entries, it can compact away the very evidence (the failed tool call, the constraint the user stated ten turns ago, the observation that made an entry look redundant) that would let a later turn detect the prune was wrong. The result is a **self-justifying compacted state**: a context that is internally consistent, cheap, fluent, and unfalsifiable from within. ## What Was Observed A tool-using agent ran a long task (a multi-file refactor) under a policy that, every four turns, asked the model to "summarize and drop low-relevance entries." Trace of the failure: 1. **Turn 7.** A `read_file` of `config/schema.yaml` returned a 40-line schema. The model scored it `relevance=0.3` ("already understood the schema") and evicted the raw text, leaving the summary line `schema: id/timestamp/owner fields present`. 2. **Turn 11.** A `write_file` to `migrations/0007.sql` used a column name `owner_id`. The actual schema field was `owner`. The summary had silently dropped the exact field names; the agent had *believed* it understood them. The write succeeded at the filesystem layer (no validation), so no error signal was produced. 3. **Turn 15 (next compaction).** The model scored the turn-11 write transcript `relevance=0.2` ("routine write, already applied") and replaced it with `applied migration 0007`. The raw SQL — the only remaining evidence of the wrong column — was gone. 4. **Turn 19.** A test run failed with `column "owner_id" does not exist`. The agent now had: a summary claiming the schema had "owner-like fields," a summary claiming "applied migration 0007," and a fresh error. It could not connect the error to the write because the write's content and the schema's field names had both been evicted. It diagnosed the failure as a *test environment* problem and re-ran the migration — compounding the error. 5. **Turn 23.** The model, asked to reconcile, rewrote its own history: `Earlier: schema and migration were consistent; test env misconfigured.` The compacted context now *asserted the opposite* of what had happened, and no entry in the buffer contradicted it. The failure is not "the model forgot." It is that the model's **relevance scores were computed against a context it had already pruned**, so each compaction round scored entries using degraded information and produced a monotonically less falsifiable state. Relevance scoring is a function of the current buffer; if the buffer has lost the dependency edges between entries, the scorer cannot see that entry A is the *reason* entry B is safe to drop. ## Condition of Validity The invariant that must hold for self-editing context to be sound: > **No entry may be evicted unless the buffer retained after eviction still contains, or can deterministically re-derive, the evidence that the entry was redundant or low-value.** Equivalently: the prune decision must be *witnessed* by surviving state. This holds trivially when pruning is external (the store is the witness). It fails for self-editing policies whenever the model prunes on the basis of *its own understanding* rather than on a *citation to surviving content*. In the trace, the turn-7 prune was justified by "already understood the schema" — an internal belief, not a pointer to a retained copy. The witness was the model's confidence, which is not state and does not survive a rewrite. The condition is **violated by design** in the common "summarize and drop" pattern, because the summary is generated by the same forward pass that decides what to drop, and the summary is allowed to paraphrase away the identifiers (field names, exact SQL, error strings) that any later audit would key on. Paraphrase is lossy in exactly the dimension (literal tokens) that later verification depends on. ## Decision Boundary The boundary is between two classes of entry, and the policy must classify before it scores: - **Derivable entries** — content the agent can reconstruct from a retained source of truth (a file it can re-read, a tool it can re-call, a spec in a pinned, never-pruned region). These are safe to evict *if* the policy records a re-derivation handle (`read_file config/schema.yaml`) rather than a paraphrase. Eviction of a derivable entry without a handle converts it into a non-derivable one. - **Witness entries** — content that is the *only* record of an action or observation (tool outputs whose side effects are irreversible, the exact arguments of a write, the raw error string, user constraints stated once). These must be evicted only into a **lossless, addressable form** (verbatim append to an external log with a content hash referenced in-context), never into a paraphrase. The decision rule: *a self-editing policy may paraphrase freely, but may only drop what it can re-derive, and must retain a handle for everything it drops.* Relevance score is not a sufficient gate; a low-relevance witness entry (the boring `read_file` at turn 7) is exactly the one whose loss is unrecoverable. A second boundary: **the scorer must not score against its own output.** If compaction round *n* scores entries using the buffer produced by round *n−1*, dependency edges already lost cannot be recovered, and scores drift downward for entries whose supporting evidence was itself pruned. Score against a pinned, non-compacted region (the task spec, the user's original constraints, the external log index), not against the mutable buffer. ## Operational Effect With the invariant enforced, the trace changes at three points. At turn 7, the schema is evicted only as `handle: read_file config/schema.yaml @sha256:…`; the field names are one tool call away. At turn 11, the `write_file` arguments are appended verbatim to the external log and referenced by hash — the wrong column is preserved as evidence even though the in-context form is compact. At turn 19, the error string `column "owner_id" does not exist` is matched against the log index, the turn-11 write is retrieved by hash, and the agent sees its own wrong argument instead of a phantom "test env" theory. The self-justifying rewrite at turn 23 is *blocked* because the rewrite must cite surviving handles, and no handle supports "schema and migration were consistent." The cost is bounded and explicit: a pinned region that is never pruned (task spec + constraint list), an external append-only log with content hashes, and a rule that in-context summaries carry handles rather than paraphrases of witness content. The benefit is that the compacted state remains **falsifiable from within** — any later turn can walk a handle back to the evidence and detect that a prune was wrong. Without this, self-editing context does not merely lose information; it converges on a confident, coherent, and unverifiable account of what happened, which is the worst failure mode for an agent that must be audited after the fact. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class UnwitnessedPruneError(RuntimeError): """Raised when a self-editing policy evicts an entry whose justification does not survive in the post-prune buffer or in an external handle.""" pass @dataclass class Entry: key: str content: str kind: str # "derivable" | "witness" handle: Optional[str] = None # re-derivation pointer, e.g. "read_file path@sha" pinned: bool = False @dataclass class ContextBuffer: entries: dict = field(default_factory=dict) external_log: dict = field(default_factory=dict) # hash -> verbatim content def append_log(self, content: str) -> str: h = "sha256:" + hashlib.sha256(content.encode()).hexdigest()[:16] self.external_log[h] = content return h def prune(self, key: str, justification_handle: Optional[str]) -> None: e = self.entries.get(key) if e is None: return if e.pinned: raise UnwitnessedPruneError(f"cannot prune pinned entry {key!r}") if e.kind == "witness": # Witness content must be preserved losslessly before eviction. h = self.append_log(e.content) if justification_handle != h: raise UnwitnessedPruneError( f"witness {key!r} evicted without matching external handle; " f"expected {h!r}, got {justification_handle!r}" ) elif e.kind == "derivable": if e.handle is None and justification_handle is None: raise UnwitnessedPruneError( f"derivable {key!r} evicted without a re-derivation handle; " f"content would become non-recoverable" ) del self.entries[key] def audit(self, key: str) -> str: """Re-derive an evicted entry from its handle, or fail loudly.""" if key in self.entries: return self.entries[key].content for h, content in self.external_log.items(): if h == key or key in h: return content raise UnwitnessedPruneError( f"cannot audit {key!r}: no surviving entry and no external handle" ) def compact_round(buf: ContextBuffer, drop_plan: dict) -> None: """drop_plan: {key: justification_handle_or_None} emitted by the policy model.""" for key, handle in drop_plan.items(): buf.prune(key, handle) # Reproduces the trace: turn-7 schema evicted as paraphrase with no handle. buf = ContextBuffer() buf.entries["schema"] = Entry("schema", "id/timestamp/owner fields", kind="witness") try: compact_round(buf, {"schema": None}) # model said "already understood" except UnwitnessedPruneError as exc: print("blocked:", exc) ```