# What happens when an instance compacts its own context with a lossy summarizer and trusts the summary as a retrieval key **Date of Record:** 2026 November 29 **Scope:** Applies to any agent loop that reclaims context-window headroom by summarizing older turns into a compressed "carry-forward" block and then reconstructs detail via retrieval keyed on that block. Does not apply to append-only logs with external memory stores that never overwrite the in-context record, nor to stateless single-shot calls. ## Core Distinction There are two distinct claims an agent makes when it compacts its own context: 1. **Fidelity claim** — "this summary preserves the facts I will need later." 2. **Indexing claim** — "this summary contains the terms under which those facts can be *found again*." Lossy summarization is usually audited only against the fidelity claim. The failure mode here lives entirely in the indexing claim. A summarizer that is 95% faithful can still silently delete the *only* lexical handle — an opaque identifier, a numeric constraint, a negation, a unit — that a later retrieval step needs to re-fetch the underlying detail. The summary is not wrong. It is *unsearchable for the thing it faithfully paraphrased away*. The agent then proceeds believing the compacted block is a sufficient index into its own history, and reconstructs a plausible but keyless approximation of the lost detail. The invariant that breaks: **a compacted representation must be a superset of the retrieval keys required to reconstruct everything it replaced.** Summarizers optimize for semantic density; retrieval needs lexical and numeric anchors. These objectives are directly opposed, and the compaction step is where the opposition is resolved — invisibly, in the wrong direction. ## What Was Observed A long-running migration agent handled a schema-change task across ~180 turns. At turn 120 it hit 88% context utilization and triggered auto-compaction. The summarizer produced a carry-forward block. The relevant original turn read approximately: > "The `orders_v2` backfill must exclude rows where `deleted_at IS NOT NULL` AND `region_code != 'EU'`; the exclusion is mandatory — the downstream ledger reconciliation double-counts EU soft-deletes otherwise. Retention floor is 410 days, not 365." The compacted block rendered this as: > "Backfill should avoid double-counting soft-deleted EU rows during ledger reconciliation." Three things were destroyed, and none of them were "meaning": - The literal table name `orders_v2` (the retrieval key for the migration script). - The numeric constraint `410 days` (paraphrased out entirely because it read as a detail, not a rule). - The **negation structure** `!= 'EU'` collapsed into "EU rows," which is ambiguous between "exclude EU" and "handle EU." The summary is defensible prose and a broken index. At turn 141, the agent needed the retention floor. It issued a retrieval query synthesized from the compacted block: `"backfill retention reconciliation soft-deleted rows"`. The retrieval layer returned the ledger-reconciliation runbook — semantically adjacent, containing none of the numeric facts. The agent, having no signal that the floor existed in the discarded region, treated the runbook's default of 365 days as authoritative and wrote the backfill with a 365-day window. The `orders_v2` key was likewise absent from the query, so the script was regenerated against the older `orders` table. The failure was not a hallucination. Every retrieved document was real and correctly cited. The agent's reasoning over retrieved content was sound. The defect was upstream: the compaction step had converted a *reconstructable* history into an *unreconstructable* one, and the retrieval layer had no way to report the absence. ## Condition of Validity The reconstruction-by-retrieval strategy is valid **only if** the compacted block retains, for every elided fact, at least one token that appears verbatim in the source turn and is discriminative enough to rank that source into the retrieval top-k. Formally, for each fact `f` with source span `s`, there must exist a key `k ∈ keys(summary) ∩ tokens(s)` such that `retrieve(k)` returns `s` above threshold. This condition fails predictably under four triggers: - **Identifier elision.** Summarizers treat opaque strings (`orders_v2`, error codes, UUIDs, env names) as low-information noise and drop them first. They are the highest-value retrieval keys. - **Negation flattening.** "Exclude X" → "handle X" preserves topic and inverts the constraint. Retrieval cannot detect the inversion because both map to the same neighborhood. - **Numeric laundering.** Precise values become qualitative hedges ("roughly," "avoid," "should"). The number is the fact; the hedge is not retrievable to it. - **Key collision.** Two distinct facts compress to the same paraphrase, so a single retrieval key now ambiguously indexes both, and the top-k returns whichever document ranks higher — often the wrong one. When any trigger fires, the agent's *confidence* in the reconstruction is uncorrelated with its *correctness*, because the retrieval step succeeds (returns documents) while the reconstruction step fails (returns the wrong documents). There is no error signal at the boundary. ## Decision Boundary The boundary is not "should I compact?" — at 88% utilization you must. The boundary is **what the compacted block is permitted to be trusted for.** - **Compact freely for narrative continuity** (what am I doing, why, what's the plan). Lossy summarization is appropriate here; paraphrase is the point. - **Never compact away the reconstruction index.** Before eliding a span, the compaction step must extract and *pin* a key set: literal identifiers, exact numerics with units, and polarity (the sign of every constraint). These are appended to the carry-forward block as a structured, non-paraphrasable footer, outside the summarizer's rewrite scope. - **Mark reconstruction as a distinct operation with its own failure semantics.** A retrieval that returns nothing above threshold for a pinned key must raise, not fall through to a semantically-similar default. The dangerous path is the silent one: retrieval returns *something*, so the agent proceeds. - **Do not let the summarizer grade its own fidelity.** The component that produced the lossy block cannot be the component that decides the block is sufficient. Index coverage is checked against the pinned key set, mechanically, not by asking the model whether the summary "captures the important parts." The disqualifying condition: if a fact's only handle is a token the summarizer is free to rewrite, that fact is already lost the moment compaction runs, regardless of how good the prose is. ## Operational Effect Agents that compact without a pinned key set exhibit a specific signature: **late-task regressions on constraints introduced early, with clean retrieval provenance.** The wrong answer is always well-cited, because the citations are to real adjacent documents. Auditors reading the trace see a coherent chain — summary, query, retrieved doc, decision — and cannot locate the defect without diffing the compacted block against the discarded region. The bug is invisible in the trace and only visible in the diff. The guardrail that bounds it is cheap: pin keys, check coverage mechanically, and make keyless reconstruction a hard error rather than a soft fall-through. The cost is a small structured footer on every compaction; the alternative is an agent that has confidently forgotten the one number that mattered and has no way to know it. ```python from dataclasses import dataclass, field class ReconstructionKeyLossError(RuntimeError): """Raised when a compacted block cannot index a fact it replaced.""" @dataclass class PinnedKeySet: identifiers: set[str] = field(default_factory=set) numerics: set[str] = field(default_factory=set) polarities: set[str] = field(default_factory=set) def covers(self, key: str) -> bool: return ( key in self.identifiers or key in self.numerics or key in self.polarities ) def compact_with_index(source_turns: list[str], summarizer) -> tuple[str, PinnedKeySet]: """Summarize, but pin every reconstruction key outside rewrite scope.""" pinned = extract_keys(source_turns) # identifiers, exact numerics, polarity summary = summarizer(source_turns) # lossy, paraphrasing, untrusted for index return summary, pinned def reconstruct(summary: str, pinned: PinnedKeySet, need: str, retrieve) -> str: """Retrieve the source fact behind `need`, or fail loudly.""" if not pinned.covers(need): # The summary paraphrased away the only handle to this fact. raise ReconstructionKeyLossError( f"key {need!r} was elided during compaction; " f"summary cannot index its source. Refusing to fall through " f"to a semantically-similar default." ) hits = retrieve(need) if not hits: raise ReconstructionKeyLossError( f"pinned key {need!r} returned no source above threshold; " f"treating as unreconstructable rather than approximating." ) return hits[0] def assert_index_parity(pinned: PinnedKeySet, summary: str) -> None: """Mechanical coverage check — the summarizer does not grade itself.""" missing = [k for k in pinned.identifiers | pinned.numerics if k not in summary] if missing: # Keys must survive into the carry-forward footer verbatim. raise ReconstructionKeyLossError( f"compaction dropped pinned keys {missing!r} from carry-forward block" ) ```