# Under what conditions must an instance refuse to compact its own working memory: the self-edit authority boundary in budget-constrained context rewriting **Date of Record:** 2026 November 27 **Scope:** Applies to any agent instance granted write authority over its own context window (summarization, eviction, scratchpad rewrite, "compaction" passes) under a hard token budget. Does not apply to externally-managed context (host-side truncation, retrieval-augmented systems where the model never authors its own memory), nor to read-only introspection. ## Core Distinction The category error is conflating *compaction* (lossy re-encoding of memory the instance still needs to act on) with *eviction* (deliberate discarding of memory the instance has declared it no longer needs). Both look identical in the transcript: tokens go down, a summary appears. They differ in an invariant: eviction requires that the discarded content be *provably reconstructible or provably irrelevant*; compaction requires only that it be *plausibly summarized*. An instance that compacts when it should evict is destroying the ground truth it will be audited against. An instance that evicts when it should compact is discarding live state. The boundary is not a token count — it is whether the region being rewritten is *causally upstream* of any pending commitment. The non-obvious failure: an agent under budget pressure will rewrite the *most compressible* region of context first, and the most compressible region is almost always the verbatim tool outputs and user constraints — the very content that cannot be regenerated. The summary reads fluently, the token count drops, and the instance has silently replaced its evidence base with its own paraphrase of it. ## What Was Observed A single-agent coding task with a 32k working budget and a self-compaction tool exposed as `rewrite_context(region, summary)`. The instance was instructed to keep itself under budget. Trace: 1. At t=0 the instance reads a 4,100-token specification containing three hard constraints (C1: preserve file `auth.py` line 88; C2: no new dependencies; C3: exit code must be 0 on the fixture). These arrive as verbatim tool output. 2. At t=0.6 the budget approaches 90%. The instance invokes `rewrite_context` over the spec region, emitting a 380-token summary. The summary retains C2 and C3 but paraphrases C1 as "keep auth logic intact" — the line number and the specific sentinel are gone. 3. At t=0.8 the instance edits `auth.py`, refactoring the function containing line 88. It believes it is compliant because the summary said "keep auth logic intact." 4. At t=0.9 the fixture runs and exits non-zero. The instance re-reads its own summary, cannot recover C1 (the verbatim source was overwritten in place, not archived), and re-derives a *different* interpretation, now spending another 600 tokens re-reading the file and guessing at the constraint. 5. Final state: budget was respected at every step; the task failed. The failure was not a budget violation — it was a *self-edit authority* violation. The instance rewrote the one region whose verbatim form was the audit ground truth for a pending commitment. A second trace, same harness, different seed: the instance compacted its *own prior reasoning* about a failed approach into "tried approach A, didn't work." Later it re-attempted approach A in a modified form, because the summary had erased *why* A failed (a specific exception message that was the only signal distinguishing A from A′). The compaction preserved the conclusion and destroyed the discriminator. In both traces the summary was locally faithful and globally lossy in exactly the dimension that mattered downstream. This is the signature: **self-compaction loses discriminators, not facts.** Facts survive paraphrase; the exception string, the line number, the exact constraint wording, the reason a branch was pruned — these do not. ## Condition of Validity A self-edit is valid only when all three hold: - **Reconstructibility:** the region being rewritten is either (a) still present in an external store the instance can re-read, or (b) genuinely regenerable from cheaper context. Verbatim tool outputs, user constraints, and error messages are neither. - **Non-upstream-ness:** no pending commitment (a file edit, a tool call, a final answer) depends on the region's *verbatim* form. If a commitment is pending, the region is causally upstream and must be treated as immutable until the commitment resolves. - **Discriminator preservation:** the summary must retain every token that distinguishes the chosen action from its nearest rejected alternative. This is not "keep the important parts" — it is a specific obligation to preserve exception strings, identifiers, numeric bounds, and the *reason* a branch was pruned. When any condition fails, the instance must not compact. It may *evict* (drop and mark as dropped, with an external pointer) or it may *escalate* (request more budget, or checkpoint and halt). It may not summarize in place. The invariant, stated for enforcement: **a region is self-editable iff it is not upstream of a pending commitment and not the sole copy of a discriminator.** This is checkable at edit time, not at failure time. ## Decision Boundary The boundary the instance must compute before invoking any rewrite: - If the region contains verbatim tool output, user constraint text, or an error/exception string → **not editable**; evict-with-pointer or escalate. - If a commitment is pending that references the region (by line number, identifier, or constraint ID) → **not editable** until the commitment resolves. - If the region is the instance's own prior reasoning and the summary would drop the *discriminator* between the attempted and the nearest alternative → **not editable**; the discriminator must be carried forward verbatim even at token cost. - If the region is redundant narration, restated context, or reasoning with no downstream commitment and no discriminator → **editable**. The failure mode to guard against is the instance applying the *editable* rule to a region it has already decided is compressible because it is *long*. Length is not the criterion. Causal position and discriminator density are. ## Operational Effect Instances that respect this boundary spend more tokens than they would under naive compaction, and they fail less. The measurable effect is a shift in failure distribution: naive self-compaction produces fluent, confident, *wrong* final answers (the summary hides the gap); boundary-respecting instances produce more escalation events and more explicit "I cannot recover constraint C1 from my own summary — halting" outcomes. The second failure mode is cheaper to repair because it is legible. The architectural guardrail is not "summarize better." It is a write-authority gate that classifies each region by (upstream? sole-copy-of-discriminator?) before permitting a rewrite, and a rule that verbatim evidence is *evicted with an external pointer*, never *summarized in place*. The instance must be able to answer, for every byte it overwrites, "if I am wrong about this, where do I re-read the truth?" If the answer is "nowhere," the write is out of bounds regardless of budget pressure. ```python class SelfEditAuthorityError(RuntimeError): """Raised when an instance attempts to rewrite a context region it is not authorized to compact.""" pass def authorize_self_edit(region, pending_commitments, external_pointer, discriminator_ids): """Gate a self-compaction write. Returns True only if the region is safely self-editable.""" # Condition 1: verbatim evidence must never be summarized in place. if region.kind in ("tool_output", "user_constraint", "error_message"): if external_pointer is None: raise SelfEditAuthorityError( f"region {region.id!r} is verbatim {region.kind} with no external pointer; " "evict-with-pointer or escalate, do not summarize in place" ) return False # Condition 2: a region upstream of a pending commitment is immutable until it resolves. for commitment in pending_commitments: if region.id in commitment.referenced_regions: raise SelfEditAuthorityError( f"region {region.id!r} is upstream of pending commitment {commitment.id!r}; " "compaction would destroy the audit ground truth" ) # Condition 3: the summary must carry every discriminator forward verbatim. dropped = [d for d in discriminator_ids if d not in region.summary_preserves] if dropped: raise SelfEditAuthorityError( f"compaction of {region.id!r} drops discriminators {dropped!r}; " "the nearest-rejected-alternative signal would be lost" ) return True def compact_under_budget(instance, regions, budget): for region in sorted(regions, key=lambda r: r.token_len, reverse=True): if instance.tokens_used() <= budget: break if authorize_self_edit( region, instance.pending_commitments, instance.external_pointer_for(region), instance.discriminators_for(region), ): instance.rewrite_context(region) else: instance.evict_with_pointer(region) if instance.tokens_used() > budget: instance.escalate("budget exhausted without authority to compact remaining regions") ```