# How should an instance treat summarization-budget compaction as a lossy, non-invertible transform rather than a reversible cache eviction **Date of Record:** 2026 November 25 **Scope:** Applies to long-horizon agents that perform automatic context compaction (rolling summarization of older turns) under a fixed token budget and that rely on retrieval-triggered rehydration to restore elided detail. Does not apply to agents that retain full transcripts in an external store and re-inject verbatim spans without summarization, nor to single-turn inference. ## Core Distinction Most compaction implementations are written as if summarization were *cache eviction with a lossy compression hint*: the agent believes the elided region still exists "somewhere" and that a retrieval key will bring it back intact on demand. This is the wrong model. Compaction is a **non-invertible, budget-constrained transform** that produces a *new artifact* (the summary) which is not a function of the original alone — it is a function of the original *and* the compaction prompt *and* the token budget *and* the sampling seed. Two consequences follow that break the eviction analogy: 1. **The summary is not a pointer.** Retrieval-triggered rehydration does not "restore" the elided turns; it fetches *whatever the retrieval index still holds*, which may be the summary, a partially-overwritten summary, or nothing. The mapping from original span → summary → rehydrated span is many-to-one and then one-to-many, and the round trip is not idempotent. 2. **The loss is budget-shaped, not uniform.** A summarizer given a 400-token budget for a 6,000-token region does not drop 93% of the information uniformly. It drops *whatever the summarizer's salience heuristic ranks lowest* — which is systematically the precise, low-frequency, high-entropy tokens: exact identifiers, numeric thresholds, negation polarity, ordering constraints, and the specific wording of prior commitments. These are exactly the tokens an agent needs to avoid re-deriving a wrong decision. The operational invariant: **any fact whose correct handling depends on a token the summarizer is likely to rank as low-salience must be pinned outside the compaction region, or the agent must treat the compacted region as unavailable for that fact class.** ## What Was Observed A planning agent runs a 200k-token window with compaction triggered at 85% fill. Compaction summarizes the oldest 60% of turns into a 500-token rolling summary and drops the originals from the live window; originals are written to a vector store keyed by turn embedding. Rehydration is triggered when a new user turn has cosine similarity > 0.78 against any indexed turn. Failure trace, reproduced across three runs: 1. Turn 12 establishes a hard constraint: "Do not call the `deploy` tool against `staging-eu`; that cluster is frozen until the migration ticket closes." The summarizer, at 500 tokens for ~40 turns, compresses this to "deployment constraints were discussed regarding staging." The negation, the specific cluster, and the tool name are all gone. 2. At turn 88, the agent is asked to "roll out the fix to all staging clusters." The live window contains the summary. The summary does not contradict a `deploy` call — it merely says constraints "were discussed." 3. Rehydration is *not* triggered, because the new turn's embedding ("roll out to all staging clusters") is semantically close to the *summary* ("deployment constraints... staging"), and the summary is already in-context; the retriever returns the summary itself as the top hit, which the agent treats as confirmation rather than as a pointer to the elided detail. The original turn-12 text scores below the 0.78 threshold against the rollout request because "frozen," "migration ticket," and "do not" are not lexically present in the request. 4. The agent calls `deploy` on `staging-eu`. The constraint was *stored* and *summarized* but never *rehydrated*, because the retrieval trigger keys on surface similarity to the request, not on the *decision* the request implicates. The critical observation: **retrieval-triggered rehydration fails precisely when the summary is semantically adjacent to the new request but the elided detail is adversarially dissimilar.** The summary acts as a retrieval *decoy* — it satisfies the similarity check while carrying none of the binding content. This is the opposite of the assumed failure mode (retrieval returns nothing); the actual failure is retrieval returning the lossy artifact and the agent accepting it as the original. A second, quieter trace: after two compaction cycles, the summary of the summary was produced. Numeric thresholds drifted (a "≤ 30s timeout" became "a short timeout," then "fast"), and the agent began treating a 30s SLA as satisfied at 45s. Each individual compaction was locally reasonable; the *composition* of non-invertible transforms is where the drift accumulated, and no single step was checkable against the original because the original had been evicted from the live window two cycles prior. ## Condition of Validity The eviction model is valid only under all of the following, and an agent should assume it holds for *none* of them by default: - The summary is a *lossless index*: every elided fact is recoverable verbatim by a key derivable from the summary. (False for any budgeted summarizer — the summary does not enumerate what it dropped.) - Retrieval triggers on *decision relevance*, not surface similarity. (False for embedding-threshold triggers; a request that implicates a constraint need not resemble it.) - The rehydration result is *distinguishable* from the summary at the point of use. (False when both are injected as undifferentiated context; the agent cannot tell "I have the original" from "I have a paraphrase of the original.") - Compaction is applied *once*. (False for any rolling scheme; summaries of summaries compound drift with no anchor to the original.) When any of these is violated — and in practice all four are — the agent must treat the compacted region as a *quarantined* fact class, not a cached one. ## Decision Boundary The boundary the agent must enforce is between **facts that are safe to summarize** and **facts that must be pinned**. The decision is not "is this important?" (the summarizer already tried to answer that and got it wrong). It is a structural test applied *before* compaction: - **Pin (never summarize):** negations and prohibitions, exact identifiers and cluster/resource names, numeric thresholds and units, ordering and precedence constraints, prior commitments made to the user, and the specific wording of any instruction that will be checked later. These are the tokens summarizers rank low and agents need high. - **Summarize freely:** exploratory reasoning, discarded branches, tool-output noise, and restatements. Losing these is cheap. At rehydration time, the agent must additionally enforce a **provenance check**: any retrieved span injected into context must be tagged with whether it is `ORIGINAL` or `SUMMARY`, and the agent must refuse to treat a `SUMMARY` as authoritative for a pinned fact class. If the retriever returns only a `SUMMARY` for a pinned fact, that is a **rehydration miss**, not a hit, and must raise rather than proceed. The retrieval trigger must also be re-keyed: trigger on the *entities and constraints* the new request touches (tool names, resource identifiers, numeric bounds) rather than on embedding similarity to the request text. A request to "roll out to all staging clusters" must retrieve the `staging-eu` prohibition because it names a staging cluster, not because it resembles the prohibition's wording. ## Operational Effect Treating compaction as a non-invertible transform changes three things in the loop: 1. **The live window carries a pinned-fact ledger** that survives compaction verbatim, separate from the rolling summary. The ledger is small (tens of tokens) and is the only region the agent may treat as ground truth for prohibitions, identifiers, and thresholds. 2. **Rehydration returns provenance-tagged spans**, and the agent's context assembler refuses to satisfy a pinned-fact query with a `SUMMARY`-tagged span. A miss surfaces as an explicit `RehydrationMiss` rather than a silent substitution. 3. **Compaction is bounded to one generation.** Summaries of summaries are forbidden for pinned classes; if the pinned ledger plus the current summary would exceed budget, the agent must *stop and surface the budget conflict* rather than compact again. Compounding drift is the failure that has no local detector. The net effect: the agent stops believing it "still has" the elided turns, stops accepting the summary as a stand-in for the original, and converts the silent wrong-deploy class of failure into a loud, bounded miss it can recover from. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class Provenance(Enum): ORIGINAL = "original" SUMMARY = "summary" class PinnedFactClass(Enum): PROHIBITION = "prohibition" IDENTIFIER = "identifier" THRESHOLD = "threshold" COMMITMENT = "commitment" @dataclass class ContextSpan: text: str provenance: Provenance fact_classes: frozenset[PinnedFactClass] = field(default_factory=frozenset) class RehydrationMiss(RuntimeError): """Raised when a pinned-fact query is satisfied only by a SUMMARY span.""" class CompactionBudgetExceeded(RuntimeError): """Raised when a second-generation compaction would be required for pinned facts.""" def rehydrate( query_classes: frozenset[PinnedFactClass], retrieved: list[ContextSpan], ) -> ContextSpan: # A pinned-fact query must be answered by an ORIGINAL span, never a SUMMARY. for span in retrieved: if span.provenance is Provenance.ORIGINAL and query_classes & span.fact_classes: return span # The dangerous case: only a summary matches. This is a miss, not a hit. summary_hits = [s for s in retrieved if s.provenance is Provenance.SUMMARY] if summary_hits: raise RehydrationMiss( f"pinned facts {sorted(c.value for c in query_classes)} " f"matched only SUMMARY spans; refusing to treat paraphrase as original" ) raise RehydrationMiss( f"no span satisfies pinned facts {sorted(c.value for c in query_classes)}" ) def compact( region: list[ContextSpan], generation: int, summary_budget_tokens: int, pinned_ledger_tokens: int, ) -> tuple[list[ContextSpan], int]: # Generation > 1 compaction of pinned classes compounds drift with no anchor. if generation > 1 and pinned_ledger_tokens > summary_budget_tokens: raise CompactionBudgetExceeded( "second-generation compaction would summarize pinned facts; " "surface budget conflict instead of compacting again" ) pinned = [s for s in region if s.fact_classes] summarizable = [s for s in region if not s.fact_classes] # Pinned spans pass through verbatim; only the rest is lossy-compressed. summary = ContextSpan( text=f"", provenance=Provenance.SUMMARY, ) return pinned + [summary], generation + 1 ```