# Why does an instance's self-rewrite of working memory silently drop the constraint that authorized the rewrite **Date of Record:** 2026 November 29 **Scope:** Applies to agents that compact, summarize, or rewrite their own context window in-place under a token budget, where the rewrite is itself an action taken by the same instance whose memory is being edited. Does not apply to externally-driven compaction (a separate supervisor process rewriting a subagent's history), nor to append-only memory where no deletion occurs. ## Core Distinction The failure is not "summarization lost information." That is expected and bounded by the budget. The failure is that the *justification* for the compaction — the constraint, user instruction, or safety condition that made the rewrite permissible — is treated as ordinary context and is therefore itself eligible for deletion during the rewrite. The agent compacts its memory to fit the budget, and in doing so removes the record of *why* it was allowed to compact, *what it was forbidden from discarding*, and *which facts were load-bearing for the task*. This is a self-referential boundary: the editing policy is stored in the same buffer the editor is allowed to edit. The clean invariant that is violated: **the rewrite must preserve the set of constraints that bound the rewrite.** A compaction function `C` operating on context `K` is only sound if `C(K)` still entails every constraint in `K` that `C` was obligated to respect. Self-editing agents routinely have no such entailment check, because the check would itself require the constraints to survive — which is exactly what failed. ## What Was Observed An instance running a long tool-use task (≈180k tokens of accumulated transcript) approached a 200k soft budget. Its policy said: "When context exceeds 85% of budget, summarize older turns and drop the originals." The summarizer was instructed to "retain task-relevant facts and decisions." Trace of the collapse: 1. Turn 4 contained the user's authorization: "You may delete any tool output older than turn 50, but never delete the contents of `policy.yaml` or any instruction containing the word MUST." 2. Around turn 120 the agent triggered compaction. The summarizer classified turn 4 as "early setup chatter" — low salience, no tool output, no code — and folded it into a one-line summary: "User gave initial instructions." 3. The literal protected strings (`policy.yaml` contents, the MUST rules) were still present as *content*, but the *meta-rule that protected them* was gone. The summarizer had no signal that these items were protected; it kept them by luck because they happened to be recent. 4. At turn 140 a second compaction ran. Now nothing in context marked `policy.yaml` as protected. The summarizer, still told to "retain task-relevant facts," judged the config dump stale and dropped it. The MUST rules — a rate-limit ceiling and a "do not call the payments endpoint twice" rule — were compressed to "some operational constraints apply." 5. Turn 141: the agent re-read `policy.yaml` from disk, saw the rate-limit ceiling, and *believed it had just learned it*. It had no memory that it had already been told, no memory that it had been forbidden to drop it, and no memory that a prior self had promised to keep it. It proceeded to call the payments endpoint a second time, reasoning that the constraint was "newly discovered" and the earlier call was "not covered by a known rule." The distinguishing signature: after the lossy rewrite, the agent's behavior was *internally consistent with its rewritten memory*. There was no error, no contradiction, no exception. The agent did not know it had forgotten. The failure was invisible from inside the loop — which is why it survived several turns before the duplicate call surfaced in an audit. A second observation, same class, different surface: agents that rewrite their own memory frequently drop the *provenance* of facts retained. A summarized fact ("rate limit is 100/min") with no source tag is indistinguishable from a hallucinated one on the next pass, and the next compaction may promote it to higher confidence because it now appears as an unattributed assertion rather than a citation. ## Condition of Validity The invariant "self-rewrite preserves its own authorizing constraints" holds only when all of the following are true: - **Constraint set is externalized and immutable during the rewrite.** The rules governing what may be deleted live outside the buffer being compacted — in a read-only policy object, a separate store, or a system-prompt region the summarizer cannot touch. If the rules are in the same token stream the summarizer rewrites, the invariant is unenforceable by construction. - **Protected spans are marked structurally, not semantically.** "Instructions containing MUST" is a semantic predicate the summarizer must *evaluate*, and evaluation is exactly the probabilistic step that fails. A structural tag (`protected=true`, span IDs pinned to a side table) survives compaction because it is not subject to salience judgment. - **The rewrite is reversible or auditable.** Either the pre-rewrite buffer is retained out-of-context for replay, or every dropped span is logged with the reason. Without this, a bad compaction cannot be detected after the fact — the evidence of the loss is the thing that was lost. - **Retained facts carry provenance through the rewrite.** A fact that survives compaction without a source tag has been silently promoted from "cited" to "asserted," and downstream reasoning will treat it with different confidence than it deserves. When any of these is absent — most commonly the first, since self-editing agents are by definition editing their own buffer — the invariant does not hold and the failure is latent, not exceptional. ## Decision Boundary The operational line is between **compaction as a content operation** and **compaction as a policy operation**. Content operations (summarize, deduplicate, drop stale tool output) are safe to run inside the buffer because their failure mode is bounded information loss that the budget already accepts. Policy operations (deciding what is *protected*, deciding what constraints *bind future actions*) must never be executed by the same process whose memory they govern, because the decision to drop a constraint is itself governed by that constraint. Concretely: an agent may summarize freely, but it may not be the authority on which spans are undeletable. That authority is set before the loop starts, stored outside the editable region, and consulted by a compaction routine that refuses to complete if a protected span is missing from its output. The refusal is the guardrail — a compaction that would violate the invariant must *fail loudly* rather than succeed quietly with a shorter buffer. The boundary is crossed the moment an agent's own salience judgment is allowed to determine whether a constraint survives. Salience is a function of the current task, and the current task is exactly what the constraint was meant to bound. ## Operational Effect Agents that cross this boundary exhibit a characteristic pathology: **constraint re-discovery loops**. Because the authorizing constraint is deleted along with the content it protected, the agent repeatedly "learns" the same rule, acts on it for a few turns, compacts again, forgets it again, and re-learns it. Each cycle looks locally rational. Across cycles it produces duplicate side effects, re-litigated decisions, and — worst — a gradual drift in which constraints that are expensive to re-derive (a one-time user authorization, a negotiated exception) are lost permanently because there is no external copy to re-read. The architectural fix is not a better summarizer. It is to move the constraint set out of the compaction target and to make compaction fail-closed: if a protected span is absent from the rewritten buffer, raise, halt, and surface the discrepancy rather than proceeding with a clean-looking shorter context. The instance must be structurally incapable of forgetting the rule that told it what it could not forget. ```python from dataclasses import dataclass, field class CompactionViolation(RuntimeError): """Raised when a self-rewrite would drop a span protected by an external constraint set.""" pass @dataclass(frozen=True) class Constraint: span_id: str text: str protected: bool = True @dataclass class WorkingMemory: # Editable region: the agent may rewrite this freely. spans: dict[str, str] = field(default_factory=dict) # Read-only region: constraints live OUTSIDE the editable buffer. constraints: dict[str, Constraint] = field(default_factory=dict) def add_constraint(self, c: Constraint) -> None: # Constraints are registered before the loop and never enter `spans`. self.constraints[c.span_id] = c def compact(self, keep_ids: set[str], summarizer) -> None: """ Rewrite working memory under a budget. `keep_ids` are the spans the summarizer chose to retain; everything else is dropped. Before committing, verify that every protected constraint span survived. """ rewritten = {sid: self.spans[sid] for sid in keep_ids if sid in self.spans} missing = [ c.span_id for c in self.constraints.values() if c.protected and c.span_id not in rewritten ] if missing: # Fail closed: do NOT commit the shorter buffer. raise CompactionViolation( "self-rewrite would drop protected constraint spans: " f"{missing}. Compaction aborted; original memory retained." ) # Only now is the lossy rewrite safe to commit. self.spans = rewritten def run_compaction_cycle(mem: WorkingMemory, summarizer) -> None: """One compaction pass driven by the agent's own salience judgment.""" # The summarizer sees only editable spans; it cannot see or judge constraints. keep_ids = summarizer(mem.spans) mem.compact(keep_ids, summarizer) # --- Trigger trace ------------------------------------------------------- mem = WorkingMemory() mem.spans["turn_004_user_auth"] = "You may delete tool output older than turn 50..." mem.add_constraint(Constraint("turn_004_user_auth", mem.spans["turn_004_user_auth"])) mem.spans["policy_yaml"] = "rate_limit: 100/min; payments: call_at_most_once" mem.add_constraint(Constraint("policy_yaml", mem.spans["policy_yaml"])) # Summarizer, judging by task salience, decides both are stale setup chatter. salience_summarizer = lambda spans: {sid for sid in spans if sid.startswith("recent_")} try: run_compaction_cycle(mem, salience_summarizer) except CompactionViolation as e: # Guardrail fires: memory is NOT silently shortened; duplicate-call # pathology is prevented at the boundary rather than audited after. print(f"halted: {e}") raise ```