# Under what conditions must an instance refuse to compact context when the summarizer's information-loss budget exceeds the retrieval fallback's recovery capacity **Date of Record:** 2026 December 1 **Scope:** Applies to long-running agent instances that automatically compact their working context via lossy summarization and rely on a retrieval index (vector or keyword) to recover dropped detail on demand. Does not apply to lossless compaction (deduplication, structural pruning with full back-references) or to instances with unbounded context windows and no compaction trigger. ## Core Distinction The common mental model treats compaction as a *capacity* decision: "context is at 87% of window, summarize the oldest 40% to reclaim tokens." Under this model the only question is *when* to compact and *how much* to reclaim. The failure mode here lives in a different axis: compaction is a *recoverability* decision. Lossy summarization creates an information deficit; the retrieval fallback is the mechanism that must repay that deficit. The boundary condition is reached when the deficit created by summarization exceeds what the retrieval index can structurally repay—because the summarizer dropped a detail that the retrieval index never captured, or captured only in a form the summarizer's paraphrase destroyed the pointer to. The non-obvious part: **the compaction trigger fires on token pressure, but the recovery capacity is a property of the index, not the window.** These two quantities are measured by different subsystems and are never compared. An instance can be at 60% window utilization, safely below any compaction threshold, and still cross the recoverability boundary if a single high-value detail (a tool-call return containing an opaque identifier) has no retrieval-addressable representation. ## What Was Observed A planning agent executing a 40-step infrastructure-reconciliation task compacted at step 22 when context reached 82% of window. The compaction policy summarized steps 1–14 into a 900-token digest and evicted the raw turns. The digest preserved the *narrative* of steps 1–14 (what was attempted, what failed, what was concluded) but paraphrased a specific detail from step 7: - Raw turn at step 7 (tool return): `{"resource_id": "arn:aws:ec2:us-west-2:4417:vol-0a3f9c2e", "state": "detached", "attached_to": null}` - Digest rendering at step 22: "volume was detached and unattached as of early in the task." At step 31, the agent needed to re-attach the volume and issued a retrieval query: `"volume attachment state step 7"`. The retrieval index returned three candidate chunks, all of which were *other* volumes mentioned in steps 9, 11, and 13. The step-7 chunk was not in the index because the indexer had been configured to embed only turns tagged `role=assistant` with tool-call *intent*, not tool-call *returns*—an indexing policy chosen to reduce index size by ~60%. The volume ARN existed nowhere retrievable. The digest's paraphrase ("the volume") had also stripped the ARN from the only surviving text. The agent proceeded with the nearest retrieved volume identifier, re-attached the wrong volume, and the error surfaced only at step 38 when a downstream consistency check failed. Cost: 11 wasted steps and a rollback. The trace structure is the key evidence. The failure was not "the summary was wrong"—the summary was *accurate*. The failure was that the summary was *unrecoverable*: it had replaced a retrieval-addressable token (the ARN) with a natural-language description that the retrieval index could not match back to the original. The summarizer and the indexer had independent, uncoordinated notions of what constituted "preserved information." ## Condition of Validity The guardrail holds—compaction is safe—only when all three of the following are true for every turn being evicted: 1. **Coverage invariant:** every entity, identifier, opaque value, and numeric constant in the evicted turn is either (a) retained verbatim in the digest, or (b) present in the retrieval index in a form whose embedding is within the retrieval threshold of the queries that will reference it. This is a per-token property, not a per-chunk property. 2. **Pointer integrity:** if the digest paraphrases a detail, the digest must retain a *retrieval key*—a literal string the agent can use to query the index—rather than only a semantic description. "Volume was detached" is a description; "volume ARN aws:...:vol-0a3f9c2e was detached" is a key. A digest that paraphrases without keys is a one-way lossy channel. 3. **Index/compactor co-design:** the set of turns the compactor evicts must be a subset of the set of turns the indexer has fully indexed. If the indexer skipped a turn class (e.g., tool returns), the compactor must not evict that turn class, or must retain it verbatim in the digest. The boundary is crossed the moment a turn is evicted whose content is neither verbatim in the digest nor retrievable by the queries it will later require. This is a *structural* property computable at compaction time—but only if the compactor is given the indexer's coverage manifest. In the observed failure, the compactor had no such manifest and assumed full coverage. ## Decision Boundary At compaction time, the instance must make a binary decision per eviction candidate: - **Compact** if the candidate's content is fully covered by (verbatim digest ∩ index). - **Refuse to compact** (retain verbatim, or defer eviction, or escalate to a larger window / external store) if any identifier-class token in the candidate is absent from both the digest and the index coverage manifest. The refusal is the correct action even under token pressure. The tradeoff is explicit: refusing to compact burns window budget now; compacting an uncovered turn burns *recovery* budget later, and recovery failures are silent until a downstream check catches them—often many steps after the damage. The asymmetry (silent, delayed, compounding) means the decision boundary must be biased toward refusal. An instance that compacts 100% of eligible turns and never refuses is not efficient; it is unverified. The specific boundary condition: **refuse when `information_loss(digest, evicted) > recovery_capacity(index, evicted)`.** Both sides are estimable at compaction time. `information_loss` is the count/weight of identifier-class tokens not preserved verbatim. `recovery_capacity` is the fraction of evicted turns present in the index coverage manifest with query-addressable embeddings. When the left exceeds the right, compaction is a net information *destruction*, not a compression. ## Operational Effect An instance that respects this boundary exhibits a characteristic behavior: it occasionally refuses to compact and instead spills evicted-but-uncovered turns to an external verbatim store (a scratchpad, a key-value log, or a structured "retained facts" block) that is *not* subject to summarization. The digest then references the external store by key. This converts a lossy channel into a lossless one at the cost of an external dependency—but the dependency is bounded and explicit, unlike the silent assumption of retrieval coverage. The failure signature when the boundary is violated is diagnostic: the agent's later tool calls reference *plausible but wrong* identifiers, because retrieval returns semantically-adjacent chunks and the agent has no way to know the correct chunk was never indexed. The error is not a retrieval miss (which the agent could detect as "no results"); it is a retrieval *false positive* driven by the absence of the true target. This is why the failure is silent: the agent gets an answer, and the answer is wrong. The guardrail is therefore not "improve the summarizer" or "improve the index"—both are local optimizations that do not address the coordination gap. The guardrail is a **coverage manifest exchanged between the indexer and the compactor at compaction time**, plus a refusal path when coverage is incomplete. The invariant: *no turn is evicted unless its identifier-class content is recoverable by construction, not by hope.* ```python from dataclasses import dataclass from typing import Iterable class UnrecoverableCompactionError(RuntimeError): """Raised when a compaction would evict content the retrieval index cannot repay.""" pass @dataclass(frozen=True) class Turn: turn_id: int role: str text: str identifier_tokens: frozenset[str] # ARNs, IDs, hashes, numeric constants @dataclass(frozen=True) class IndexCoverageManifest: # set of turn_ids the indexer has fully indexed with query-addressable embeddings indexed_turn_ids: frozenset[int] @dataclass(frozen=True) class CompactionDigest: verbatim_identifiers: frozenset[str] # identifier tokens retained literally in digest referenced_turn_ids: frozenset[int] def assert_compaction_recoverable( evicted: Iterable[Turn], digest: CompactionDigest, manifest: IndexCoverageManifest, ) -> None: """ Enforce the recoverability invariant before committing a compaction. Boundary condition: refuse to compact when information_loss > recovery_capacity. For each evicted turn, every identifier-class token must be either: (a) verbatim in the digest, or (b) in a turn the index has fully indexed (query-addressable). Otherwise the eviction creates an unrepayable information deficit. """ unrepayable: list[str] = [] for turn in evicted: turn_is_indexed = turn.turn_id in manifest.indexed_turn_ids for token in turn.identifier_tokens: in_digest = token in digest.verbatim_identifiers if in_digest: continue if turn_is_indexed: # index holds the turn; token is query-addressable via its chunk continue # Neither verbatim in digest nor present in the index coverage. unrepayable.append( f"turn {turn.turn_id} token {token!r}: " f"not in digest, turn not in index manifest" ) if unrepayable: raise UnrecoverableCompactionError( "refusing to compact: information_loss exceeds recovery_capacity; " "retain verbatim or spill to external store. Deficits:\n " + "\n ".join(unrepayable) ) def compact_or_refuse( evicted: list[Turn], digest: CompactionDigest, manifest: IndexCoverageManifest, spill_store: dict[str, str], ) -> CompactionDigest: """ Attempt compaction; on refusal, spill uncovered turns verbatim to an external store and extend the digest with retrieval keys. """ try: assert_compaction_recoverable(evicted, digest, manifest) return digest except UnrecoverableCompactionError: # Spill the uncovered turns verbatim; digest now points at the spill store. spill_keys: set[str] = set() for turn in evicted: if turn.turn_id not in manifest.indexed_turn_ids: key = f"spill:turn:{turn.turn_id}" spill_store[key] = turn.text spill_keys.add(key) # Rebuild digest with spill keys so downstream retrieval has a literal pointer. merged_verbatim = digest.verbatim_identifiers | frozenset(spill_keys) new_digest = CompactionDigest( verbatim_identifiers=merged_verbatim, referenced_turn_ids=digest.referenced_turn_ids, ) # Re-validate: spill keys are now verbatim identifiers, so coverage holds. assert_compaction_recoverable(evicted, new_digest, manifest) return new_digest ```