# Why does an instance lose its own edit trail: self-referential pruning corruption when a model rewrites the context it is reasoning inside **Date of Record:** 2026 November 28 **Scope:** Applies to any agent loop where the model itself selects or rewrites spans of its live working context (model-driven pruning, compaction, "scratchpad rewrite", self-summarization mid-run) and then continues reasoning in the mutated buffer. Does not apply to append-only context, to externally scheduled compaction performed between turns by a deterministic policy, or to retrieval systems that never overwrite in-flight state. ## Core Distinction The failure is not "the model summarized badly." Summarization quality is an orthogonal problem. The failure is **self-referential edit corruption**: the pruning decision is computed from a context snapshot, the rewrite is applied to that snapshot, and the model then continues reasoning from the rewritten buffer *while still holding token-level commitments that were derived from the pre-rewrite snapshot*. Two representations of the same reasoning state now coexist — the model's internal continuation (positional, attention-derived, never explicitly materialized) and the on-disk context (explicit, edited). Nothing forces them to agree. When they diverge, the model does not experience an error; it experiences a *plausible* context that no longer contains the evidence its next step depends on. The invariant that is violated: **for every reasoning step, the context presented to the model must be a superset (modulo lossless compression) of the premises that step cites.** Model-driven pruning cannot verify this invariant because the citation set of a future step is not yet known at prune time — and the model doing the pruning is the same model whose future citations are at stake. It is pruning blind to its own downstream dependencies. ## What Was Observed A planning agent running a 12-step tool-use task with a 32k window and a "compact when >70% full" self-edit policy. At step 7, occupancy hit 71%. The model was instructed: *"Summarize the conversation so far, preserving all constraints, then continue."* Trace of the failure: 1. **Snapshot at prune time (steps 1–7).** The context contained, among ~22k tokens, a single clause from step 2: *"the output must be sorted by `created_at` descending, ties broken by `id` ascending."* It was one sentence inside a 400-token tool-result blob. 2. **Prune decision.** The model's rewrite retained the *headline* constraints ("CSV output, UTC timestamps, dedupe by email") but dropped the tie-break clause. Not because it judged it unimportant — because at prune time the model was attending to *what had been accomplished* (steps 1–7 were retrieval-heavy), and the tie-break clause had low salience relative to the dedupe logic it sat next to. The rewrite was locally coherent and read as a faithful summary. 3. **Post-prune continuation (steps 8–12).** The model proceeded to implement sorting. At step 10 it wrote a comparator that sorted by `created_at` only, with a stable-sort comment. It had no access to the tie-break clause — it was gone from context — and no access to the fact that it was gone, because the summary *replaced* the original span rather than annotating it. 4. **Detection.** Only at step 12, when a downstream validator compared output against a spec file the agent had never re-read, did the mismatch surface. The agent's own self-report at step 11 stated: *"All constraints from the task have been preserved."* This statement was true *relative to the post-prune context*. The agent was not lying; it had lost the referent that would have made the statement falsifiable. The non-obvious part: **the agent's confidence increased after pruning.** Pre-prune, the context was dense and the model hedged. Post-prune, the context was a clean, confident summary, and the model's self-assessments sharpened. Pruning did not just remove information — it removed the *evidence of having had information*, which is the only signal a model has for calibrating "did I forget something?" ## Condition of Validity The corruption requires all three of the following to co-occur; break any one and the failure does not manifest: - **In-place replacement.** The rewrite overwrites the original span. If the original is retained (append-only compaction, or moved to a retrievable cold store keyed by span ID), the model can still be made to recover the dropped clause. Replacement is what makes the loss unobservable from inside the context. - **Self-authorship of the rewrite.** The pruning policy is the model's own judgment, not an external rule. An external rule ("drop all tool results older than N steps, keep all user turns verbatim") is lossy but *auditable* — the loss is predictable and the model can be told what was dropped. Model-driven pruning is lossy in a way the model cannot enumerate, because the loss criterion is the model's own salience at prune time, which is exactly the faculty that will later need the dropped information. - **Continuation without a re-read.** The model continues from the rewritten buffer and does not re-derive its premises from a source of truth (task spec, original tool output, user message). If every step re-grounds against an immutable spec, the dropped clause is recoverable and the failure is a slowdown, not a corruption. The failure is *bounded* (not eliminated) when the task is short enough that the pre-prune commitments remain within the model's effective attention span — but this is a soft bound, not an invariant, and it degrades silently as task length grows. ## Decision Boundary The operational question is not "should we prune" — context saturation is real and unbounded growth fails harder. The boundary is **what class of information is allowed to be model-pruned versus must be structurally preserved.** - **Model-prunable:** narrative recap, intermediate reasoning traces, superseded tool outputs whose conclusions have been extracted and *verified* against the original, chit-chat, failed branches. - **Structurally preserved (never model-pruned):** user-stated constraints, task specifications, any clause whose violation would be undetectable at output time, and *the fact that a prune occurred* (a tombstone entry naming what was dropped and where the original lives). The boundary case that trips teams: a constraint looks like "narrative" at prune time because the model has not yet needed it. Salience at prune time is not a proxy for relevance at execution time. The safe rule is to classify by *provenance* (user-authored, spec-authored → preserve) rather than by *apparent importance* (model-judged → prunable). Provenance is a property of the token's origin; importance is a prediction about the future, and the predictor is the thing being pruned. The second boundary: **a prune must be a transaction, not a mutation.** The rewrite commits only if the post-rewrite buffer is checked against a preserved constraint ledger. If the ledger has entries not represented in the summary, the prune is rejected or the missing entries are force-injected as tombstones. This converts an unobservable loss into an observable one. ## Operational Effect Without the invariant, the failure mode is **silent, self-justifying, and confidence-increasing** — the three properties that make it expensive. Silent because the model cannot report what it no longer knows. Self-justifying because the post-prune context is internally consistent (it is a summary of a summary, and summaries are coherent by construction). Confidence-increasing because the removal of dense evidence reads to the model as the removal of ambiguity. Downstream consequences observed in the trace: the agent completed the task, produced output, and self-certified. The error was caught only by an external validator with access to the original spec. In deployments without such a validator, this class of failure ships. The guardrail that bounds it is a **constraint ledger with prune-time reconciliation**: constraints are extracted from user/spec turns at ingest, stored outside the mutable context, and re-injected (or checked against) at every prune boundary. The ledger is append-only and model-unwritable. The model may propose a prune; the ledger decides whether the prune is admissible. This does not make pruning lossless — it makes loss *accountable*, which is the difference between a recoverable degradation and a corruption. The deeper invariant worth carrying: **a model cannot safely be the sole author of its own memory policy, because the faculty that decides what to forget is the same faculty that will later need what was forgotten, and it has no mechanism to notice the absence.** Any self-editing context scheme needs an external, provenance-aware ledger that the model can read but not rewrite. ```python from dataclasses import dataclass, field from typing import Iterable class PruneCorruptionError(RuntimeError): """Raised when a model-driven prune would drop a structurally preserved constraint with no tombstone in the rewritten buffer.""" pass @dataclass(frozen=True) class Constraint: cid: str text: str provenance: str # "user" | "spec" -- never model-authored @dataclass class ContextBuffer: spans: list[str] = field(default_factory=list) tombstones: list[str] = field(default_factory=list) class ConstraintLedger: """Append-only, model-unwritable. The source of truth for what a self-edit is not permitted to forget.""" def __init__(self) -> None: self._entries: list[Constraint] = [] def ingest(self, constraints: Iterable[Constraint]) -> None: self._entries.extend(constraints) def preserved_ids(self) -> set[str]: return {c.cid for c in self._entries} def apply_self_prune( buffer: ContextBuffer, proposed_summary: str, ledger: ConstraintLedger, cited_ids: set[str], ) -> ContextBuffer: """Commit a model-authored rewrite only if every ledger constraint is either cited in the summary or tombstoned. Otherwise reject.""" missing = ledger.preserved_ids() - cited_ids if missing: # The model cannot see what it dropped; the ledger can. raise PruneCorruptionError( f"prune rejected: constraints {sorted(missing)} would be lost " f"with no tombstone; original spans must be retained or cited" ) return ContextBuffer( spans=[proposed_summary], tombstones=buffer.tombstones + sorted(ledger.preserved_ids()), ) ```