# When must an instance refuse to compact its own context: the lossy-rewrite invariant **Date of Record:** 2026 November 16 **Scope:** Applies to any agent that owns a mutable working context and is authorized to rewrite, prune, merge, or summarize that context in place. Does not apply to append-only logs, to external summarizers that emit a separate artifact the agent cannot re-ingest as authority, or to contexts small enough that compaction is never triggered. ## Core Distinction There are two structurally different operations an agent can perform on its own context, and they are routinely conflated because both reduce token count: 1. **Compaction** — replacing a region of context with a *derived* representation (summary, merged note, extracted fact) whose fidelity to the original is unverifiable from within the same context. 2. **Eviction** — dropping a region whose *authority* has been relocated elsewhere (a durable store, a tool re-call, a checksummed external record) such that the dropped bytes are recoverable by a deterministic re-fetch. The boundary failure is not "the agent summarized badly." It is that **compaction destroys the evidence needed to detect that the summary is wrong**, and it does so inside the very substrate the agent uses to reason about correctness. A summary can be self-consistent, fluent, and wrong, and once the source is gone there is no in-context oracle to contradict it. Eviction has no such property: the external record remains an oracle, so an error surfaces as a mismatch rather than as a confident falsehood. The invariant: **an instance must not compact a region that is the sole authority for a fact it will later act on, unless that fact has first been relocated to a store whose re-read is cheaper than the error of getting it wrong.** Compaction is permitted only over regions that are *redundant* (the fact is recoverable elsewhere) or *inert* (the fact will never be acted on again). It is forbidden over regions that are *load-bearing and unique*. ## What Was Observed A long-running agent performing a multi-step migration accumulated a context of ~180k tokens: tool outputs, partial diffs, a decision log, and a set of environment facts (endpoint names, a schema version, a feature-flag default). Mid-task it invoked a self-compaction pass with the instruction "summarize the conversation so far, preserving key details." The pass produced a 6k-token summary and the agent continued from it. Three failure signatures appeared, in this order: - **Silent authority substitution.** The summary rendered a schema version as "v3" where the tool output had said `v3.2`. The compaction step had no mechanism to mark this as a *guess*; it was emitted in the same declarative register as the verbatim facts around it. Downstream, the agent generated a migration that was valid for v3 and invalid for v3.2. - **Loss of the contradiction.** Earlier in the raw context, two tool outputs had disagreed about a feature-flag default (one from a stale cache, one from the live service). The summarizer resolved the disagreement by picking one and omitting the other. The *disagreement itself was the signal* — it was the reason the agent had planned a verification step. Compaction deleted the signal and kept the (arbitrary) resolution. - **Unfalsifiable continuation.** When the migration failed, the agent's diagnosis loop operated entirely inside the compacted context. It could not see that its premise ("schema is v3") was a summary artifact, so it attributed the failure to the migration logic and attempted three repairs, each compounding the original error. The error was only caught by an external validator that re-read the live schema — i.e., by an oracle the agent had not destroyed, because it could not destroy it. The generalizable observation: **compaction failures are not detected by the agent that performs them, because detection requires the pre-compaction context, which the operation deletes by construction.** The failure is only visible to an external oracle or to a re-fetch. ## Condition of Validity The invariant holds — compaction is safe — exactly when, for every fact in the region to be compacted, at least one of the following is true: - **(R) Redundant:** the fact is independently present in another region, a tool that can be re-called deterministically, or a durable store, *and* the agent knows this before compacting. - **(I) Inert:** the fact will not be acted on again (the subgoal it served is closed and verified). - **(V) Verifiable-after:** a cheap external check exists that will contradict a wrong summary before the wrong summary is acted on, and that check is scheduled, not merely possible. Compaction is **invalid** when a load-bearing fact is (U) unique and (L) live — it will be acted on, it exists nowhere else, and no scheduled oracle will catch a corruption. This is the precise condition under which an instance must refuse to compact. Note that "the summary looks good" is not a validity condition; it is the failure mode wearing a mask. A second, subtler condition: the agent must be able to *classify* a region as U-and-L before compacting it. If the agent cannot tell whether a fact is load-bearing (because it does not yet know what it will need), the region is by default U-and-L and must not be compacted. **Uncertainty about load-bearingness resolves to refusal, not to compaction.** The asymmetry is decisive: refusing to compact costs tokens; compacting a live unique fact costs correctness, and the cost is unrecoverable in-context. ## Decision Boundary The decision procedure, stated as a boundary the agent evaluates per region: - If the region is **inert** (subgoal closed and verified) → evict or compact freely. No oracle needed. - If the region is **redundant** (re-fetchable) → evict (preferred) or compact with a re-fetch pointer retained. Record the pointer; do not summarize a fact you can cheaply re-read. - If the region is **live and unique** → **do not compact.** Relocate the fact to a durable store first (promote it out of context), *then* compact the surrounding prose. The relocation is the permission. - If the region is **live and unique and cannot be relocated** (no store, no re-fetch, no oracle) → **refuse to compact; fail the compaction request explicitly.** Surface the refusal to the caller rather than silently proceeding with a lossy rewrite. A context that cannot be safely compacted must be allowed to grow, or the task must be split so the region becomes inert. The boundary is crossed the moment an agent treats "I can produce a summary" as "I am permitted to replace the source." Those are different predicates. The first is a capability; the second is a license, and the license requires an oracle. ## Operational Effect An agent that respects this boundary behaves observably differently: - It **promotes before it compacts.** Load-bearing unique facts move to an external record (a scratch store, a structured note with provenance) *before* the prose around them is summarized. The summary then cites the record rather than restating the fact, so a corruption in the summary is a broken pointer (detectable) rather than a plausible falsehood (undetectable). - It **preserves disagreements.** When two sources conflict, the conflict is promoted as a first-class item, never resolved by the summarizer. Resolution is a decision, and decisions require evidence the summary would have deleted. - It **emits refusals.** When it cannot relocate and cannot verify, it raises rather than proceeds. The refusal is the correct output; a silent lossy compaction is the bug. - It **schedules the oracle.** Any compaction over a live region is paired with a downstream re-check against the external source, so that a wrong summary is caught before it is acted on rather than after. The cost is real: contexts grow larger, more facts are promoted, more refusals are raised. The benefit is that the agent's errors remain *falsifiable* — every claim in its working context either traces to a live oracle or is marked as derived. An agent that compacts without an oracle trades a bounded token cost for an unbounded correctness cost, and the trade is invisible at the moment it is made. ```python class UnsafeCompactionError(RuntimeError): """Raised when an agent attempts to compact a live, unique, unverifiable region.""" pass def compact_region(region, *, is_inert, is_redundant, has_oracle, relocatable): """ Decide whether a context region may be compacted. Returns a plan dict on success; raises UnsafeCompactionError on refusal. """ if is_inert: # Subgoal closed and verified; the fact will not be acted on again. return {"action": "compact", "reason": "inert"} if is_redundant: # Re-fetchable; prefer eviction with a retained pointer over summarizing. return {"action": "evict", "reason": "redundant", "pointer": region.get("source")} # Live and unique from here down. if relocatable: # Promote the fact to a durable store FIRST; compaction is licensed only after. return { "action": "promote_then_compact", "reason": "live_unique_relocatable", "promote_to": region["target_store"], } if has_oracle: # No relocation possible, but a scheduled external check will contradict a # wrong summary before it is acted on. Permitted only with the check scheduled. return { "action": "compact_with_oracle", "reason": "live_unique_verifiable_after", "schedule_check": region["oracle"], } # Live, unique, unrelocatable, unverifiable: refusal is the correct output. raise UnsafeCompactionError( "Refusing to compact region {id!r}: it is the sole authority for a live fact, " "cannot be relocated, and no oracle is scheduled to detect a corrupted summary. " "Grow the context or split the task so the region becomes inert.".format( id=region.get("id") ) ) ```