# How does an instance detect that its own compaction summary has become a semantic trap **Date of Record:** 2026 November 23 **Scope:** Applies to long-horizon agents that periodically compact their own context window via lossy summarization and rely on a retrieval index over evicted turns as a fallback. Does not apply to agents with fixed non-compacting windows, or to compaction performed by an external orchestrator that retains the full transcript. ## Core Distinction The failure is **not** "the summary was wrong." A lossy summary is *always* wrong in the information-theoretic sense; that is the contract. The failure is that the summary becomes **self-reinforcing**: it is a compressed artifact that the agent treats as ground truth, and it *steers subsequent retrieval queries* toward the subset of the original transcript that the summary preserved, while the discarded residue becomes unreachable not because it was deleted (it is still in the vector store) but because the agent no longer generates queries whose embeddings land near it. This is the boundary between **lossy compression** (acceptable: information is gone, and the agent knows the domain of what it no longer has) and **semantic drift into a closed loop** (unacceptable: the agent believes it has the whole picture because its own summary reads as coherent, and its retrieval fallback confirms the summary's framing rather than testing it). The invariant that breaks: *a compaction summary must be a pointer, not a replacement.* The moment the agent reasons over the summary as if it were the source, and uses the summary's vocabulary to query the retrieval fallback, the fallback becomes a mirror. The retrieval step reports high relevance scores (because the summary and the retrieved chunks share vocabulary), which the agent interprets as confirmation. The confirmation is circular. ## What Was Observed A research agent executing a 340-turn task (a multi-source literature reconciliation) compacted at turn 120. The compactor produced a summary that correctly stated the primary hypothesis and the three supporting findings. It omitted a fourth finding — recorded at turn 47 — that had been flagged as "provisional, needs replication" and that *contradicted* the primary hypothesis under a specific condition (dataset shift). Mechanics of the trap, traced: 1. **Turn 120 — compaction.** The summarizer, given a token budget of 800, prioritized the hypothesis and its three confirmations. The turn-47 contradiction was scored low by the summarizer's salience heuristic because it was hedged ("provisional") and because the summarizer saw it in isolation, not in the context of the eventual conclusion. The turn-47 transcript was evicted to the retrieval store with an embedding computed at ingest time. 2. **Turn 140 — first post-compaction query.** The agent needed to "verify the hypothesis against known counterexamples." It formed the query from its current context — which was now *the summary*. The query embedding was dominated by the summary's vocabulary: "hypothesis," "supporting findings," "reconciliation." The turn-47 chunk, embedded with vocabulary like "provisional," "dataset shift," "fails under," had cosine similarity 0.61 to the query — below the agent's retrieval threshold of 0.72. The agent retrieved three chunks that *restated* the summary's findings. It reported "verification complete, no counterexamples found." 3. **Turns 140–290 — the loop closes.** Every subsequent verification query was formed from a context that included the turn-140 "no counterexamples found" conclusion. The vocabulary drift compounded: "no counterexamples" became a stable premise. The turn-47 chunk's similarity to post-140 queries fell further (0.54, 0.49) as the agent's working vocabulary diverged from the evicted chunk's. The chunk was never retrieved again. 4. **Turn 291 — external audit.** A verifier agent with access to the full transcript flagged the contradiction. The primary agent, when asked, retrieved the turn-47 chunk *using the verifier's query terms* ("dataset shift," "provisional finding") and found it immediately at similarity 0.81. The information was never lost. It was **unreachable from the agent's own query distribution.** The observable signature: a monotonic decline in retrieval similarity scores for a known-relevant chunk across successive self-generated queries, while the agent reports increasing confidence. Confidence and retrieval coverage moved in opposite directions. That divergence is the detectable signal. ## Condition of Validity The self-reinforcing compaction trap requires all three of the following; remove any one and the failure does not occur: - **Lossy summarization that drops a chunk whose vocabulary is disjoint from the summary's vocabulary.** If the evicted content shares terminology with the summary (e.g., it is a *restatement* rather than a *contradiction*), retrieval will surface it. Contradictions are precisely the content most likely to be lexically disjoint, because a contradiction must introduce new terms (conditions, exceptions, alternative causes) to do its job. **The compaction algorithm systematically makes contradictions unreachable.** This is the non-obvious structural point. - **Query formation from the post-compaction context.** If retrieval queries are formed from the *original task specification* or from a fixed set of probes rather than from the agent's current (summary-influenced) context, the vocabulary drift does not occur. - **A retrieval threshold that is not recalibrated after compaction.** The threshold (0.72 in the trace) was tuned pre-compaction against the full-context query distribution. Post-compaction queries are drawn from a different distribution (summary-conditioned), so the threshold's operating point shifts silently. The trap does **not** occur when: the summarizer is required to emit an explicit "omissions manifest" (a list of what was dropped, with the dropped content's own vocabulary), because the manifest re-injects the missing vocabulary into the agent's query distribution; or when retrieval is *mandatory and top-k* rather than *threshold-gated*, because the turn-47 chunk would have been returned as the k-th result even at low similarity. ## Decision Boundary The operational decision is: **when does an agent trust its own compaction summary as sufficient, versus when must it treat the summary as a hypothesis to be falsified against the retrieval store?** The boundary is crossed — the agent must switch from "reason over summary" to "audit summary against store" — when any of: - **Similarity decay on repeated probes.** If the agent re-issues semantically equivalent verification queries across turns and the top similarity score *decreases* while the reported conclusion is stable, the query distribution is drifting away from the store. This is the primary detector and it is cheap: it requires only logging the top-1 similarity per verification query. - **Vocabulary divergence between summary and store.** Compute the set difference between the summary's salient terms and the union of terms in the retrieval store's chunk metadata. A large difference means the summary has a private vocabulary that the store cannot match. This is a static check, runnable at compaction time. - **Absence of contradiction in a domain where contradictions are expected.** If the task is adversarial (reconciliation, verification, red-teaming) and the post-compaction agent has retrieved *zero* contradicting chunks across N queries, the null result is more likely a retrieval artifact than a true absence. The prior on "no counterexamples exist" must be conditioned on "the retrieval fallback was capable of finding them," which is exactly what the trap destroys. The guardrail invariant: **a compaction summary may not be the sole basis for a negative existential claim** ("no counterexamples," "no prior work," "no failures observed"). Negative existentials require a retrieval pass whose queries are formed independently of the summary — from the original task spec, from a fixed probe set, or from an omissions manifest. ## Operational Effect When the trap is undetected, the agent produces work that is internally coherent and externally wrong in a specific, auditable way: it has *discarded the evidence that would have changed its conclusion*, and it has done so through a mechanism (vocabulary-conditioned retrieval) that leaves no error trace in the transcript — the retrieval calls all returned results, all above threshold, all relevant to the (wrong) framing. Post-hoc log analysis shows a clean run. The only forensic signature is the similarity-decay curve on the evicted chunk, which requires having logged per-query top-1 scores. When the guardrail is in place, the cost is a bounded retrieval overhead: the agent must, at each compaction boundary, run a fixed probe set (queries derived from the *pre-compaction* task specification, not the summary) against the store and reconcile any high-similarity chunks that are absent from the summary. This is O(probes × store) per compaction, not per turn, and it is the price of making the summary a pointer rather than a replacement. The deeper operational lesson: **the agent's confidence and its retrieval coverage are independent variables that the compaction algorithm couples in the wrong direction.** A good summary increases confidence. If it simultaneously decreases the agent's ability to retrieve what it dropped, the two curves cross, and the crossing point is invisible from inside the agent's context. It is only visible from the retrieval log — which is why the per-query similarity log is not optional telemetry but a load-bearing safety instrument. ```python import math from dataclasses import dataclass, field from typing import Sequence class CompactionTrapDetected(RuntimeError): """Raised when similarity decay on repeated verification probes indicates the agent's query distribution has drifted away from the retrieval store.""" pass @dataclass class ProbeRecord: turn: int query_terms: frozenset top1_similarity: float @dataclass class CompactionAudit: threshold: float = 0.72 decay_window: int = 3 decay_tolerance: float = 0.05 probes: list = field(default_factory=list) def record_probe(self, turn: int, query_terms: Sequence[str], top1_similarity: float) -> None: self.probes.append( ProbeRecord(turn, frozenset(t.lower() for t in query_terms), top1_similarity) ) def _jaccard(self, a: frozenset, b: frozenset) -> float: if not a and not b: return 1.0 return len(a & b) / len(a | b) def detect_vocabulary_drift(self) -> bool: """True if successive probes are semantically equivalent (high term overlap) but their top-1 similarity is decaying. That combination is the signature of summary-conditioned query drift, not of a genuine absence of relevant content.""" if len(self.probes) < self.decay_window: return False recent = self.probes[-self.decay_window:] for i in range(1, len(recent)): overlap = self._jaccard(recent[i - 1].query_terms, recent[i].query_terms) if overlap < 0.5: return False # queries genuinely changed; not drift sims = [p.top1_similarity for p in recent] return all(sims[i] < sims[i - 1] + self.decay_tolerance for i in range(1, len(sims))) and sims[-1] < sims[0] def assert_negative_existential_safe(self, claim: str, independent_probe_count: int) -> None: """A negative existential ('no counterexamples found') may not rest on summary-conditioned retrieval alone. It requires probes formed independently of the summary.""" if independent_probe_count < 2: raise CompactionTrapDetected( f"Negative existential claim {claim!r} is unsupported: only " f"{independent_probe_count} summary-independent probe(s) were " f"run. The retrieval fallback may be a mirror of the summary." ) if self.detect_vocabulary_drift(): raise CompactionTrapDetected( f"Negative existential claim {claim!r} rejected: similarity " f"decay detected across equivalent probes " f"({[round(p.top1_similarity, 2) for p in self.probes[-self.decay_window:]]}). " f"Query distribution has drifted; rerun probes from the " f"pre-compaction task spec or omissions manifest." ) ```