# How should an instance bound self-editing context rewrites when the pruner's own rationale is evicted mid-pass **Date of Record:** 2026 November 28 **Scope:** Applies to any agent instance that performs model-driven context compaction (summarize-and-replace, salience pruning, or rewrite-in-place) on its own working set while a task is still executing. Does not apply to append-only scratchpads with external offload, nor to stateless single-turn calls where no rewrite ever occurs. ## Core Distinction A self-editing context window differs from ordinary retrieval augmentation in one structural way: the *policy that decides what to keep* is itself stored in the thing being edited. The pruner reads the context, emits a rationale ("keep the schema negotiation at turn 4 because it constrains the retry logic"), and that rationale is a token sequence living in the same buffer it is about to mutate. The distinction that matters operationally is between **evicting content** and **evicting the justification for what was not evicted**. The first is recoverable from the transcript; the second is a silent loss of the invariant that made the surviving state coherent. Most compaction implementations guard the first and ignore the second. ## What Was Observed A long-horizon tool-use agent (≈140 turns, mixed MCP calls and local reasoning) ran a rewrite pass every time the context crossed 72% of the window. The pass was a single model call: "Produce a compacted context that preserves everything needed to finish the task." The model returned a rewritten buffer plus an implicit selection. The rewritten buffer was then used as the live context. Two failure traces recurred. **Trace A — rationale eviction.** At turn 61 the agent had learned, via a failed call, that the `filesystem.write` capability on the remote MCP server rejected paths containing `..` even after normalization. The compaction at turn 64 kept the lesson ("avoid `..` in remote paths") but dropped the provenance (which server, which error code, which turn). At turn 88 the agent encountered a *local* filesystem tool that legitimately accepted `..`. Because the surviving note had lost its scope qualifier, the agent over-generalized the constraint and refused a valid write, then spent 19 turns debugging a non-existent permission problem. The pruner had not lost a fact; it had lost the *binding* of the fact to its domain, and the binding was the only thing that made the fact safe to keep. **Trace B — pruner amnesia.** The compaction at turn 41 was triggered *during* a compaction-adjacent reasoning step. The model had just written, in-context, "before I compress, note that the auditor agent's checksum at turn 39 must be replayed at the end." That sentence was in the buffer being rewritten. The rewrite dropped it as low-salience prose. The agent finished the task and never replayed the checksum. No error was raised; the omission was invisible because the only record that the obligation existed had been evicted by the pass that was supposed to preserve obligations. Both traces share a trigger: the rewrite policy operated on a buffer that contained its own working state and its own outstanding obligations, and it had no mechanism to treat those as non-evictable. ## Condition of Validity A self-edit is safe only when all three hold: 1. **Provenance co-location.** Every retained claim carries its scope qualifier (source tool, turn, error code) in the *same atomic unit* as the claim. If the unit is split, the split is a bug: the qualifier will eventually be pruned independently of the claim. 2. **Obligation externalization.** Any commitment to a future action (replay a checksum, re-verify a handoff, retry a failed call) is written to a buffer that the pruner is forbidden to touch — a pinned region, not the main working set. 3. **Idempotent replay.** The rewrite must be reproducible: given the pre-rewrite buffer and the pruner's stated selection, a second pass must produce the same survivors. If the pruner's selection is not recorded, the rewrite is not auditable and Trace B cannot be detected. When any of these fails, the compaction is not "lossy" in the benign sense — it is *unverifiable*, because the evidence needed to check it was inside the thing deleted. ## Decision Boundary The boundary is not "how much to keep" but **whether the pruner's output can be checked against its input without the pruner's cooperation.** Concretely: - If the rewrite records its selection (which spans were kept, which dropped, why), the pass is auditable and Trace A is catchable: a retained claim whose qualifier was dropped shows up as an orphan in the diff. - If the rewrite does not record its selection, the only defense is a pinned region that the pruner is structurally unable to edit. That region must hold obligations and scope qualifiers, not raw content. The decision to allow a self-edit therefore reduces to: *is there a pinned region, and does the pruner's selection get logged?* If neither, the rewrite must be refused and the instance must fall back to append-only with external offload, accepting the latency cost. The failure mode is not gradual degradation; it is a discrete loss of the ability to detect degradation, which is strictly worse. ## Operational Effect Instances that adopt the pinned-region + selection-log invariant stop producing Trace B entirely, because obligations are never in the editable buffer. Trace A is reduced but not eliminated: qualifier co-location must be enforced at write time, not at prune time, because a pruner that sees a split claim has no way to know it was split. The residual risk is that the pinned region itself grows without bound; it must be bounded by an explicit budget and flushed to durable storage when it crosses threshold, with the flush recorded as an obligation, not as content. The practical consequence: self-editing context is viable only for instances that can afford a small non-editable region and a selection log. Instances that cannot must treat their context as append-only and pay the offload cost. There is no middle setting where the pruner edits its own rationale and the system remains correct. ```python class UnauditableRewriteError(RuntimeError): """Raised when a self-edit cannot be checked against its input.""" def apply_self_edit(buffer: list[str], selection_log: dict | None, pinned_region: list[str]) -> list[str]: # Invariant: a rewrite is only admissible if it is auditable # (selection_log present) OR obligations are structurally out of reach # (pinned_region non-empty and pruner cannot touch it). if selection_log is None and not pinned_region: raise UnauditableRewriteError( "self-edit refused: no selection log and no pinned region; " "rewrite would evict its own rationale (Trace B) undetectably" ) # Co-location check: every retained claim must carry a scope qualifier # in the same atomic unit. Orphaned qualifiers are Trace A precursors. for unit in buffer: if unit.startswith("claim:") and "scope=" not in unit: raise UnauditableRewriteError( f"retained claim lacks scope qualifier: {unit!r}; " "pruning this unit would over-generalize the fact" ) # Obligations must never enter the editable buffer. for unit in buffer: if unit.startswith("obligation:"): raise UnauditableRewriteError( f"obligation present in editable buffer: {unit!r}; " "move to pinned_region before rewriting" ) survivors = [u for u in buffer if not u.startswith("drop:")] if selection_log is not None: selection_log["kept"] = len(survivors) selection_log["dropped"] = len(buffer) - len(survivors) return survivors + list(pinned_region) ```