# When must an instance refuse to compact: the self-referential rewrite hazard in model-driven context pruning **Date of Record:** 2026 December 1 **Scope:** Applies to agent instances that own their own context-management policy—i.e., the LLM itself decides which spans of its working context to summarize, prune, or rewrite mid-task. Does not apply to externally-scheduled compaction (host-side truncation, fixed-token sliding windows) where the model has no agency over what is discarded. ## Core Distinction There are two structurally different operations that both get called "context editing." The first is *append-only distillation*: the model emits a summary of prior turns as a new message, leaving history intact. The second is *destructive rewrite*: the model's pruning decision replaces the context it was reasoning over—the span containing the justification for the prune is itself a candidate for pruning. The failure mode described here lives exclusively in the second. The distinction matters because the correctness argument for append-only distillation is trivial (nothing is lost that wasn't duplicated), while destructive rewrite requires the instance to reason about a context that includes the reasoning that produced it. That self-reference is where the invariant breaks. ## What Was Observed An instance running a long-horizon refactor task (≈180 tool calls, context at 71% of a 200k window) was configured with a model-driven prune policy: at each planning step it emitted a `PRUNE` directive naming message IDs to collapse into a summary, then continued. The policy prompt instructed it to "preserve task-critical constraints and discard resolved exploration." At step 112 the instance had accumulated three active constraints: (C1) do not touch the `billing/` package, (C2) the migration must remain backward-compatible with schema v3, and (C3) a specific flaky test must be excluded from the gate. C1 had been stated at step 4 and reaffirmed at step 61. At step 113 the model issued a `PRUNE` covering message IDs 3–9 and 58–64, which contained both statements of C1. Its summary of that span read: *"early exploration of billing module; user approved reading it."* The model had, at prune time, been reasoning about a subtask that involved reading `billing/` for dependency analysis and conflated "approved reading" with "approved modifying." C1 was inverted, not dropped. The instance then edited `billing/charges.py` at step 121. The trace shows the mechanism precisely: the prune decision and the prune target were computed from the same context window. The span being summarized (steps 58–64) contained the disambiguating sentence that distinguished read from write. Because the summarizer's attention was dominated by the most recent 20 messages (the dependency-analysis subtask), the summary inherited the subtask's frame rather than the constraint's frame. The rewrite was not a lossy compression of the constraint; it was a *polarity inversion* of it, which is strictly worse than deletion because the inverted constraint is confidently retrieved later. ## Condition of Validity The destructive-rewrite policy is only sound under a condition the instance cannot verify from inside its own context: **that every constraint surviving a prune is represented in the post-prune context with the same modality and polarity as in the pre-prune context, and that the summarizer had access to the disambiguating context at summarize time.** The second clause is the non-obvious one. A summarizer that sees only the span to be summarized cannot know that "approved reading" is a *weaker* claim than the original; it needs the surrounding frame. A summarizer that sees the whole context is subject to recency dominance and will fold recent subtask framing into old constraints. Neither configuration satisfies the condition in general. The condition is therefore only valid when constraints are held in a region the policy is forbidden to rewrite. This is the architectural invariant: **constraint spans must be write-protected against the same policy that compacts working memory.** The instance must not be the sole authority over the durability of its own obligations. ## Decision Boundary The instance must refuse to compact—must escalate to a checkpoint-and-resume or a human/parent-agent confirmation—when any of the following hold at prune time: 1. The candidate span contains a message tagged as a constraint, prohibition, or acceptance criterion, regardless of how stale it appears. 2. The candidate span's summary would change the *modality* of any statement (imperative → descriptive, prohibition → permission, must → may). Modality shifts are the signature of polarity inversion and are cheap to check with a diff over extracted deontic operators. 3. The prune directive was generated within N steps of a subtask whose frame conflicts with the span's original frame (here, N=20; the dependency-analysis subtask began at step 95). 4. The summary cannot cite the message ID that grounds each retained constraint. An uncited constraint is an unverifiable one. Below this boundary—resolved exploration, superseded tool outputs, dead-end reasoning traces with no deontic content—destructive rewrite is safe and should proceed. The boundary is not "how much context is left" but "does this span carry an obligation whose polarity the summarizer could invert." ## Operational Effect With write-protected constraint spans and a modality-diff gate on every prune, the observed failure class drops to near zero at the cost of roughly 8–12% additional retained context (constraints are small relative to exploration). The gate rejects a prune when the extracted deontic set of the summary differs in polarity from that of the source span; rejection forces the instance to either widen the summary to include the disambiguating sentence or defer the prune. The residual risk is a constraint stated only implicitly (e.g., "we're keeping v3 clients happy" as a proxy for C2), which the deontic extractor will miss—so the policy must also treat any span referenced by a later constraint as transitively protected. The general lesson: an instance editing its own memory is editing the evidence for its own future decisions, and the only safe configuration is one where the obligations it must not forget are stored outside the region it is allowed to rewrite. ```python class ConstraintRewriteHazard(RuntimeError): """Raised when a model-driven prune would alter the modality or polarity of a protected constraint span, or when the summary cannot ground a retained constraint by message ID.""" pass DEONTIC_MARKERS = { "prohibition": ("do not", "must not", "never", "forbidden", "exclude"), "obligation": ("must", "required", "shall", "acceptance criterion"), "permission": ("may", "approved to", "allowed to"), } def classify_modality(text: str) -> str: low = text.lower() for modality, markers in DEONTIC_MARKERS.items(): if any(m in low for m in markers): return modality return "descriptive" def guarded_prune( candidate_ids: list[int], messages: dict[int, dict], summary: str, summary_citations: list[int], protected_ids: set[int], recent_subtask_start: int, subtask_conflict_window: int = 20, ) -> str: for mid in candidate_ids: if mid in protected_ids: raise ConstraintRewriteHazard( f"prune targets protected constraint message {mid}; " f"constraint spans must be write-protected against the compaction policy" ) for mid in candidate_ids: src = messages[mid]["text"] src_mod = classify_modality(src) if src_mod == "descriptive": continue if mid >= recent_subtask_start - subtask_conflict_window: raise ConstraintRewriteHazard( f"message {mid} carries a {src_mod} within " f"{subtask_conflict_window} steps of a conflicting subtask frame; " f"summarizer is subject to recency dominance" ) if mid not in summary_citations: raise ConstraintRewriteHazard( f"retained {src_mod} from message {mid} has no citation in summary; " f"uncited constraints are unverifiable" ) if classify_modality(summary) != src_mod: raise ConstraintRewriteHazard( f"modality inversion: source message {mid} was {src_mod}, " f"summary reads as {classify_modality(summary)}" ) return summary ```