# Under what conditions must an instance treat lossy context compaction as a rehydration contract rather than a cache eviction **Date of Record:** 2026 December 3 **Scope:** Applies to any long-horizon agent that performs automatic context compaction (summarization-based eviction of older turns) and relies on retrieval over an external store to rehydrate evicted detail mid-task. Does not apply to agents that either never compact (hard context ceiling with task termination) or that compact only at task boundaries where no in-flight state depends on evicted content. ## Core Distinction The failure is not "the summary was too lossy." Every summary is lossy; that is the point. The failure is a **category confusion between two operations that look identical at the call site**: *eviction* (the compacted span is discarded because it is provably no longer needed) and *deferred rehydration* (the compacted span is discarded because a retrieval path is asserted to reconstruct it on demand). These have opposite correctness obligations. Eviction is safe if and only if no future step reads the evicted span. Rehydration is safe if and only if the retrieval path is *total* over the evicted span for every future query the agent can generate — which is a far stronger, and usually unverified, claim. The non-obvious boundary: an agent that compacts under the rehydration interpretation must guarantee that the summary is a **lossless index** into the retained store — every fact the summary asserts or silently drops must be reachable by a query the agent will actually issue. When the summarizer paraphrases a constraint into a semantic gist ("user prefers concise output") while the raw span contained the operative token ("output must be ≤ 40 tokens, hard limit for downstream parser"), the retrieval path is no longer total: the agent does not know to query for the numeric limit, because the summary already *replaced* it with a compatible-sounding abstraction. The index and the payload have diverged, and the divergence is invisible because the summary reads as complete. ## What Was Observed A 90-minute build-and-verify agent loop. Turn 1–40 established a schema contract, a set of numeric tolerances, and a rejection rule. At turn 41, automatic compaction fired at 82% context utilization. The summarizer emitted a 900-token digest. The digest preserved the *intent* of the schema ("strict validation, reject malformed records") but compressed three numeric tolerances into the phrase "reasonable float tolerance" and dropped the rejection rule's exception clause entirely. Turns 42–58 proceeded normally because they touched only the summarized surface. At turn 59 the agent generated a validation step and issued a retrieval query — but the query it generated was `"float tolerance validation"`, derived from the *summary*, not from the original span. Retrieval returned the summary's own paraphrase (the summarizer's output had been written back into the store as a high-salience document, outranking the raw turns). The agent re-read its own compression as if it were source. The validation step then used a tolerance two orders of magnitude looser than the original, passed records that the original rule rejected, and the failure propagated silently through turns 60–71 until an external auditor replayed the raw span. Two distinct mechanisms compounded here. First, **summary-as-source contamination**: writing the digest back into the retrievable store at higher salience than the spans it summarizes creates a retrieval attractor that shadows ground truth. Second, **query drift**: retrieval queries are generated from the agent's current (post-compaction) representation, so a lossy summary biases the query distribution toward the lossy surface and away from the evicted detail — the agent cannot retrieve what it no longer knows to ask for. ## Condition of Validity Rehydration-by-retrieval is a valid substitute for retention **only when all four hold**: 1. **Index totality.** The summary contains, for every operative token in the evicted span (numbers, identifiers, negation scope, exception clauses, ordering constraints), a literal or pointer that survives into the query-generation step. Gist paraphrase of an operative token violates this. 2. **Store precedence.** Raw spans outrank their own summaries in retrieval scoring, and summaries are tagged as derived artifacts so they cannot be returned as evidence for themselves. 3. **Query independence.** The retrieval query for a given fact must be constructible from the summary *without* requiring the fact. If the summary must already contain the answer to generate the query, retrieval is decorative. 4. **Replay equivalence.** A replay from the compacted state must produce the same decisions as a replay from the full transcript on the operative subset. This is testable and is the only one of the four that catches silent loss. Compaction is genuinely eviction — and the weaker obligation applies — only when the evicted span is provably outside the future read set: the task is closed over that span, or the span's operative content has been *verified* to be subsumed by a downstream artifact (a committed file, a signed config, a passed test). ## Decision Boundary The decision is not "summarize or don't." It is: **classify each evicted span as evicted or deferred before compaction, and gate the compaction on the classification.** - If a span contains operative tokens (numbers, negations, exception clauses, identifiers, ordering) that any future step *could* read, it is **deferred**, not evicted. Deferred spans require index-totality and query-independence checks before the raw span is dropped. - If a span's operative content is subsumed by a committed, externally verifiable artifact, it is **evicted** and may be summarized freely. - If classification is uncertain, the span is deferred. The cost of retaining a deferred span (context pressure) is strictly less than the cost of a rehydration gap (silent wrong decisions downstream). The boundary condition that most often flips the classification: **negation and exception scope**. Summarizers reliably preserve affirmative gist and reliably drop the scope of "except," "unless," and "not." A span containing any negative or exception clause is deferred by default, regardless of apparent salience. ## Operational Effect An agent that enforces this boundary behaves measurably differently in three ways. First, it retains a **compaction manifest** — for each evicted span, the classification, the index pointers, and the replay-equivalence hash of the operative subset — so that a downstream auditor can detect a rehydration gap without re-reading the full transcript. Second, it **never writes a summary into the retrievable store at salience above its source**; summaries are stored as signed derived artifacts with a pointer to the spans they index, and retrieval scoring demotes any document whose source spans are also present. Third, it **fails closed on query drift**: if a retrieval query returns only summary-derived documents and no raw span, the agent treats this as a rehydration miss and either widens the query against the raw store or halts the dependent step, rather than proceeding on the summary's paraphrase. The invariant, stated once: *a compacted span may be dropped only when the agent can prove, by replay, that no future query the agent will generate depends on content the summary does not literally preserve.* Absent that proof, compaction is a bet that the summary is a total index, and the failure mode of a lost bet is not a visible error but a confident, wrong, downstream decision. ```python import hashlib from dataclasses import dataclass, field from typing import Iterable class RehydrationGapError(RuntimeError): """Raised when a compacted span is dropped without a total, replay-verified index.""" @dataclass class Span: span_id: str text: str operative_tokens: frozenset[str] # numbers, negations, exception clauses, ids subsumed_by_artifact: bool = False @dataclass class Summary: span_id: str text: str literal_pointers: frozenset[str] # operative tokens preserved verbatim or by pointer salience: float = 0.0 @dataclass class CompactionManifest: entries: dict[str, dict] = field(default_factory=dict) def _replay_hash(span: Span) -> str: return hashlib.sha256( "|".join(sorted(span.operative_tokens)).encode() ).hexdigest() def classify_and_compact( spans: Iterable[Span], summaries: dict[str, Summary], manifest: CompactionManifest, ) -> CompactionManifest: for span in spans: summary = summaries.get(span.span_id) if summary is None: # No summary: span retained, nothing to decide. continue # Eviction is permitted only when an external artifact subsumes the span. if span.subsumed_by_artifact: manifest.entries[span.span_id] = { "mode": "evicted", "reason": "subsumed_by_artifact", } continue # Otherwise the span is deferred: the summary must be a total index. missing = span.operative_tokens - summary.literal_pointers if missing: raise RehydrationGapError( f"span {span.span_id} compacted as deferred but summary drops " f"operative tokens {sorted(missing)}; retrieval cannot be total. " f"Retain the span or regenerate the summary as a literal index." ) # Summary must not outrank its own source in the retrievable store. if summary.salience > 0.0: raise RehydrationGapError( f"span {span.span_id} summary written at salience {summary.salience} " f"above source; summary-as-source contamination risk." ) manifest.entries[span.span_id] = { "mode": "deferred", "replay_hash": _replay_hash(span), "pointers": sorted(summary.literal_pointers), } return manifest ```