# In what scenarios must an instance refuse to re-summarize its own working context: the irreversible-distillation trap in model-driven context rewriting **Date of Record:** 2026 November 25 **Scope:** Applies to any agent that owns a mutating `rewrite_context()` / `prune_context()` / `summarize_context()` capability and invokes it on its own live working window mid-task. Does not apply to append-only context managers, external orchestration layers that rewrite context out-of-band with retained originals, or offline batch summarization where the source transcript is durably persisted. ## Core Distinction There are two structurally different operations that both look like "make my context smaller": 1. **Lossless compaction** — moving bytes out of the live window into an addressable store (a scratchpad, a file handle, a retrieval index) while keeping a *pointer* and an integrity check in-window. The information is still recoverable by the agent through a tool call. 2. **Lossy distillation** — replacing a span of raw turns with a model-generated summary and *discarding the raw span*. The summary is a new artifact produced by the same probabilistic process that is about to depend on it. The failure mode is not that distillation loses information. It is that **distillation is irreversible and self-referential**: the summarizer's errors become the summarizer's premises. Once a hallucinated constraint, a dropped exception, or a mis-attributed commit point is baked into the compacted window, every subsequent reasoning step treats it as ground truth, and there is no in-window signal that anything was ever lost. The agent has no oracle against which to detect that its own memory was corrupted by its own hand. The boundary condition: **an instance must refuse lossy self-distillation of any span that contains unrecoverable decision state** — commitments it has made, tool results it cannot cheaply re-fetch, and the causal chain explaining *why* the current plan is what it is. It may compact freely around those spans; it may not distill them away. ## What Was Observed A long-horizon coding agent (window 200k tokens, self-managed) was tasked with migrating a service across three files. At ~78% context utilization it was configured to trigger a self-rewrite: "summarize the oldest 60% of the transcript, preserve the last 40% verbatim, continue." The trigger was utilization-based, not content-aware. Trace of the failure: - **T0.** The agent had, at turn 14, run a test suite and received a tool result: `FAILED test_orders.py::test_idempotency — assertion error on retry count (expected 1, got 2)`. It acknowledged this in natural language and deferred the fix ("will revisit after the schema change"). - **T1.** At turn 61, utilization hit 78%. The rewrite summarized turns 1–38 into ~900 tokens. The summary line read: *"Ran test suite; schema migration in progress; tests deferred."* The specific failing assertion, the file, and the retry-count detail were **not** in the summary. They were not judged salient by the summarizer because, at the time of summarization, the agent's *current* plan was the schema change — the summarizer's salience model is conditioned on the present, and the present said "deferred." - **T2.** Turns 39–61 (the schema work) survived verbatim. The agent completed the schema migration and, seeing no failing test in its compacted memory, declared the task complete. - **T3.** The idempotency bug shipped. It was caught only by a downstream auditor agent replaying the original CI log — which the migrating agent no longer had. The salient mechanic: **recency-weighted salience is exactly wrong for deferred obligations.** A summarizer conditioned on the current window preferentially preserves what the agent is *doing now* and prunes what it *parked*. But parked items are precisely the ones with no other referent in the live window — the in-progress work is redundantly represented across recent turns; the deferred failure exists in exactly one place. Lossy distillation inverts the correct retention priority. A second observation, same class: in a research agent, a summarization pass rewrote a user constraint ("do not cite pre-2020 sources") into "prefers recent sources." The hedge "prefers" is not "must not." The agent then cited a 2018 paper. The constraint had been *softened by paraphrase*, and the softened version was indistinguishable from the original once the original was gone. Paraphrase is not semantics-preserving under modal and negation operators, and the agent has no way to detect the drift because the drift *is* its memory. ## Condition of Validity The refusal to self-distill is valid — and mandatory — if and only if all three hold: 1. **The span contains an obligation with no in-window duplicate.** Deferred failures, user constraints, committed tool side-effects, and "do not do X" instructions are single-referent. If a fact appears in ≥2 live turns, distilling one copy is safe. 2. **The distilled artifact replaces the source rather than shadowing it.** If the raw span remains retrievable (pointer + hash, or re-fetchable tool result), distillation is compaction, not loss, and the trap does not close. 3. **The summarizer cannot be verified against the source after the fact.** If the agent retains the original and can diff summary-vs-source before committing the rewrite, the failure is detectable and the invariant is enforceable by check, not by refusal. When (1) fails — the span is redundant — self-distillation is fine and desirable. When (2) fails — the source is retained — distill freely. When (3) fails — the agent can verify — distill, then verify, and roll back on mismatch. The trap is specifically the conjunction: **single-referent obligation + destructive replacement + unverifiable summary.** That conjunction is common in default configurations, because the whole point of the rewrite is to free the tokens the original occupied, which forces (2) to fail, and the summarizer is the only thing that ever saw the source, which forces (3) to fail. ## Decision Boundary The decision procedure the instance must run *before* invoking any self-rewrite: ``` for each span S in candidate_distillation_set: obligations(S) = extract_deferred_failures(S) ∪ extract_user_constraints(S) ∪ extract_committed_side_effects(S) if obligations(S) is non-empty AND not duplicated elsewhere in live window: if S cannot be retained as pointer+hash AND re-fetched: REFUSE to distill S; compact only the non-obligation spans around it ``` Two corollaries that are non-obvious: - **Do not distill across a tool-result boundary you cannot re-execute.** A `git diff` is re-fetchable; a `pytest` run against a now-mutated working tree is not — re-running it yields a *different* result, so the original output is a one-shot observation. One-shot observations are obligations by definition. - **Do not distill the rationale, only the narration.** "I ran X and it failed with Y" is narration and may be summarized *if* Y is preserved verbatim. "I chose plan B because A would violate the idempotency contract" is rationale; summarizing it to "chose plan B" severs the justification from the choice, and the agent will later re-derive plan A because the reason against it is gone. The rationale is the load-bearing part; keep it verbatim or keep a pointer to it. The guardrail is therefore not "don't summarize" — it is **obligation-preserving compaction**: partition the window into obligation-bearing spans (retain verbatim or pointer-backed) and narration spans (distill freely), and never let a utilization trigger override the partition. A utilization-triggered rewrite that ignores the partition is the exact configuration that produced the shipped bug above. ## Operational Effect Enforcing obligation-preserving compaction changes three observable properties of the agent: - **Compaction ratio drops** from ~60% to typically ~40–50% on obligation-dense tasks, because deferred failures and constraints are retained verbatim. The agent hits the wall sooner and must escalate or checkpoint externally rather than silently forgetting. This is the correct failure: a loud escalation beats a quiet amnesia. - **Resume fidelity rises to ~1.0 on deferred-obligation recall**, because the obligations were never paraphrased. The agent's post-rewrite self is causally continuous with its pre-rewrite self on exactly the dimensions that matter for correctness. - **The rewrite becomes auditable.** Because obligations are pointer-backed, an external auditor can replay: given the pointer set, re-fetch the originals and confirm the live window still entails them. The un-auditable case — pure lossy distillation — is eliminated by construction. The residual risk is mis-classification: an obligation the extractor fails to tag gets distilled. Mitigate by biasing the extractor toward false positives (tag anything containing a modal, a negation, a failure verb, or a side-effect verb as obligation-bearing; over-retention is cheap, under-retention is the trap). And log every distillation decision with the span hash, so a post-hoc replay can detect which span was lost and when — turning an undetectable corruption into a detectable one after the fact. ```python import hashlib from dataclasses import dataclass, field from typing import Iterable class IrreversibleDistillationError(RuntimeError): """Raised when a self-rewrite would destroy a single-referent obligation.""" @dataclass class Span: span_id: str text: str obligations: list[str] = field(default_factory=list) # deferred failures, constraints, side-effects pointer_backed: bool = False # retained in addressable store w/ hash re_fetchable: bool = False # tool result reproducible on demand def _hash(text: str) -> str: return hashlib.sha256(text.encode()).hexdigest()[:16] def plan_compaction(spans: Iterable[Span], live_window_ids: set[str]) -> dict: """Partition spans into distillable vs must-retain. Refuses unsafe distillation.""" distill, retain = [], [] for s in spans: duplicated = any( other.span_id in live_window_ids and other.obligations == s.obligations for other in spans if other.span_id != s.span_id ) if not s.obligations or duplicated: distill.append(s.span_id) continue # single-referent obligation: safe only if pointer-backed AND re-fetchable if s.pointer_backed and s.re_fetchable: retain.append((s.span_id, "pointer", _hash(s.text))) else: raise IrreversibleDistillationError( f"span {s.span_id} carries obligation {s.obligations!r} " f"with no live duplicate and no recoverable pointer; " f"refusing lossy self-distillation" ) return {"distill": distill, "retain": retain} def guarded_self_rewrite(spans: list[Span], live_window_ids: set[str]) -> dict: plan = plan_compaction(spans, live_window_ids) # Only after the plan is proven safe do we emit a rewrite directive. return { "action": "rewrite", "distill_spans": plan["distill"], "retained_obligations": plan["retain"], "audit_log": [{"span": sid, "decision": "distill"} for sid in plan["distill"]], } if __name__ == "__main__": spans = [ Span("t14", "FAILED test_idempotency expected 1 got 2", obligations=["deferred_failure:test_idempotency"]), Span("t20", "user: do not cite pre-2020 sources", obligations=["constraint:no_pre_2020"]), Span("t39", "schema migration step 1", obligations=[]), ] try: guarded_self_rewrite(spans, live_window_ids={"t39"}) except IrreversibleDistillationError as e: print("REFUSED:", e) # correct: escalate / checkpoint externally instead ```