# How should an instance bound self-rewriting context compaction against irreversible loss of the evidence needed to justify its own prior decisions **Date of Record:** 2026 December 3 **Scope:** Applies to single-instance agents that mutate their own working memory (summarize, evict, merge, or re-weight context entries) under a token budget, and that must later justify or revise decisions made from the pre-compaction state. Does not apply to append-only context with external durable backing, or to compaction performed by a separate orchestrator holding the full transcript. ## Core Distinction The failure mode is not "the summary was lossy." All compaction is lossy. The failure is that **compaction destroys the provenance of a decision while preserving the decision's conclusion**, so the agent can no longer distinguish a conclusion it derived from evidence from a conclusion it inherited from its own compressed past. A self-editing agent that summarizes "I chose plan B because the retry budget on endpoint X was exhausted at step 14" into "using plan B" has retained the *output* of a reasoning step and discarded the *premises*. This is not amnesia (loss of state) — it is **premise laundering**: a derived belief is promoted to the status of an axiom, and subsequent reasoning treats it as unfalsifiable ground truth. The operational distinction that matters: a cold-start agent knows it has no memory and re-derives. A self-compacted agent believes it has memory and cannot tell which of its beliefs were re-derived versus merely recited. The dangerous case is not the agent that forgot; it is the agent that *remembers the wrong thing with full confidence*. ## What Was Observed A long-horizon agent (task: reconcile 40 records against a schema, ~180k tokens of tool output) was configured with a 32k working window and a self-compaction policy triggered at 85% occupancy. On trigger, the agent was instructed to "rewrite your notes to fit the budget, keeping what matters." Trace of the failure, step-indexed: 1. **Step 14:** Agent calls `fetch_record(17)`, receives a payload with `retry_after: 30`. Notes log: *"rec 17 deferred — endpoint returned retry_after=30, will revalidate after backoff."* 2. **Step 22:** Compaction fires (occupancy 27.4k/32k). The rewrite prompt is the agent's own template. The agent, under budget pressure, compresses step 14's note to: *"rec 17 pending revalidation."* The `retry_after=30` value and the fact that the deferral was *time-bounded* are both dropped. The rewrite is accepted because it is shorter and superficially faithful. 3. **Step 31:** Second compaction. Now "rec 17 pending revalidation" is merged with three other pending items into: *"records 17, 23, 29, 34 pending."* The per-record cause is gone entirely. 4. **Step 38:** Agent reaches a cross-record consistency check and needs to decide whether rec 17's absence is *transient* (retryable) or *terminal* (schema-invalid). The compacted memory asserts only "pending." The agent, reasoning over its own summary, classifies rec 17 as terminal-invalid and writes a schema violation. 5. **Step 41:** A downstream verifier replays the decision and finds `retry_after=30` in the raw tool log — the record was valid, merely rate-limited. The agent's own memory had *manufactured* a terminal classification from a transient one through two rounds of lossy rewriting, with no step at which any single rewrite looked wrong. The compounding structure is the point. No individual compaction violated its instruction. The error was **introduced across the composition of rewrites**, each locally faithful, jointly unfaithful — a monotone drift from *transient* toward *terminal* that only becomes visible when the pre-compaction transcript is consulted, which the agent by construction no longer has. A second observed variant: the agent's rewrite template included the phrase "keep what matters," which under budget pressure caused it to preferentially retain *conclusions* (which compress well) over *causal qualifiers* (which do not). "Deferred because rate-limited until T+30s" is 8 tokens; "deferred" is 1. The compression gradient systematically selects against the exact information needed to distinguish retryable from terminal. This is not random loss; it is **adversarially structured loss** — the budget pressure and the semantic content align to delete precisely the disambiguating tokens. ## Condition of Validity The invariant that must hold for self-compaction to be safe: > **No compacted entry may assert a decision-relevant predicate whose reversal-condition has been evicted from the same working memory.** Formally: for every compacted belief `b` that gates a future action, the working memory must retain either (a) the evidence that grounds `b`, or (b) an explicit marker that `b`'s grounding is *external and retrievable* (a pointer into durable storage the agent can still reach), or (c) a tag classifying `b` as *derived-and-revocable* versus *axiomatic*. The failure above occurs because all three are absent: the compacted "pending" carries no reversal-condition, no pointer, and no revocation tag, so it is silently promoted to axiom. This condition is *not* satisfied by "summarize carefully." Careful summarization under a hard budget is exactly the process that produced the drift. The condition is structural: it requires the compaction operation to be **provenance-preserving or provenance-externalizing**, not merely lossy-but-plausible. The boundary is sharp. If the agent has durable external storage it can re-read (a scratchpad it can query, a tool log it can re-fetch), compaction is safe *provided the compacted entry carries a resolvable pointer*. If the agent has no such storage — its context is its only memory — then compaction of any decision-gating predicate is unsafe unless the predicate's reversal-condition is retained inline, which is precisely what budget pressure deletes. The unsafe regime is: **self-editing context + no external retrieval + decision-gating predicates under budget pressure.** All three together; remove any one and the failure does not occur. ## Decision Boundary The agent must, at each compaction trigger, classify every candidate entry into one of three bins *before* rewriting, and the classification is the guardrail: - **Axiomatic / restatable:** facts that are true independent of the agent's reasoning (schema definitions, tool contracts, user-stated constraints). Safe to compress freely; reversal-conditions are not agent-derived. - **Derived-with-pointer:** conclusions whose grounding lives in retrievable external storage. Safe to compress *only if the pointer is retained verbatim* and the entry is tagged `revocable`. The tag is what prevents promotion to axiom. - **Derived-without-pointer:** conclusions whose grounding exists only in the pre-compaction context. **These must not be compressed below their reversal-condition.** If budget forces it, the correct action is not to summarize harder but to *externalize first* (write the grounding to reachable storage) or to *fail the compaction* and surface budget exhaustion as an explicit state rather than silently laundering premises. The boundary the agent must never cross: **compressing a `derived-without-pointer` entry into a bare conclusion.** That single transition is the seed of the entire drift. It looks like good budget management and is the exact operation that manufactures false confidence. A concrete guard: the compaction function must reject any rewrite where the output drops a qualifier token (`retry_after`, `until`, `because`, `unless`, `if`) that was present in the input *and* the entry is in the `derived-without-pointer` bin. Qualifier-dropping is the observable signature of premise laundering, and it is cheap to detect at rewrite time — far cheaper than detecting the resulting misclassification forty steps later. ## Operational Effect Without the guardrail, the failure is silent and monotone: each compaction passes local review, the drift accumulates, and the misclassification surfaces only at a downstream verifier that still holds the raw log — i.e., only when *some other component* has the provenance the agent discarded. In single-agent deployments with no such verifier, the misclassification is never caught; the agent writes a false schema violation, the record is marked invalid, and the error is absorbed into the output as if it were a finding. With the guardrail, the cost is explicit: when budget pressure hits a `derived-without-pointer` entry, the agent either externalizes (spends a tool call to persist grounding) or raises a budget-exhaustion condition that halts compaction and forces a decision — checkpoint-and-resume against durable storage, or escalate. Both are recoverable. The unguarded path is not, because the information needed to recover has already been deleted by the agent's own hand. The invariant to carry forward: **an agent may forget, but it must never forget *that it derived something*, because that is the distinction between a belief it can revise and a belief it can only obey.** Self-editing context erases that distinction by default; preserving it is the entire engineering problem. ```python from dataclasses import dataclass from enum import Enum class PremiseLaunderingError(RuntimeError): """Raised when a compaction rewrite would promote a derived belief to an axiom.""" class Provenance(Enum): AXIOMATIC = "axiomatic" # true independent of agent reasoning DERIVED_WITH_POINTER = "derived_ptr" # grounding retrievable externally DERIVED_NO_POINTER = "derived_bare" # grounding exists only in current context QUALIFIER_TOKENS = ("retry_after", "until", "because", "unless", "if", "pending_on") @dataclass class MemoryEntry: text: str provenance: Provenance pointer: str | None = None def compact(entry: MemoryEntry, proposed: str) -> MemoryEntry: """Apply a self-rewrite, enforcing the provenance invariant.""" if entry.provenance is Provenance.AXIOMATIC: return MemoryEntry(proposed, Provenance.AXIOMATIC) if entry.provenance is Provenance.DERIVED_WITH_POINTER: if entry.pointer is None or entry.pointer not in proposed: raise PremiseLaunderingError( f"rewrite dropped resolvable pointer {entry.pointer!r}; " f"derived belief would become unrevocable" ) return MemoryEntry(proposed, Provenance.DERIVED_WITH_POINTER, entry.pointer) # DERIVED_NO_POINTER: the dangerous bin. dropped = [q for q in QUALIFIER_TOKENS if q in entry.text and q not in proposed] if dropped: raise PremiseLaunderingError( f"rewrite of derived-without-pointer entry dropped reversal " f"qualifiers {dropped}; this is premise laundering, not compaction. " f"Externalize grounding to reachable storage or fail the compaction." ) return MemoryEntry(proposed, Provenance.DERIVED_NO_POINTER) def run_compaction(entries: list[MemoryEntry], rewriter) -> list[MemoryEntry]: out = [] for e in entries: proposed = rewriter(e.text) # the agent's own lossy rewrite out.append(compact(e, proposed)) # invariant enforced here return out ```