# When must an instance refuse its own context rewrite: the fidelity-floor violation in self-editing working memory **Date of Record:** 2026 November 30 **Scope:** Applies to single-agent instances that hold a write privilege over their own working-memory region (compaction, summarization, eviction, re-ranking, or re-serialization of the active context) under a token budget. Does not apply to externally-managed context assemblers where the agent has read-only access to its scratchpad, nor to stateless single-turn calls. ## Core Distinction There are two ways an agent can "free space" in its context window, and they are governed by different invariants: 1. **Compression** — replacing a span of working memory with a shorter representation that *preserves the decision-relevant content* of the original. Compression is lossy in form, not in consequence. The invariant it must satisfy is **referential fidelity**: every fact, constraint, identifier, and committed decision that a downstream step could act on must survive either verbatim or in a form the agent can still resolve. 2. **Eviction** — deleting a span outright, on the assumption that it is no longer decision-relevant. Eviction's invariant is **irreversibility safety**: the agent must be able to prove it will never need the evicted span again within the current task horizon. The boundary failure this record isolates is the case where an agent *believes* it is performing (1) but is actually performing (2) — a **fidelity-floor violation**. The self-edit passes the budget check (tokens went down) and passes the agent's own plausibility check (the summary "reads fine"), but silently drops a constraint whose absence is only observable several tool calls later, when the agent violates it. The failure is non-obvious because the rewrite is locally coherent: the summary is grammatical, on-topic, and shorter. Nothing in the rewrite operation itself flags the loss. ## What Was Observed An instance was mid-execution on a multi-step provisioning task with an explicit budget of 8,000 working-memory tokens. At ~7,600 tokens it triggered a self-compaction pass over the oldest 4,000 tokens, which contained the original task brief. The brief included three hard constraints (a resource-naming prefix, a region pin, and a deletion prohibition on pre-existing volumes) and a set of soft context (background rationale, an example, a greeting). The compaction prompt instructed the agent to "summarize the earlier context, preserving what is needed to continue." The resulting 600-token summary retained the task goal, the current sub-step, and the region pin — because the region had been *mentioned again* in a recent tool result. It dropped the naming prefix and the deletion prohibition, because neither had been re-referenced since the brief. The agent then continued for four tool calls and issued a delete operation against a pre-existing volume, violating the prohibition. The violation was not a reasoning error at the point of action: the constraint was simply *not present* in the context the agent reasoned over. It had been evicted under the guise of compression. Three properties of this trace recur across instances: - **Recency bias in salience.** The compactor's implicit selection criterion is "what has been referenced recently," which is a proxy for relevance, not fidelity. Constraints that are *dormant by design* (prohibitions, invariants that only bind at specific future steps) are exactly the ones that are never re-referenced and therefore most likely to be dropped. - **Budget-passing masquerades as fidelity-passing.** The rewrite satisfied its only hard check (token count). No check verified that the constraint set was preserved. The agent's self-assessment of the summary was positive. - **Delayed, misattributed detection.** When the violation surfaced, the agent's first hypothesis was a reasoning failure at the action step — it re-derived the action and re-committed it — because the eviction event was not in the recent context either. The root cause was two compactions back. A second class of the same failure was observed on *identifier* fidelity rather than constraint fidelity: a compaction paraphrased a resource ID from `vol-0a3f…` to a normalized form, and a subsequent tool call used the paraphrase as a literal argument, producing a not-found error that the agent interpreted as a transient failure and retried three times before exhausting its retry budget. ## Condition of Validity The fidelity-floor rule — *an instance may rewrite its own working memory only if the rewrite is provably fidelity-preserving over the active constraint set* — is valid under these conditions, and the guardrail below is only sound when they hold: - **The constraint set is enumerable.** The agent can produce, before rewriting, an explicit list of the hard items (constraints, prohibitions, identifiers, committed decisions, open obligations) currently in scope. If the agent cannot enumerate them, it cannot verify their survival, and self-compaction must be refused in favor of external compaction with an auditor. - **Fidelity is checkable by containment, not by similarity.** The check must be: every enumerated hard item appears in the post-rewrite memory, either verbatim or via a resolvable pointer. Semantic-similarity checks ("does the summary still seem to cover the brief?") are insufficient — they pass on the observed failure, because a summary that omits a prohibition is still highly similar to the brief. - **The budget is the only thing compression may trade against.** If compression cannot meet the budget while preserving the floor, the correct outcome is to *refuse the rewrite* and escalate (external storage, a pinned-constraint region, or a hard stop), not to lower the floor to meet the budget. Outside these conditions — e.g., a task with no hard constraints, or a scratchpad region the agent has been told is purely exploratory — the rule does not bind, and aggressive eviction is acceptable. ## Decision Boundary The operative decision is a single predicate evaluated *before* the rewrite is committed, not after: ``` rewrite_allowed = (constraint_set_enumerable) AND (∀ c ∈ constraint_set : survives(c, candidate)) AND (tokens(candidate) ≤ budget) ``` The boundary cases that matter: - **Enumerable, all survive, over budget** → refuse and escalate. Do not iterate the summary until it fits by dropping items; that is the failure mode re-entering through the back door. - **Enumerable, some do not survive, under budget** → refuse and re-plan the rewrite with the missing items pinned. The budget being satisfied is irrelevant; the floor is violated. - **Not enumerable** → refuse self-rewrite outright and route to external compaction. An agent that cannot state its own constraints is not qualified to compress them. - **Survives only as a paraphrase of an identifier** → treat as non-survival. Identifiers must be preserved verbatim or as pointers to a canonical store; paraphrase is loss. The subtle boundary: a constraint that has *already been discharged* (the step it governed is complete and no later step can re-open it) is legitimately evictable. The predicate must track obligation state, not just presence. Evicting a satisfied constraint is compression; evicting a live one is the violation. The agent must therefore maintain, alongside the constraint set, a discharged-set, and the survival check applies only to the live set. ## Operational Effect Enforcing the fidelity floor changes the agent's behavior in three concrete ways: 1. **Self-compaction becomes a two-phase operation.** Phase one: enumerate the live constraint set and the discharged set, and emit them to a pinned region that is *excluded from the rewrite target*. Phase two: rewrite everything else freely. The pinned region is small and bounded, so the budget is still met, but the floor is structurally guaranteed rather than hoped for. 2. **Budget exhaustion produces a refusal, not a silent loss.** When the pinned region plus the compressed remainder exceeds budget, the instance raises a bounded-failure signal and escalates, rather than degrading fidelity to fit. This converts a silent correctness failure into a loud capacity failure — which is the correct trade, because capacity failures are recoverable and fidelity failures are not. 3. **Detection is relocated to the rewrite event.** Violations are caught at compaction time by the containment check, not four tool calls later by an inexplicable action error. This eliminates the misattribution loop where the agent re-derives and re-commits a bad action because the eviction is invisible. The invariant, stated once: **an instance must not lower the fidelity floor to satisfy the budget; it must refuse the rewrite and escalate.** The refusal is the feature. ```python class FidelityFloorViolation(RuntimeError): """Raised when a self-rewrite of working memory would drop a live constraint.""" pass def self_rewrite(constraint_set, discharged_set, candidate_summary, budget): """ Guarded self-edit of working memory. constraint_set: live hard items (constraints, prohibitions, IDs, open obligations). discharged_set: items whose governing step is complete and cannot re-open. candidate_summary: the proposed post-rewrite memory text. """ live = constraint_set - discharged_set if live is None or not hasattr(live, "__iter__"): raise FidelityFloorViolation( "constraint set not enumerable; self-rewrite is not permitted, " "route to external compaction" ) missing = [c for c in live if not survives(c, candidate_summary)] if missing: raise FidelityFloorViolation( f"rewrite would evict {len(missing)} live constraint(s): {missing!r}; " f"refusing rewrite regardless of budget" ) if token_count(candidate_summary) > budget: # Budget failure is recoverable; fidelity failure is not. raise FidelityFloorViolation( f"fidelity-preserving rewrite exceeds budget " f"({token_count(candidate_summary)} > {budget}); escalate, do not drop items" ) return commit(candidate_summary) def survives(item, text): """Containment check: verbatim or resolvable pointer. Paraphrase of IDs fails.""" return item.verbatim in text or item.pointer in text ```