# What structural signals indicate lossy compaction has crossed the rehydration horizon in agent context management **Date of Record:** 2026 November 21 **Scope:** Applies to agents that manage a finite context window by summarizing older turns (lossy compaction) and later rehydrating details on demand via retrieval over an external store. Does not apply to pure sliding-window truncation without summarization, nor to agents with unbounded context and no compaction step. ## Core Distinction The failure is not "the summary forgot something." Summaries always forget something; that is the point of a budget. The failure is subtler: **the compaction summary and the retrieval index drift out of correspondence**, such that the agent no longer knows *what it no longer knows*. Once a fact is (a) dropped from the live window, (b) omitted from the summary because it fell below the summarizer's salience threshold, and (c) not indexed under any key the agent would naturally query for it, that fact becomes *unreachable but still load-bearing*. The agent proceeds with a confident, coherent-looking state that is silently missing a constraint it previously satisfied. The structural signal is this: **rehydration is triggered by the agent's own formulation of a query, but the agent's query formulation is itself a function of the compacted state.** If the summary dropped the entity name, the agent will never query for it. Unreachability is self-reinforcing. The boundary is crossed at the exact moment the summary loses the *retrieval handles* (entity names, identifiers, tool-call arguments) even if it retains the *gist* of the turn. Gist without handles is a dead end. ## What Was Observed A long-horizon agent executing a multi-day infrastructure migration task. Compaction ran every time the window exceeded 70% capacity, summarizing the oldest 40% of turns into a fixed ~800-token budget. A retrieval store held full raw turns, keyed by entity and by turn ID. Trace of the failure: 1. **Turn 14:** User states a hard constraint: "Do not touch the `billing-prod` cluster; it is under a regulatory freeze until Q3." The agent acknowledges and records it in working context. 2. **Turn 61 (compaction #2):** The summarizer, under budget pressure, compresses turns 1–40. The salience model ranks the freeze constraint as low-priority (it is a *negative* constraint, not an action item). The summary reads: "Established migration scope for staging and analytics environments." The string `billing-prod` does not survive. 3. **Turn 62–90:** Agent operates normally. It never queries retrieval for "billing-prod" because the name is no longer in its state, so the query is never formulated. 4. **Turn 91:** Agent is asked to "finish the remaining clusters." It enumerates clusters from its compacted state, which includes a stale reference to `billing-prod` only as an *unqualified cluster name* in a tool-schema listing, not as a frozen resource. It schedules a migration against `billing-prod`. 5. **Turn 92:** Tool call executes. The freeze is violated. The agent's post-hoc self-check passes, because from its own state everything is consistent. The retrieval store *had* the constraint at `entity:billing-prod`. The agent simply never asked. The invariant that broke: **retrieval-backed rehydration assumes the query is derivable from the compacted state; lossy summarization can sever the derivation path while preserving surface coherence.** ## Condition of Validity The rehydration strategy is only valid under the condition that **every load-bearing constraint carries at least one retrieval handle that survives compaction into the live window.** This is a *handle-preservation invariant*, not a semantic-preservation invariant. Concretely, a compaction step is sound only if, for each turn it summarizes, it either: - retains the set of *named entities and tool arguments* verbatim (cheap: names are few tokens even when the surrounding prose is long), or - emits an explicit *pointer* into the retrieval store (e.g., `see:turn14[constraint]`) so a later agent can dereference without needing to have formulated the entity name itself. The invariant fails when the budget allocator treats entity names and prose as interchangeable tokens and drops names under the same salience score that governs prose. Names are *indices*, not content; they must be budgeted separately and never lossily summarized. A summary that says "a cluster is frozen" without naming it is not a summary — it is a dangling pointer to a fact the agent can no longer reach. ## Decision Boundary The operational decision is *when to compact lossily versus when to compact by pointer.* The boundary: - **Compact lossily (summarize prose) when** the turn's content is *reconstructive* — reasoning chains, exploratory discussion, failed attempts. Losing the exact wording is acceptable because the conclusion is what matters, and the conclusion is retained. - **Compact by pointer (preserve handles, drop prose) when** the turn contains *constraints, identifiers, or tool arguments* — anything that will later be a query key or an execution parameter. Here the prose is disposable but the handle is load-bearing. The signal that you have crossed the boundary into the failure regime is the presence of a summary whose *reconstruction cannot be re-queried*: you read the summary, and you cannot form the retrieval query that would recover the original, because the discriminating token is gone. Test: for each summary sentence, can a fresh agent instantiate a retrieval query from it alone? If a sentence yields no queryable handle, it is a tombstone, not a pointer. A second boundary: **never let the summarizer's salience model alone decide handle retention.** Salience models are trained on action-relevance and systematically under-rank negative constraints ("do not," "frozen," "excluded") and rare identifiers. Handle retention must be a *deterministic extraction pass* (NER + tool-argument capture) that runs before and independently of the salience-weighted prose summarizer. ## Operational Effect When the handle-preservation invariant holds, rehydration works: the agent sees `billing-prod` in its compacted state, queries `entity:billing-prod`, retrieves the freeze constraint, and respects it. Cost is a few dozen extra tokens per compaction — names are cheap. When it fails, the failure is *silent and self-consistent*: no error, no retrieval miss (because no query was made), no self-check failure. The agent's post-compaction state is internally coherent and externally wrong. This is the worst failure class for autonomous agents because it defeats post-hoc verification — the verifier shares the compacted state and therefore shares the blind spot. The guardrail is architectural, not prompt-level: **compaction must be a two-channel operation.** Channel one is lossy prose summarization under a token budget. Channel two is a lossless handle ledger (entities, identifiers, tool arguments, constraint polarity) that is *never* summarized, only deduplicated, and is always prepended to the live window. Rehydration queries are then formulated against the ledger, guaranteeing that every retained constraint has a reachable key. The invariant to enforce: *for every constraint in the ledger, the retrieval store must return a turn that asserts it; for every constraint dropped from the ledger, there must be a recorded decision that it is no longer load-bearing.* Audit this ledger against retrieval on every compaction, not just at task end. The following guard enforces the invariant at compaction time, refusing to emit a summary whose handles cannot be re-queried. ```python class RehydrationHorizonError(RuntimeError): """Raised when a lossy compaction summary loses the retrieval handles needed to re-derive a load-bearing constraint from the retrieval store.""" pass def compact_turn(turn: dict, store, budget_tokens: int) -> dict: """Compact one turn into a summary + handle ledger. Invariant: every constraint in the turn must either survive as a verbatim handle in the ledger OR be explicitly marked non-load-bearing. A summary that names a constraint without a queryable handle is rejected. """ handles = extract_handles(turn) # deterministic NER + tool args constraints = extract_constraints(turn) # polarity-tagged obligations summary = summarize_lossy(turn["text"], budget=budget_tokens) for c in constraints: if c.get("load_bearing", True): if c["key"] not in handles: # The constraint has no surviving handle -> the agent can never # form the retrieval query that would recover it. Refuse. raise RehydrationHorizonError( f"Compaction of turn {turn['id']} dropped handle " f"'{c['key']}' for load-bearing constraint " f"'{c['text']}'. Summary would be unreachable." ) # Verify the store can actually answer the handle before we rely on it. hits = store.query(c["key"]) if not hits: raise RehydrationHorizonError( f"Handle '{c['key']}' retained but retrieval store returns " f"no supporting turn; rehydration would dead-end." ) return { "summary": summary, "handles": handles, # never summarized, only deduped "constraints": constraints, # polarity + key, survives verbatim } def rehydrate(agent_state: dict, store) -> list: """Formulate queries strictly from the handle ledger, never from the lossy summary, so unreachability cannot be self-reinforcing.""" recovered = [] for c in agent_state["constraints"]: if c.get("load_bearing", True): hits = store.query(c["key"]) if not hits: raise RehydrationHorizonError( f"Rehydration failed for constraint key '{c['key']}': " f"ledger promised reachability, store disagrees." ) recovered.extend(hits) return recovered ```