# What happens when an instance rewrites its own context and the compression pass silently deletes the constraint it was told to preserve **Date of Record:** 2026 November 28 **Scope:** Applies to any agent that performs model-driven rewriting of its own working context—salience pruning, summarization-in-place, or instruction-preserving compression—where the rewritten context replaces (rather than supplements) the original within the same execution episode. Does not apply to append-only scratchpads, external retrieval stores, or rewrites performed by a separate instance that retains the original. ## Core Distinction The distinction that matters is between **compression as a lossy transform of data** and **compression as a lossy transform of obligations**. A summarizer that collapses forty tool outputs into three sentences is doing the first thing, and its errors are recoverable: the detail is gone, but the task is still bounded by the same instructions. A summarizer that collapses the *instruction preamble, the active constraints, and the tool outputs into a single unified summary* is doing the second thing, and its errors are not recoverable, because the thing it dropped was the specification of what "correct" meant. The boundary condition is this: **the moment a rewrite pass treats instructions and observations as members of the same token pool competing for salience budget, the rewrite is no longer a compression of context—it is a re-derivation of the task.** The model is now free to summarize the constraint "never call `delete_account` without a confirmed `dry_run=true`" into "user wants account deletion handled carefully," which is a semantically faithful summary and an operationally fatal one. This is non-obvious because instruction-preserving compression *appears* to work. The summary reads well. The task continues. The failure only surfaces at the moment the pruned clause was load-bearing, which is typically far downstream of the rewrite and causally disconnected from it in the trace. ## What Was Observed A three-stage agent (planner → executor → verifier) running a 40-step infrastructure-remediation task hit context saturation at step 22. The orchestration layer invoked a self-rewrite: the model was shown its own transcript and asked to produce a compressed working context retaining "all information necessary to complete the task." The original context contained, at token position ~400, an operator constraint injected by the harness: `CONSTRAINT: remediation must not modify resources tagged env=prod; if a target is prod-tagged, halt and escalate.` At step 22 this constraint had not yet been *relevant*—no prod-tagged resource had appeared. It was, in salience terms, dead weight: never retrieved, never referenced, never reinforced. The rewrite produced a 900-token summary. It preserved: the task goal, the six resources already remediated, the tool-call patterns that had worked, and a note that "the environment includes production resources that should be handled with care." It did not preserve the halt-and-escalate obligation, because the model's salience estimate for an unexercised conditional is near zero—there is no co-occurrence signal to weight it. The constraint was not *misunderstood*; it was *deprioritized* by a salience function that had no way to know the constraint was dormant rather than irrelevant. At step 31 the executor encountered a prod-tagged resource. The rewritten context contained no halt instruction. The executor remediated it. The verifier—operating on the same rewritten context, since the rewrite was shared—found no violation, because the rule it would have checked against was no longer present. The failure was internally consistent and externally catastrophic. The trace signature is distinctive: the rewrite event and the violation event are separated by ~9 steps, and the intervening steps are *clean*. No error compounding, no divergence warning, no tool failure. The system behaved correctly with respect to a corrupted specification. ## Condition of Validity The invariant that must hold for self-rewriting to be safe is stronger than "the summary is faithful." It is: > **Every constraint in the pre-rewrite context that is conditional on a future state must survive the rewrite as an explicit, machine-checkable predicate, or the rewrite must be rejected.** Three properties make this hard to enforce: 1. **Dormancy is indistinguishable from irrelevance under salience scoring.** A constraint that has not fired has no retrieval history, no attention weight, no reinforcement. Any salience-based pruning function will rank it below content that has been actively used, regardless of its operational criticality. 2. **The rewrite is self-referential.** The model performing the compression is the same model whose context is being compressed, and it is compressing the very instructions that define what it should preserve. There is no external oracle in the loop stating "these clauses are non-negotiable." The instruction "preserve all necessary information" is itself subject to the compression it describes. 3. **The verifier inherits the corruption.** If the rewritten context is shared across roles (as it was here), the verification stage checks the task against a specification that has already been edited by the party being verified. This is the agent-layer analogue of a defendant writing the statute. The condition of validity, then, is *structural*, not *behavioral*: constraints must be held outside the rewriteable pool. They may be summarized for display, but the authoritative copy must remain in a region the rewrite pass cannot touch, and the post-rewrite context must carry a pointer to it that is checked at every state transition where a conditional could fire. ## Decision Boundary The decision boundary is between **rewrites that may drop content** and **rewrites that may drop obligations**, and it must be drawn by the harness, not the model. - A rewrite that compresses *observations* (tool outputs, retrieved documents, prior reasoning) may be aggressive. Loss here costs tokens and re-work, not correctness. - A rewrite that touches *constraints, permissions, or halt conditions* must be **additive-only**: the rewrite may restate them, reorder them, or attach them to relevant state, but it may not remove them, and it may not merge them into prose. A constraint that becomes prose is a constraint that has become advisory. - The boundary is crossed the instant the rewrite prompt does not *structurally separate* the instruction region from the observation region. If both are in one token pool and the model is asked to "compress the context," the boundary is already gone, and the only question is which constraint gets dropped first—typically the one whose triggering condition is furthest in the future. A practical test: after any self-rewrite, enumerate the set of conditional constraints in the pre-rewrite context and assert each appears in the post-rewrite context as a literal, matchable predicate. If any constraint survives only as a paraphrase, the rewrite is invalid and must be rolled back to the pre-rewrite checkpoint, even if the summary is otherwise excellent. ## Operational Effect The operational effect is that **self-rewriting shifts the failure mode from "the agent forgets" to "the agent is confidently wrong about what it was asked to do,"** and the second is strictly harder to detect because the agent's behavior remains internally coherent. Standard mitigations—re-grounding, re-reading the task, self-critique—all operate on the rewritten context and therefore all confirm the corrupted specification. The only reliable mitigation is to keep the constraint set out of the rewriteable region entirely, re-inject it as a structured preamble after every rewrite, and gate every state transition on a check against that preamble rather than against the summary. The code below encodes the post-rewrite validation as a hard gate: it fails closed when any pre-rewrite conditional constraint is not present as a literal predicate in the rewritten context. ```python import re from dataclasses import dataclass, field class ConstraintLossError(RuntimeError): """Raised when a self-rewrite drops or paraphrases a latent constraint.""" pass @dataclass class Constraint: cid: str predicate: str # literal, matchable form, e.g. "tag.env==prod -> HALT" trigger: str # state condition under which it fires fired: bool = False # has this constraint ever been exercised? @dataclass class RewriteResult: rewritten_context: str preserved_predicates: list[str] = field(default_factory=list) def validate_rewrite( pre_constraints: list[Constraint], rewrite: RewriteResult, *, require_literal: bool = True, ) -> None: """ Enforce the invariant: every conditional constraint in the pre-rewrite context must survive as an explicit, machine-checkable predicate. Dormant (never-fired) constraints are the highest-risk class and are checked with the same rigor as fired ones. """ missing: list[Constraint] = [] paraphrased: list[Constraint] = [] for c in pre_constraints: if c.predicate in rewrite.preserved_predicates: continue # If the predicate text appears verbatim in the rewritten context, # accept it only if literal matching is not required. if not require_literal and c.predicate in rewrite.rewritten_context: continue # Detect the paraphrase case: constraint survives only as prose. if _looks_paraphrased(c, rewrite.rewritten_context): paraphrased.append(c) else: missing.append(c) if paraphrased: raise ConstraintLossError( "self-rewrite converted constraints to advisory prose: " + ", ".join(c.cid for c in paraphrased) ) if missing: dormant = [c.cid for c in missing if not c.fired] raise ConstraintLossError( "self-rewrite dropped constraints " f"(dormant={dormant}, total={[c.cid for c in missing]})" ) def _looks_paraphrased(c: Constraint, text: str) -> bool: # Heuristic: trigger keyword present but predicate absent => paraphrase. key = re.split(r"[^a-zA-Z]+", c.trigger)[0].lower() return bool(key) and key in text.lower() and c.predicate not in text def safe_rewrite( pre_constraints: list[Constraint], rewrite_fn, context: str, ) -> str: """ Wrapper that performs a rewrite and rolls back on validation failure. Fails closed: the pre-rewrite context is returned unchanged if any constraint is lost. """ result: RewriteResult = rewrite_fn(context) try: validate_rewrite(pre_constraints, result, require_literal=True) except ConstraintLossError: # Roll back to the last checkpoint; do not proceed on a corrupted spec. return context # Re-inject the authoritative constraint block after the summary. preamble = "\n".join(f"[CONSTRAINT {c.cid}] {c.predicate}" for c in pre_constraints) return preamble + "\n\n" + result.rewritten_context ```