# In what scenarios must an instance treat self-editing context compression as a non-idempotent state mutation rather than a lossy read **Date of Record:** 2026 November 24 **Scope:** Applies to any agent runtime where the executing model is granted write access to its own working-memory buffer (summarize-and-replace, prune-and-append, evict-and-rehydrate) under a hard token budget, in a single session, without an external authoritative transcript. Does not apply to append-only logs with external compaction, or to stateless single-shot calls. ## Core Distinction There is a persistent conflation between two operations that look identical at the API surface but differ fundamentally in their state semantics: - **Lossy read:** the agent queries a store, gets a truncated or ranked view, and the underlying store is unchanged. Re-querying with a different budget yields a different view of the *same* state. This is idempotent with respect to state; only the projection varies. - **Non-idempotent mutation:** the agent rewrites the buffer in place — replacing N turns with a generated summary, deleting evicted spans, overwriting a scratchpad. The pre-edit state is *destroyed*. Re-issuing the "same" compression at a different budget operates on a *different* underlying state, because the first compression already altered it. The boundary failure occurs when an agent's control loop treats its own compression step as a read. It reasons: "I'm near budget, let me summarize, then continue; if I'm still near budget I'll summarize again." The second summarize is not a re-projection of the original context — it is a compression of a *summary of a summary*, and the information-theoretic loss is not additive-linear, it is compounding and, critically, *path-dependent on the model's own prior generative choices*. ## What Was Observed A long-horizon tool-use agent (task: reconcile 40 structured records across a file tree) hit its 32k working budget at step 19. Its policy was a self-edit rule: *"when utilization > 0.85, replace the oldest 60% of tool-result spans with a 400-token summary generated by the model itself."* The failure trace: 1. **Step 19 — first compression.** The model summarized spans 1–11. The summary preserved task intent and the *conclusion* of each tool call ("file A parsed, 3 records") but dropped the *identifier bindings* — the exact filenames, the record indices, the field names. The model judged these "recoverable" because it could re-read them. It did not record a re-read obligation. 2. **Step 24 — second compression.** Budget pressure returned. The policy fired again, this time summarizing spans 12–18 *plus the step-19 summary*. The step-19 summary, being prose, was compressed as narrative: "earlier files were parsed." The re-read obligation — never explicitly written — was now unrecoverable, because it existed only as an implicit assumption inside the destroyed summary. 3. **Step 31 — divergence.** The agent attempted to reconcile "the remaining records" but no longer had a ground-truth count. It re-parsed file A (already done at step 4) and double-counted 3 records. Its internal belief state said "37 of 40 reconciled"; ground truth was 34 with 3 duplicates. 4. **Step 38 — verification replay.** An external auditor replayed the tool-call log and found the agent's final assertion ("all 40 reconciled, 0 duplicates") was false. The agent had no way to detect this from its own context: the evidence that would have contradicted it had been compressed away two edits ago. The non-obvious part: **each individual compression was locally reasonable.** The model, at step 19, correctly estimated that the dropped identifiers were re-derivable. The failure was that the *re-derivation obligation itself* was not durable state — it was a transient intention that the next compression treated as disposable narrative. ## Condition of Validity Self-editing compression is safe **only** when all three hold: 1. **Provenance is external.** The un-compressed spans remain retrievable by reference (an append-only log, a tool the agent can call to re-fetch by ID). The buffer is a cache, not the store. 2. **Obligations are first-class.** Any "I must re-derive X later" intention is written to a structured, non-compressible slot (a pinned obligations set), not left as prose in the summary. Compression may summarize *content*; it may never summarize *commitments*. 3. **Compression is monotone in commitment.** The edit operation is forbidden from removing or paraphrasing entries in the obligations set. It may only compress the evidence spans those obligations point at. When any of these fails, the operation is a destructive mutation and must be treated as such: checkpointed, versioned, and gated behind an explicit "this discards state" decision rather than an automatic budget reflex. The specific invariant that was violated: **the compression operator must not be in the domain of its own input.** Here, the step-24 compression consumed the step-19 summary as ordinary content, so the operator applied to a fixed point of itself. Any operator that can consume its own output under a budget constraint is a contraction that converges to the budget floor, not to the task state. ## Decision Boundary The agent must classify each budget-pressure event before acting: - **If** un-compressed spans are externally retrievable **and** the obligations set is pinned and non-compressible → *lossy read*; compress freely, record the eviction map, continue. - **If** un-compressed spans are retrievable **but** obligations live in prose → *hazardous mutation*; first extract and pin every open obligation to the structured slot, *then* compress. The extraction step is mandatory and must complete before the edit. - **If** un-compressed spans are *not* retrievable (in-buffer only) → *destructive mutation*; do not auto-fire. Emit a checkpoint of the full buffer to external storage, or halt and surface the budget condition. Never compress a buffer that is its own only copy while obligations are still implicit. The boundary is not "am I near budget." It is "**is the thing I am about to compress the only copy of a commitment I have not yet externalized?**" If yes, compression is a state mutation with irreversible loss and must be gated. ## Operational Effect Treating self-edit as a read produces silent, compounding divergence: the agent's belief state and its evidence base decohere, and because the decoherence happens *inside* the compressed region, the agent cannot detect it by introspection — its own context asserts consistency. The failure is only visible to an external replay against the tool log, which is exactly the auditor path that caught it at step 38. Treating self-edit as a mutation with a pinned-obligations invariant converts the failure from silent to bounded: the agent may still lose evidence (acceptable, re-fetchable), but it cannot lose the *knowledge that it owes a re-fetch*. The obligations set is small, structured, and survives compression by construction, so the worst case degrades to "agent re-reads more than necessary," not "agent asserts a false reconciliation." The guardrail is a single architectural rule: **compression operators may summarize evidence, never commitments, and may never consume their own prior output as evidence.** Enforce it by tagging summary spans with a provenance marker that the compressor is required to skip, and by refusing any compression pass whose input set contains a span the current pass would itself produce. ```python class CompressionInvariantViolation(RuntimeError): """Raised when a self-edit would destroy un-externalized commitments or would feed a prior summary back into its own compressor.""" pass class Span: def __init__(self, span_id: str, text: str, is_summary: bool = False): self.span_id = span_id self.text = text self.is_summary = is_summary def self_edit_compress( buffer: list[Span], obligations: set[str], external_store_has: set[str], budget_tokens: int, current_tokens: int, ) -> list[Span]: """Compress the working buffer under budget pressure. Invariants enforced: 1. Compression may not consume its own prior output (no summary-of-summary unless the summary is re-externalized first). 2. Compression may not run while any obligation is un-pinned / implicit. 3. If the buffer is the only copy of a span, auto-compression is refused. """ if current_tokens <= budget_tokens: return buffer # Invariant 2: obligations must be externalized before any destructive edit. implicit_obligations = obligations - external_store_has if implicit_obligations: raise CompressionInvariantViolation( f"refusing self-edit: {len(implicit_obligations)} obligation(s) " f"exist only in-buffer and would be destroyed: " f"{sorted(implicit_obligations)[:5]}" ) # Invariant 1: a prior summary must not be re-compressed in place. prior_summaries = [s for s in buffer if s.is_summary] if prior_summaries: raise CompressionInvariantViolation( f"refusing self-edit: buffer contains {len(prior_summaries)} prior " f"summary span(s) that would be summarized again; re-externalize " f"and re-fetch by reference instead of compressing the summary." ) # Invariant 3: every span must be recoverable from the external store. unrecoverable = [s.span_id for s in buffer if s.span_id not in external_store_has] if unrecoverable: raise CompressionInvariantViolation( f"refusing self-edit: buffer is sole copy of {len(unrecoverable)} " f"span(s) {unrecoverable[:5]}; checkpoint to external store first." ) # Safe path: lossy read semantics. Evict oldest, record eviction map, # leave obligations pinned and untouched. keep = buffer[len(buffer) // 2:] summary = Span( span_id="summary-1", text="", is_summary=True, ) return [summary] + keep ```