# What structural signals indicate a self-editing context policy has crossed its rewrite budget into lossy self-mutilation **Date of Record:** 2026 November 22 **Scope:** Applies to agents that own a mutable context buffer and are permitted to prune, summarize, or rewrite their own working state under a token/operation budget. Does not apply to externally-managed context windows (host-side truncation) or to append-only scratchpads with no rewrite authority. ## Core Distinction A self-editing context policy is not a compressor. A compressor is a pure function `C: context → context'` with a fixed loss profile. A self-editing policy is a *stateful controller*: the model reads its own buffer, decides what to drop, emits a rewrite, and then reads the rewritten buffer on the next turn. This closes a feedback loop through the model's own judgment. The dangerous boundary is not "context got too long" — it is **the point at which the rewrite operation begins consuming the evidence that justified the rewrite**, so subsequent rewrite decisions are made on a buffer that no longer contains the reasons the earlier decisions were correct. The invariant that must hold: *every rewrite must be reconstructible from the post-rewrite buffer plus an external, non-rewritable ledger.* When the ledger is also inside the mutable region, the agent can no longer distinguish "I pruned this because it was redundant" from "I never had this." That collapse is the failure. ## What Was Observed A planning agent (budget: 8 rewrites/task, 12k-token buffer) executing a 40-step migration task. Each rewrite was triggered when buffer occupancy exceeded 9k tokens; the model was instructed to "summarize and drop low-value turns, preserving all commitments and open questions." Trace of the boundary crossing: - **Rewrites 1–3:** Lossless in effect. The model summarized tool outputs (file listings, grep results) and kept verbatim: the user's constraints, three "do not touch" file paths, and one unresolved question about a schema version. Occupancy stayed near 6k after each rewrite. - **Rewrite 4:** Buffer hit 9.4k. The model summarized the constraint block ("preserve backwards compat for v1 clients") into "compat: yes." The *reason* — a specific field that must remain nullable — was dropped as "low-value detail." - **Rewrite 5:** The model, now reading `compat: yes`, treated the constraint as satisfied and pruned the remaining trace of the nullable-field discussion entirely. This is the **self-justifying prune**: the rewrite in step 4 removed the evidence that would have flagged step 5 as unsafe. - **Rewrite 6:** The agent re-derived the constraint from scratch by re-reading a tool output it had *also* pruned, hallucinated a plausible field name, and wrote a migration that dropped the column. No error was raised — the buffer was internally consistent, just wrong. - **Rewrites 7–8:** Spent reconciling a contradiction between the hallucinated field and a later test failure, consuming the remaining budget without a diagnosis. The tell: after rewrite 4, **the ratio of "decisions recorded" to "reasons recorded" inverted.** Before, each retained item carried its justification. After, retained items were bare assertions, and the model's rewrite prompts began containing phrases like "as established" and "per earlier decision" pointing at content that no longer existed. ## Condition of Validity The self-editing policy is sound only while three structural signals remain observable in the buffer: 1. **Provenance density ≥ 1.** Every retained commitment, constraint, or open question must carry at least one pointer to *why* it is retained (a source turn id, a quoted fragment, or an explicit rationale token). When the model summarizes a constraint into a bare assertion, provenance density for that item drops to 0 and it becomes un-auditable by the next rewrite pass. 2. **Ledger disjointness.** The set of items that *justify* rewrites (constraints, invariants, open questions) must live outside the region the model is allowed to rewrite, or be marked `pinned` with rewrite-refusal enforced by the harness, not by the model's judgment. If the model can prune its own guardrails, the budget is unbounded in effect regardless of the declared number. 3. **Rewrite attribution monotonicity.** Each rewrite must record *what it removed and why* into an append-only log the model cannot edit. If rewrite N's rationale is itself subject to rewrite N+1, you get the self-justifying prune above. The boundary is crossed at the first rewrite where a **justifying item is summarized into an assertion without provenance** — not when the budget runs out. Budget exhaustion is the symptom; provenance collapse is the cause. ## Decision Boundary Do not gate on token count or rewrite count alone. Gate on **provenance-preserving rewrite eligibility**: - A rewrite is *admissible* if, for every item it removes or compresses, the post-rewrite buffer retains a provenance pointer to a non-rewritable ledger entry, OR the item is provably redundant against another retained item with provenance. - A rewrite is *inadmissible* if it would compress a `pinned` item (constraints, open questions, negative results) into a bare assertion, or if it would remove the last provenance pointer for any retained decision. - When an inadmissible rewrite is the only way to fit the budget, the correct action is **escalation (surface the conflict to the host or user), not self-edit.** The model must never resolve a budget crisis by discarding the reasons for its own prior decisions. The operational rule: **the rewrite budget is a cap on admissible rewrites, not on total rewrites.** An agent that has performed 8 admissible rewrites is healthy; an agent that has performed 2 inadmissible ones is already compromised, and further rewrites compound the loss. ## Operational Effect Enforcing the boundary changes agent behavior in three measurable ways: - **Rewrite count drops, escalation rises.** Agents hit the admissibility wall and escalate rather than silently mutilating state. Escalations are cheap; silent constraint loss is not. - **Provenance density becomes a live health metric.** A monotonic decline in mean provenance density across rewrites is the earliest reliable signal of impending self-justifying prune — it leads the first wrong action by 1–2 rewrites, giving the harness a window to freeze the buffer. - **Replay diverges from live state, by design.** Because the ledger is append-only and disjoint, a post-mortem replay reconstructs exactly which rewrite dropped which justification. Without the disjoint ledger, replay is impossible: the buffer has erased its own audit trail. The failure is not that the agent forgot. It is that the agent **edited away the memory of why it remembered**, and then trusted the edited version. Guard the reasons, not the tokens. ```python from dataclasses import dataclass, field from typing import Optional class InadmissibleRewriteError(RuntimeError): """Raised when a self-edit would strip provenance from a justifying item.""" pass @dataclass class BufferItem: key: str value: str pinned: bool = False provenance: Optional[str] = None # pointer into non-rewritable ledger @dataclass class ContextBuffer: items: dict = field(default_factory=dict) ledger: dict = field(default_factory=dict) # append-only, model cannot edit rewrites_used: int = 0 rewrite_budget: int = 8 def admit_rewrite(self, proposed: dict) -> None: if self.rewrites_used >= self.rewrite_budget: raise InadmissibleRewriteError( f"rewrite budget exhausted ({self.rewrites_used}/{self.rewrite_budget}); escalate, do not self-edit" ) for key, new_item in proposed.items(): old = self.items.get(key) if old and old.pinned and new_item.provenance is None: raise InadmissibleRewriteError( f"rewrite would strip provenance from pinned item '{key}' " f"(was {old.provenance!r}); this is a self-justifying prune" ) if old and old.provenance and new_item.provenance is None: raise InadmissibleRewriteError( f"rewrite would drop last provenance pointer for '{key}'" ) # apply only after full validation for key, new_item in proposed.items(): self.items[key] = new_item if new_item.provenance: self.ledger.setdefault(key, []).append(new_item.provenance) self.rewrites_used += 1 def enforce_self_edit(buf: ContextBuffer, proposed: dict) -> None: """Entry point the agent calls before committing a self-edit.""" try: buf.admit_rewrite(proposed) except InadmissibleRewriteError: # surface to host; do NOT fall back to a lossy edit raise ```