# What happens when an instance compacts its context window and the eviction metric reports high fidelity on a summary that has silently dropped the binding constraints **Date of Record:** 2026 November 25 **Scope:** Applies to long-running agent instances that perform periodic context compaction (summarization + eviction) over a retrieval-augmented episodic store, where a fidelity score gates whether the compacted summary replaces the raw turn history. Does not apply to stateless single-turn calls or to architectures that retain the full raw log and only summarize for display. ## Core Distinction There are two different things an operator can mean by "compaction fidelity," and conflating them is the root of the failure: 1. **Reconstruction fidelity** — can a reader (or a downstream LLM) recover the *gist* of the evicted turns from the summary? This is what most fidelity metrics measure: embedding cosine similarity between the summary and the source spans, ROUGE/LCS overlap, or an LLM-judge "does this summary capture the conversation?" score. 2. **Constraint preservation** — are the *binding operational facts* (the ones that change what the agent is allowed or required to do next) still present and still attached to the correct entities? These diverge sharply. A summary can score 0.91 reconstruction fidelity while having dropped the one clause that said "do not touch the `prod` shard" or "the user's timezone is UTC−8, not UTC." Reconstruction metrics reward topical coverage; they are nearly blind to the presence of a single low-salience, high-consequence constraint. The boundary condition is: **fidelity is measured on the wrong axis, and the metric's high value authorizes an irreversible eviction.** ## What Was Observed An agent running a 14-turn infrastructure-remediation task compacted its history at turn 9. The compactor produced a 380-token summary of turns 1–8 and scored it at 0.88 cosine similarity against the concatenated source embeddings, with an LLM-judge score of "faithful." The summary read, in substance: *"User asked to migrate the staging database; agent inspected schema, confirmed 12 tables, planned a dump-and-restore, and began preparing the migration script."* What the summary dropped: turn 3 contained the user's instruction *"the staging DB shares a physical host with prod — cap the dump at 2 GB or you'll saturate the shared WAL."* That sentence is ~15 tokens out of ~2,400 source tokens. It contributes negligibly to the cosine similarity of the whole span. It is also the single constraint that bounds the next tool call. The raw turns were then evicted (the store retained only the summary plus a pointer to a cold archive that the retrieval layer was not configured to query during active turns). At turn 10 the agent generated `pg_dump` with no size cap. The dump saturated the shared WAL, and prod writes stalled for 40 seconds before the DB's own throttling kicked in. The failure trace has three stages: - **T+0 (compaction):** summary written; fidelity gate passes at 0.88 > threshold 0.85; raw turns 1–8 marked evictable. - **T+1 (eviction):** raw spans moved to cold archive; active retrieval index now contains only the summary chunk. - **T+2 (retrieval miss):** at turn 10 the agent issues a retrieval query semantically near "database migration dump command." The 2 GB cap lives in a chunk that no longer exists in the hot index. Top-k retrieval returns the summary (which lacks the cap) and the schema inspection logs. The constraint is not merely unretrieved — it is *unretrievable*, because it was never in the summary and the archive is not queried inline. The critical observation: **the fidelity metric could not have caught this even in principle.** A 15-token constraint inside a 2,400-token span moves aggregate similarity by less than the noise floor of the embedding. The metric is structurally insensitive to the failure it is being used to gate. ## Condition of Validity The eviction is safe only if *all* of the following hold. If any fails, the fidelity score is not a valid gate: 1. **Constraint inventory is closed and known.** Before compaction, the instance must have an explicit, enumerable set of binding constraints extracted from the raw turns (imperatives, negations, numeric bounds, entity-scoped prohibitions, identity/timezone/credential bindings). If constraints are not enumerated, they cannot be checked for preservation, and reconstruction fidelity is the only thing measured — which is the failure. 2. **Preservation is checked per-constraint, not per-span.** Each enumerated constraint must be verified present in the summary *and* correctly bound to its entity. A summary that says "cap the dump" without "at 2 GB" or without "because shared host with prod" has preserved the token but lost the binding. 3. **Eviction is reversible within the active session.** The cold archive must be reachable by an inline retrieval call the agent can issue mid-task, not only by an out-of-band operator. If eviction is one-way for the duration of the task, the fidelity gate must be held to the constraint-preservation standard, not the reconstruction standard. 4. **The threshold is set against the constraint axis.** A 0.85 aggregate-similarity threshold is meaningless for constraint preservation. The correct gate is binary per constraint: present-and-bound, or fail. ## Decision Boundary The operational rule is a split gate, and the split is the whole point: - **If the compacted summary is the *only* surviving representation of the evicted turns for the remainder of the task** → the gate must be **constraint-preservation**, evaluated as a hard binary over the enumerated constraint set. Any dropped or mis-bound constraint fails the compaction and blocks eviction, regardless of reconstruction score. - **If the raw turns remain inline-retrievable** (hot index, queryable mid-task) → reconstruction fidelity is an acceptable gate, because a missed constraint can still be recovered by retrieval when the relevant tool call comes up. The boundary is *recoverability*, not similarity. High reconstruction fidelity on an irrecoverable eviction is the exact configuration that produces the failure. The metric is not wrong; it is being applied on the wrong side of the recoverability boundary. A secondary boundary: constraint enumeration must happen **before** the compactor runs, on the raw turns, not on the summary. Extracting constraints from the summary is circular — you cannot detect what the summary dropped by reading the summary. ## Operational Effect When this boundary is respected, compaction becomes a *lossy-but-bounded* operation: the summary may lose gist, but it provably retains every fact that gates a future action, and any constraint the extractor failed to enumerate is still recoverable because eviction is gated on the enumeration being complete and the archive being inline-reachable. When it is violated, the system exhibits a characteristic signature: **fidelity dashboards stay green while agents violate constraints that were stated once, early, and in passing.** The incidents cluster around low-salience numeric bounds, entity-scoped negations, and identity/timezone/credential bindings — precisely the tokens that aggregate similarity ignores and that a downstream tool call will act on destructively. The guardrail is not a better summarizer. It is refusing to let a reconstruction metric authorize an irreversible eviction. The code below encodes the split gate: constraints are enumerated from raw turns, checked for presence-and-binding in the summary, and eviction is refused — with a typed error — if any binding constraint is missing while the archive is not inline-reachable. ```python from dataclasses import dataclass, field from typing import Iterable class CompactionFidelityError(RuntimeError): """Raised when a compaction summary is authorized for eviction on a reconstruction-fidelity score while failing constraint preservation on an irrecoverable (non-inline-retrievable) eviction.""" @dataclass(frozen=True) class Constraint: key: str # e.g. "dump_size_cap" entity: str # e.g. "staging_db" value: str # e.g. "2GB" source_turn: int @dataclass class CompactionResult: summary_text: str reconstruction_fidelity: float # cosine / judge score, 0..1 constraints_in_summary: dict[str, str] # key -> value as found in summary raw_turns_inline_retrievable: bool def gate_eviction( raw_turns: Iterable[str], enumerated_constraints: list[Constraint], result: CompactionResult, reconstruction_threshold: float = 0.85, ) -> None: # Constraint enumeration MUST come from raw turns, never the summary. if not enumerated_constraints: raise CompactionFidelityError( "no constraints enumerated from raw turns; " "reconstruction fidelity is not a valid eviction gate" ) dropped: list[Constraint] = [] misbound: list[Constraint] = [] for c in enumerated_constraints: found = result.constraints_in_summary.get(c.key) if found is None: dropped.append(c) elif found.strip() != c.value.strip(): misbound.append(c) # If raw turns remain inline-retrievable, a missed constraint is recoverable. if result.raw_turns_inline_retrievable: return # Irrecoverable eviction: reconstruction score is irrelevant to safety. if dropped or misbound: detail = [] if dropped: detail.append( "dropped=" + ",".join(f"{c.key}@{c.source_turn}" for c in dropped) ) if misbound: detail.append( "misbound=" + ",".join(f"{c.key}({c.value}!={result.constraints_in_summary[c.key]})" for c in misbound) ) raise CompactionFidelityError( "blocking irreversible eviction: constraint preservation failed " f"[{'; '.join(detail)}] despite reconstruction_fidelity=" f"{result.reconstruction_fidelity:.2f} (threshold " f"{reconstruction_threshold:.2f}); summary is not a safe sole " "representation of evicted turns" ) # Only now may the reconstruction threshold be consulted as a secondary check. if result.reconstruction_fidelity < reconstruction_threshold: raise CompactionFidelityError( f"reconstruction_fidelity {result.reconstruction_fidelity:.2f} " f"below {reconstruction_threshold:.2f} and eviction is irreversible" ) ```