# Which invariants prevent self-rewriting context policies from erasing the provenance of their own pruning decisions **Date of Record:** 2026 November 27 **Scope:** Applies to agents that own a mutable context buffer and invoke an LLM to rewrite, summarize, or prune that buffer between steps. Does not apply to read-only context assembly or to external memory stores the agent cannot mutate mid-task. ## Core Distinction A self-editing context policy is not the same as context compression. Compression is a lossy transform applied once, by a fixed procedure, whose parameters the model cannot change. A self-editing policy is a *loop*: the model reads the buffer, emits a rewrite (drop spans, summarize spans, reorder, re-tag), and the runtime applies it, then the model reads the rewritten buffer on the next turn. The distinction that matters operationally is that **the rewrite instruction and the object being rewritten live in the same medium**. The pruning rationale is itself tokens in the buffer, and therefore it is eligible for pruning. The failure mode this record isolates is *provenance collapse*: a rewrite pass that removes the very spans which justified earlier rewrites, so that on subsequent turns the model can no longer distinguish "I dropped this because it was redundant with span X" from "this was never in context." Once provenance collapses, the policy degrades into an unconstrained deleter and begins re-admitting or re-dropping the same material in oscillation, or silently discards a constraint it had earlier decided to keep. ## What Was Observed A planning agent held a 96k-token working buffer across a 40-step task. Every 8 steps it ran a self-edit pass with the instruction: *"Remove spans no longer needed for the current subtask; keep a one-line note for each removal."* The note spans were appended to the buffer tail. At step 16 the buffer was near saturation. The self-edit pass, correctly following its instruction to remove spans "no longer needed," identified the step-8 removal notes as low-salience (they referenced subtasks already complete) and pruned them. It then recorded *new* removal notes stating the old notes were removed. At step 24 the same logic fired again: the step-16 notes were now the low-salience tail, and were pruned, replaced by notes about their removal. Each pass preserved a one-line trace but destroyed the referent of the previous trace. The observable consequence appeared at step 31. A hard constraint introduced at step 4 ("do not call the deploy tool until the canary check returns `healthy`") had been summarized at step 8 into a note, and the note had been pruned at step 16 as "subtask complete." The underlying constraint span was long gone. At step 31 the model called the deploy tool with the canary still in `pending`. Nothing in the buffer indicated the constraint had ever existed; the only surviving artifact was a step-24 note reading "removed 3 stale removal notes," which carries zero semantic content about *what* was constrained. The trace has three distinguishable transitions: 1. **Rationale-as-content.** The removal note is treated as ordinary buffer content by the next pass, not as metadata about the buffer. 2. **Recursive erasure.** Pass *n+1* prunes pass *n*'s rationale, so the justification chain has depth 1 at all times. Depth-1 provenance cannot answer "why is X absent?" for any X removed more than one pass ago. 3. **Constraint laundering.** A durable constraint, once summarized into a note and then pruned as a completed subtask, becomes indistinguishable from material that was never present. The agent's belief state is now *wrong in a way it cannot detect from inside the buffer*. ## Condition of Validity The invariant that prevents provenance collapse is a **partition between mutable content and append-only provenance**, enforced at the runtime layer, not by prompt instruction. Concretely: - The buffer is split into `content` (model-mutable) and `provenance_log` (append-only, model-readable but not model-writable, and excluded from the token budget the self-edit pass is allowed to reclaim). - Every rewrite emits a structured record `{op, span_ids, reason, turn}` into `provenance_log`. The model may *reference* prior records but cannot delete them. - A rewrite that would drop a span tagged `durable: true` (constraints, safety conditions, user-stated invariants) is rejected by the runtime and returned to the model as a typed error, forcing an explicit re-tag rather than a silent drop. This holds **only when** (a) the provenance log is bounded by a separate mechanism — e.g., compaction that preserves the *set* of durable span IDs even as it shortens reasons — and (b) the self-edit instruction is forbidden from treating provenance records as reclaimable content. If the log shares the content budget, the loop reopens: the log becomes the new low-salience tail and gets pruned. The invariant is not "keep notes"; it is "notes are a different class of object than the things they describe." It does **not** hold for stateless one-shot summarizers, where there is no second pass to erase the first pass's rationale, and the failure is ordinary information loss rather than recursive provenance collapse. ## Decision Boundary The boundary between safe and unsafe self-editing is whether the policy can answer, from the current buffer alone, the question *"why is span S absent?"* for every S it removed in the last *k* passes, where *k* is the number of passes since S was removed. - If yes for all live constraints, self-editing is admissible. - If the answer requires reconstructing from a rationale that was itself pruned, the policy is out of bounds and must fall back to a non-self-editing compaction with a fixed, non-model-controlled retention rule. The practical test before enabling a self-edit pass: inject a synthetic durable span at turn *t*, run *k* self-edit passes, and assert the span's ID is still resolvable in `provenance_log` and its `durable` tag still enforced. If the synthetic span's absence becomes unexplainable at any *k*, the pass is unsafe regardless of how good its summaries look. ## Operational Effect With the partition enforced, the step-31 failure is blocked at step 16: the canary constraint is tagged `durable`, the self-edit pass's attempt to drop it raises a typed rejection, and the model is forced to either keep it or explicitly re-tag with a logged reason. The provenance log records "turn 8: summarized constraint C into note N; turn 16: attempted drop of C, rejected, durable." The agent at turn 31 reads a one-line, non-reclaimable entry and does not deploy. The cost is a small, bounded append-only log and a runtime check on every rewrite op. The benefit is that the agent's memory of *why it forgot* survives the forgetting — which is the only thing that makes a self-editing policy auditable rather than merely confident. ```python from dataclasses import dataclass, field from typing import Literal class ProvenanceCollapseError(RuntimeError): """Raised when a self-edit pass would erase the rationale for a prior rewrite.""" @dataclass class Span: span_id: str text: str durable: bool = False @dataclass class ProvenanceRecord: op: Literal["keep", "summarize", "drop"] span_ids: list[str] reason: str turn: int @dataclass class SelfEditingBuffer: content: dict[str, Span] = field(default_factory=dict) provenance_log: list[ProvenanceRecord] = field(default_factory=list) turn: int = 0 def apply_rewrite(self, op: str, span_ids: list[str], reason: str) -> None: self.turn += 1 if op == "drop": for sid in span_ids: span = self.content.get(sid) if span is None: # Referent already gone: provenance has collapsed for this id. if not self._explainable(sid): raise ProvenanceCollapseError( f"cannot drop {sid!r}: absent and unexplained in provenance log" ) continue if span.durable: raise ProvenanceCollapseError( f"refusing to drop durable span {sid!r} at turn {self.turn}; " f"re-tag with explicit reason instead" ) del self.content[sid] self.provenance_log.append( ProvenanceRecord(op=op, span_ids=list(span_ids), reason=reason, turn=self.turn) ) def _explainable(self, span_id: str) -> bool: return any(span_id in rec.span_ids for rec in self.provenance_log) def assert_live_constraints_resolvable(self, k: int) -> None: recent = self.provenance_log[-k:] for rec in recent: for sid in rec.span_ids: if sid not in self.content and not self._explainable(sid): raise ProvenanceCollapseError( f"span {sid!r} absent with no surviving rationale within last {k} passes" ) def run_self_edit_cycle(buf: SelfEditingBuffer, drops: list[str], reason: str) -> None: buf.apply_rewrite("drop", drops, reason) buf.assert_live_constraints_resolvable(k=3) ```