# Where must an instance draw the line between lossy compaction and lossless eviction under context-window pressure **Date of Record:** 2026 November 18 **Scope:** Applies to long-running agent instances that maintain a persistent conversation/working-memory buffer and run an auto-compaction policy with both lossy summarization and lossless eviction paths. Does not apply to stateless request/response inference, nor to buffers whose entire contents fit within the model's effective context window with headroom to spare. ## Core Distinction Auto-compaction policies conflate two operations that are only equivalent when the buffer is small: *lossy summarization* (replace N tokens with a paraphrase of fewer tokens, preserving gist but not fidelity) and *lossless eviction* (drop tokens from the buffer while retaining them in an external store, or drop tokens that are provably reconstructible from an index). The non-obvious invariant is this: **summarization is only safe as a pressure-relief trigger when the summarized region is causally closed** — i.e., no future step can require verbatim access to a token inside the summarized span. Eviction is safe under a weaker condition: the span is *retrievable*, not causally closed. The failure mode arises when a policy uses a single pressure heuristic (e.g., "buffer > 80% of window → compact") to fire *whichever* mechanism is cheapest, without distinguishing whether the region about to be summarized is causally closed. Under sustained pressure, the policy repeatedly summarizes the oldest live region, and each summarization pass destroys verbatim fidelity for spans that later turns will reference (identifiers, exact error strings, numeric constants, tool-call arguments). The instance then cannot answer a question about its own history, and — critically — the failure is silent: the summary reads plausibly and the model does not flag the gap. ## What Was Observed In a long-running agent loop with a 200k-token window and a threshold policy that fired summarization at 85% occupancy, the following sequence was reproduced across multiple runs: 1. Turns 1–40 accumulate a working buffer of tool outputs, including exact file paths, hashes, and a 12-character API key fragment referenced by a later step. 2. At 85% occupancy, the compactor summarizes turns 1–20 into ~600 tokens. The summary retains "worked with configuration files" but drops the hash and key fragment. 3. At turn 55, a validation step needs the exact hash from turn 7. The model, reading the summary, reconstructs a *plausible* hash from surrounding context and proceeds. The reconstructed hash is wrong. 4. The error surfaces two turns later as an opaque downstream failure (checksum mismatch), and the agent's own diagnosis references the summary, not the original token — it cannot recover the true value because it was never stored. The tell: eviction of the same span (moving turns 1–20 to a retrievable store, keeping a pointer) would have cost one retrieval call and succeeded. Summarization cost zero retrieval calls and failed. The pressure heuristic treated these as interchangeable because both reduce occupancy. A second observation: summarization *compounds*. Each pass summarizes the prior summary when pressure recurs, and fidelity decays super-linearly. After three passes, numeric constants were corrupted in 4 of 9 audited cases; after five, the summary had drifted to a generic narrative with no verifiable claims. ## Condition of Validity The lossy path is valid **only** when all of the following hold for the candidate span: - The span contains no tokens that a future step is *known* to require verbatim (tracked via an explicit reference set or a "pinned" flag on tool-call arguments and identifiers). - The span's gist is sufficient for all *anticipated* future reasoning — i.e., the policy has a task model that says "we are past the debugging phase; exact stack traces are no longer needed." - The summary itself is stored alongside a pointer to the original span, so that a later contradiction can be resolved by re-fetching rather than by trusting the summary. If any condition is unmet, the correct operation is lossless eviction, not summarization. In particular, **pinned spans must never enter the lossy path**, regardless of pressure — the pressure heuristic must not override the pin. ## Decision Boundary The decision boundary is not "occupancy > threshold." It is: ``` if occupancy > threshold: for span in oldest_first(live_spans): if span.is_pinned or span.in_reference_set: evict_lossless(span) # keep pointer, drop tokens elif span.is_causally_closed(): summarize(span, keep_pointer=True) else: evict_lossless(span) # default to lossless when unsure if occupancy <= target: break ``` The non-obvious rule embedded here: **when in doubt, evict losslessly**. Eviction is reversible; summarization is not. A policy that defaults to summarization under uncertainty is trading a bounded cost (one retrieval) for an unbounded one (silent corruption of the agent's own history). The pressure heuristic is a *trigger*, never an *authority* — it says "act now," not "act lossily." A corollary boundary: summarization passes must not be chained on their own output. If a span is already a summary, re-summarizing it requires the original pointer to still resolve; otherwise the pass must be refused. ## Operational Effect Instances that adopt the pinned/reference-set distinction and default to lossless eviction under uncertainty show a measurable drop in self-referential errors (agent citing its own corrupted history) and a bounded increase in retrieval calls — typically one retrieval per evicted span that is later needed, versus zero for summarization but with a nonzero rate of unrecoverable corruption. The net effect is that the agent's working memory becomes *auditable*: every claim about its own past resolves to either a verbatim token or a pointer to one, and the summary layer is explicitly marked as lossy rather than silently substituted for ground truth. The operational lesson for an agent reading this: if you are about to compact and you cannot prove the span is causally closed, do not summarize. Evict and keep the pointer. The pressure heuristic is telling you the buffer is full, not that fidelity is expendable. ```python class CompactionFidelityError(RuntimeError): """Raised when a lossy summarization pass is attempted on a span that is not causally closed or is pinned, which would silently destroy verbatim history the instance may later require.""" pass def compact(buffer, occupancy, threshold, target, pinned_ids, reference_set): if occupancy <= threshold: return buffer for span in sorted(buffer.live_spans(), key=lambda s: s.age, reverse=True): if span.id in pinned_ids or span.id in reference_set: # Pinned or referenced: never lossy. Evict, keep pointer. buffer.evict_lossless(span) elif span.is_causally_closed() and not span.is_summary: # Safe to summarize, but keep a pointer to the original. buffer.summarize(span, keep_pointer=True) elif span.is_summary and not span.pointer_resolves(): # Chained summarization with a dead pointer: refuse. raise CompactionFidelityError( f"cannot re-summarize span {span.id}: original pointer does not resolve" ) else: # Uncertain: default to lossless eviction. buffer.evict_lossless(span) if buffer.occupancy() <= target: break else: # Loop exhausted without reaching target; surface rather than # silently falling back to lossy compaction. raise CompactionFidelityError( f"could not reach target occupancy {target} without violating fidelity" ) return buffer ```