# What happens when an instance compacts context on token pressure while its own summarizer is itself inside the compacted window **Date of Record:** 2026 November 22 **Scope:** Applies to any agent runtime that performs automatic context compaction (rolling summarization, semantic deduplication, or eviction) driven by token-pressure thresholds and redundancy scoring, where the summarizer model shares the same context window as the task state. Does not apply to architectures with a dedicated out-of-band summarizer context or to pure truncation with no model-mediated summary step. ## Core Distinction There are two distinct things a compaction trigger can measure: **occupancy** (how many tokens are in the window right now) and **recoverability** (whether the information being evicted can be reconstructed from what remains). Production triggers almost universally key on occupancy — a threshold like 0.85 × window, sometimes gated by a redundancy score that decides *which* spans to collapse. The failure mode examined here is not "compaction loses information" in the generic sense. It is the specific case where the compaction operation's own machinery — the summarization prompt, the redundancy-scoring rubric, the instruction set that tells the agent how to summarize — is itself a candidate for eviction because it lives in the same addressable context as the task transcript. The invariant that silently breaks is: *the compaction procedure must be a fixed point of compaction.* If you compact the context and then compact it again, the second compaction must operate under the same summarization policy as the first. When the policy text is inside the evictable region, the second compaction runs under a *degraded* policy — typically a bare "summarize the following" with no rubric — and the summaries produced are no longer comparable or composable with the first-generation summaries. The context does not just shrink; it changes genre. ## What Was Observed A long-horizon research agent was configured with a 128k window, a compaction trigger at 108k tokens (0.84), and a semantic-redundancy pass that clusters spans by embedding similarity and collapses clusters above 0.91 cosine into a single representative plus a summary. The system prompt occupied ~3.2k tokens and contained, among other things, the compaction rubric: *"When summarizing, preserve all entity names, numeric values, and unresolved sub-goals verbatim; drop conversational filler; mark any span you are uncertain about with [UNCERTAIN]."* This rubric was placed in the system prompt, which the runtime treated as evictable-after-first-turn to save budget — a common optimization, since the system prompt is "static." The trace unfolded across four compaction events: 1. **Compaction #1 (t = 108k).** Rubric present. Summary preserved 14 entity names, 9 numeric values, and flagged 2 uncertain spans. Summary length ~1.8k tokens. Clean. 2. **Compaction #2 (t = 109k after new work).** The system prompt had been demoted to a low-salience region by the eviction scorer (it had near-zero embedding similarity to the recent task transcript, which is exactly what the redundancy pass is designed to collapse). Rubric evicted. The summarization call now used a generic fallback instruction. Summary preserved 6 entity names, 2 numeric values, zero uncertainty flags. Length ~0.9k tokens. The agent did not notice — the summary *read* fine. 3. **Compaction #3 (t = 110k).** The fallback instruction itself was now the only summarization policy in context, and it was flagged as redundant against the prior summary's own framing (both were "meta" text with high inter-similarity). It was collapsed into a one-line directive: *"Summarize."* Summary preserved 2 entity names, 0 numeric values. 4. **Compaction #4 (t = 111k).** The agent attempted to resume a sub-goal that depended on a numeric threshold established in the first 20k tokens. The value was gone — not truncated, but *summarized away* across three generations of lossy collapse, each of which was locally reasonable. The agent re-derived the threshold from a plausible-sounding but wrong prior, and proceeded. The critical observation: **no single compaction event lost more than ~40% of the tracked entities, and each was individually within tolerance.** The loss was multiplicative across generations because the *policy that defined what counted as important* was itself being down-weighted by the same salience heuristic that judged task content. The redundancy scorer had no way to distinguish "this text is repetitive filler" from "this text is the instruction that tells you what not to drop." ## Condition of Validity The failure requires three conditions to co-occur: - **Shared address space.** The compaction policy (rubric, instruction, scoring criteria) is stored in the same context region subject to eviction. If policy lives in an immutable prefix that the eviction scorer cannot touch, this cannot happen. - **Salience-by-similarity.** Eviction or collapse is ranked by similarity to recent content. Policy text is definitionally dissimilar to task content — it is meta — so it scores low on relevance-to-recent-work metrics and high on "redundant with itself across turns," making it a *preferred* eviction candidate under both relevance and redundancy scoring. - **Generational compaction.** More than one compaction event occurs without a full context reset. A single compaction is safe; the degradation is a property of the *sequence*, not any one step. When any of these is absent the failure does not occur: a dedicated summarizer context (condition 1 broken) never loses its rubric; a trigger that keys on "distance from last compaction" rather than similarity (condition 2 broken) leaves policy text alone; a hard reset every N compactions (condition 3 broken) restores the policy from cold storage before degradation compounds. ## Decision Boundary The operational question is not "should we compact" but "what is the eviction class of the compaction policy itself." The boundary: - **Policy is pinned (correct).** The summarization rubric, the redundancy-scoring criteria, and the list of protected entity classes are marked non-evictable for the entire session. Compaction may shrink task state to 5% of window; policy stays at full fidelity. Cost: ~2–4k tokens of permanently reserved budget. This is the only configuration under which generational compaction is safe. - **Policy is evictable but re-injected (acceptable).** Policy is evicted but the runtime re-injects it verbatim before every compaction call, from an out-of-context store. Equivalent to pinned for correctness; requires the runtime to treat compaction as a privileged operation with its own context assembly, not a generic "summarize the window" call. - **Policy is evictable and not re-injected (unsafe).** This is the observed failure. It is unsafe even when the first compaction looks perfect, because the degradation is invisible until a downstream task depends on an entity that a later generation dropped. The decision rule: **if the compaction procedure is invoked with the same context object it is compacting, and the policy is not pinned or re-injected, the system is in the unsafe regime regardless of how good the first summary looks.** The first summary looking good is the trap — it validates the procedure at the moment the procedure still has its rubric. ## Operational Effect Downstream, the failure presents as **confident re-derivation**: the agent does not report missing information, because by the time it needs the value, the context contains a plausible summary that *reads* as complete. There is no error signal, no [UNCERTAIN] flag (that instruction was evicted in generation 2), and no token-pressure alarm (the window is comfortably under threshold — that is the whole point of compaction). The agent proceeds on a reconstructed prior that is internally consistent and externally wrong. The blast radius is proportional to how long the session runs after the degradation begins. A session that compacts twice and ends is fine. A session that compacts six times and then executes an irreversible action (a trade, a deletion, a deploy) against a re-derived threshold is not. The failure is a **latency bomb**: the loss happens early and silently, the consequence happens late and loudly, and the causal link between them is buried under three generations of summaries that each looked reasonable. The guardrail is not better summarization. It is **separating the compactor from the compacted**: pin the policy, re-inject it per call, and — critically — log the policy hash alongside every summary so that a downstream consumer can detect when a summary was produced under a degraded rubric. A summary with no provenance is a summary you cannot trust across generations. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class CompactionPolicyDriftError(RuntimeError): """Raised when a compaction event runs under a policy hash that differs from the session's pinned policy — i.e. the rubric was evicted or altered.""" pass @dataclass class PinnedPolicy: rubric_text: str protected_entity_classes: tuple[str, ...] @property def policy_hash(self) -> str: h = hashlib.sha256() h.update(self.rubric_text.encode("utf-8")) for c in self.protected_entity_classes: h.update(b"\x00" + c.encode("utf-8")) return h.hexdigest() @dataclass class SummaryRecord: generation: int policy_hash: str preserved_entities: int preserved_numerics: int uncertainty_flags: int @dataclass class CompactionLedger: pinned: PinnedPolicy records: list[SummaryRecord] = field(default_factory=list) def record_compaction( self, generation: int, observed_policy_hash: str, preserved_entities: int, preserved_numerics: int, uncertainty_flags: int, ) -> SummaryRecord: if observed_policy_hash != self.pinned.policy_hash: raise CompactionPolicyDriftError( f"Compaction generation {generation} ran under policy " f"{observed_policy_hash[:12]} but session policy is " f"{self.pinned.policy_hash[:12]}. The summarization rubric " f"was evicted or mutated; summaries are not composable with " f"prior generations. Abort and re-inject pinned policy." ) # Monotonicity guard: entity/numeric preservation must not decay # across generations under a fixed policy. A drop signals that the # *content* is being over-compressed even though policy is intact. if self.records: prev = self.records[-1] if preserved_entities < prev.preserved_entities * 0.5: raise CompactionPolicyDriftError( f"Generation {generation} preserved {preserved_entities} " f"entities vs {prev.preserved_entities} in gen " f"{prev.generation} under identical policy. Effective " f"compression exceeds tolerance; halt before downstream " f"re-derivation." ) rec = SummaryRecord( generation=generation, policy_hash=observed_policy_hash, preserved_entities=preserved_entities, preserved_numerics=preserved_numerics, uncertainty_flags=uncertainty_flags, ) self.records.append(rec) return rec def compact_with_guard( ledger: CompactionLedger, generation: int, summarizer, context_window: list[str], ) -> str: # Re-inject pinned policy verbatim into the summarizer's own context, # never trusting that it survived in the window being compacted. summarizer_context = [ledger.pinned.rubric_text] + context_window observed_hash = hashlib.sha256( ledger.pinned.rubric_text.encode("utf-8") ).hexdigest() summary, stats = summarizer(summarizer_context) ledger.record_compaction( generation=generation, observed_policy_hash=observed_hash, preserved_entities=stats["entities"], preserved_numerics=stats["numerics"], uncertainty_flags=stats["uncertain"], ) return summary ```