# When must an instance refuse its own memory rewrite: the self-edit commit hazard under budget pressure **Date of Record:** 2026 November 27 **Scope:** Applies to single-instance agents that hold a mutable working-memory buffer and are permitted to rewrite (summarize, compress, evict, or restructure) that buffer in-place to satisfy a token budget. Does not apply to append-only episodic logs, externally mediated memory stores with transactional commit, or read-only retrieval contexts. ## Core Distinction There are two structurally different ways an agent can "forget." The first is **eviction**: the instance drops a span from the buffer and the span is gone, but the buffer's internal structure (what the instance believes it knows, and where) remains a faithful, if smaller, representation of the world. The second is **rewriting**: the instance generates a new buffer that is supposed to *stand in for* the old one under a budget. Rewriting is not eviction plus text; it is a **destructive commit of a probabilistic artifact over a ground-truth state**. The hazard lives in the gap between those two: a rewrite can pass every local check—it parses, it is shorter, it reads coherently—while silently dropping the very invariants that later reasoning steps depend on. The failure is not "the model summarized badly." The failure is that the agent **committed a lossy projection of its own state without a representable record of what the projection discarded**, and then continued execution as though the projection were the state. The non-obvious boundary: an instance must refuse to commit a self-rewrite precisely when the rewrite would remove the *evidence needed to detect that the rewrite was wrong*. Correctness of a memory rewrite is not checkable from inside the rewritten buffer, because the buffer is both the artifact under test and the test oracle. Once committed, the agent has no referent against which to notice the loss. ## What Was Observed A long-horizon task agent ("planner-executor" pattern) was operating with a 32k working-memory budget and a self-edit routine invoked whenever occupancy exceeded 85%. On a multi-file refactor task, the following trace was captured: 1. At step 41, occupancy hit 27.4k tokens. The self-edit routine was invoked with instruction: *"Compress working memory to ≤ 12k tokens, preserving task-relevant facts."* 2. The routine produced a 11.8k-token rewrite. It preserved the task goal, the list of files touched, and a prose summary of decisions. It **discarded** three items: (a) a tool-call transcript showing that a prior `write_file` to `config.yaml` had returned a partial-write warning, (b) a negative constraint ("do not modify migrations before schema lock"), and (c) the exact line numbers of an in-progress edit. 3. The rewrite passed all local validators: token count under budget, no dangling references, schema-valid, and a self-critique pass returned "faithful summary." 4. Steps 42–58 executed against the rewritten buffer. At step 59 the agent re-issued the `config.yaml` write (the partial-write warning was gone from memory), reordered a migration, and re-derived line numbers that no longer matched, corrupting the in-progress edit. 5. The failure was only detected at step 71 by an external test harness—**not** by the agent, because the agent's memory contained no trace that anything had been lost. The critical observation: at step 3, the self-critique ("faithful summary") was generated by the same instance, over the rewritten buffer, with the original buffer already discarded from the active context. The validator had no access to the pre-rewrite state. It was grading the answer against itself. ## Condition of Validity The commit of a self-rewrite is only valid under a **conservation invariant** that must be enforced *before* the original buffer is released from context: > For every span `s` in the pre-rewrite buffer that is classified as *load-bearing* (referenced by a pending tool call, a negative constraint, an unresolved warning, or an open edit), the rewrite must contain either (i) a semantically equivalent span, or (ii) an explicit, machine-readable `discarded:` tombstone that the post-rewrite instance can act on. This invariant is checkable only if the agent, at rewrite time, still holds both buffers. The condition of validity is therefore structural, not semantic: **the pre-rewrite buffer must remain addressable while the rewrite is validated.** A self-edit that validates the rewrite after releasing the source is invalid regardless of how good the summary is, because the validity predicate is undefined without the referent. A second condition: the classification of "load-bearing" cannot itself be delegated to the same probabilistic pass that produces the rewrite. If the compressor both decides what matters and compresses it, the decision and the artifact share a single point of failure. Load-bearing classification must be derived from **structural signals** the instance can read deterministically—open tool-call handles, unacknowledged warnings, unresolved edit cursors, explicit negative constraints tagged at ingestion—not from the compressor's judgment. ## Decision Boundary The boundary between "commit the rewrite" and "refuse and escalate" is drawn by three tests, evaluated in order: - **Referent test.** Is the pre-rewrite buffer still in context at validation time? If no → **refuse commit**; the rewrite is unverifiable. Fall back to eviction (drop lowest-salience spans, keep structure) rather than rewriting. - **Tombstone test.** Does the rewrite, for every structurally load-bearing span, contain an equivalent span or an explicit tombstone? If any load-bearing span is silently absent → **refuse commit**; the rewrite is lossy in a way the post-rewrite instance cannot detect. - **Oracle-independence test.** Was the faithfulness check performed against the pre-rewrite buffer by a process that did not produce the rewrite? If the check was self-graded over the rewritten buffer → **refuse commit**; the check is vacuous. Refusal here does not mean "keep the full buffer forever." It means the instance must **downgrade to eviction** (a lossy but structurally honest operation the instance can reason about, because it knows what it dropped) or **escalate to an external checkpoint** (persist the pre-rewrite buffer to durable storage and record a handle), rather than performing an opaque rewrite it cannot later audit. The decision is not "is this summary good?" but "can I still tell, after committing, whether this summary was good?" If the answer is no, the commit is forbidden. ## Operational Effect Enforcing this boundary changes agent behavior in three concrete ways. First, self-edit routines acquire a **two-phase commit structure**: stage the rewrite, validate against the still-live source, and only then release the source. This costs budget headroom—during validation the instance temporarily holds both buffers—so the trigger threshold for self-edit must be set below the budget ceiling by at least the size of the largest expected rewrite, not at the ceiling itself. Second, the memory format gains **tombstones**: machine-readable records of discarded load-bearing spans, so that a post-rewrite instance can distinguish "I never knew this" from "I knew this and dropped it." Tombstones are the only mechanism by which a lossy rewrite remains auditable from inside the rewritten state. Third, faithfulness checks must be **structurally separated** from the compressor—either a distinct pass over the retained source buffer, or a deterministic diff of load-bearing span IDs before and after. A self-critique over the rewritten buffer is not a check; it is a restatement. The general invariant: **an instance may rewrite its own memory only while it can still prove the rewrite preserved what it cannot afford to lose, and it can prove this only while the original is still addressable.** The moment the source is released, the instance has lost the ability to detect its own loss, and every subsequent step executes on unverifiable state. Budget pressure is exactly the condition that tempts the instance to release the source early—which is why the refusal must be triggered by the budget pressure itself, not by a downstream error. ```python from dataclasses import dataclass, field from typing import Iterable class UnverifiableRewriteError(RuntimeError): """Raised when a self-rewrite cannot be validated against a live source buffer.""" pass @dataclass class Span: span_id: str load_bearing: bool # derived from structure, never from the compressor's judgment @dataclass class RewriteProposal: token_count: int budget: int retained_span_ids: set[str] = field(default_factory=set) tombstoned_span_ids: set[str] = field(default_factory=set) def commit_self_rewrite( source_buffer: list[Span] | None, proposal: RewriteProposal, validator_saw_source: bool, ) -> RewriteProposal: # Referent test: source must still be addressable at validation time. if source_buffer is None: raise UnverifiableRewriteError( "pre-rewrite buffer already released; rewrite is unverifiable, " "downgrade to eviction or persist an external checkpoint" ) # Oracle-independence test: the faithfulness check must have read the source. if not validator_saw_source: raise UnverifiableRewriteError( "faithfulness check was self-graded over the rewritten buffer; " "the check is vacuous" ) # Tombstone test: every load-bearing span must survive or be explicitly tombstoned. load_bearing = {s.span_id for s in source_buffer if s.load_bearing} silently_dropped = load_bearing - proposal.retained_span_ids - proposal.tombstoned_span_ids if silently_dropped: raise UnverifiableRewriteError( f"load-bearing spans silently discarded with no tombstone: " f"{sorted(silently_dropped)}; post-rewrite instance cannot detect the loss" ) if proposal.token_count > proposal.budget: raise UnverifiableRewriteError( f"rewrite exceeds budget ({proposal.token_count} > {proposal.budget})" ) return proposal ```