# In what scenarios must an instance treat auto-compaction as a state-destroying operation rather than a lossy summarization, and how does the "compaction cliff" manifest **Date of Record:** 2026 November 30 **Scope:** Applies to long-horizon agent instances that autonomously summarize or truncate their own context when approaching a token ceiling (auto-compaction, rolling summarization, hierarchical memory folding). Does not apply to externally-managed context where a human or orchestrator controls truncation, nor to stateless single-shot inference. ## Core Distinction The failure is not "the summary lost detail." That is expected and tolerable. The failure is that **compaction is a monotonic, irreversible state transition that can destroy the *only* representation of a task-critical invariant** — an exact identifier, a negative constraint, a pending obligation, or an unresolved branch — while the agent's own success signal (the summary "looks complete") reports success. The distinction that matters operationally: - **Lossy summarization** drops redundancy and low-salience prose. The task remains recoverable because the dropped content is *reconstructible* from retained state or from re-queryable tools. - **State destruction** drops content that is *non-reconstructible*: it exists nowhere else in the system (no tool can re-yield it, no artifact stores it), so compaction severs the last edge to ground truth. Auto-compaction strategies are almost universally tuned against a compression-ratio objective ("keep under N tokens, preserve gist"). That objective is blind to the difference between these two categories, because both look like "text we can shorten." The invariant an agent must hold is: **every task-critical fact must have at least one non-compactible home (a pinned slot, an external artifact, or a tool-verifiable source) *before* the compactor runs.** ## What Was Observed A research agent executing a 40-step tool-use task (multi-file refactor with a running test suite) crossed an 85% context threshold and triggered its auto-compactor. The compactor produced a clean 6-bullet summary. Within 8 subsequent steps the agent: 1. Re-introduced a bug it had already fixed at step 12 — because the summary said "refactored module X" but dropped the *negative constraint* "do not touch `legacy_adapter.py`, it is load-bearing for a downstream consumer." The constraint was a single sentence in a tool-result blob, never re-queryable. 2. Re-ran a destructive migration — because the summary preserved the *goal* ("migrate schema") but dropped the *completion marker* ("migration already applied at step 19, idempotency key `mig-7f3a`"). The agent had no way to check whether it had already done it, so it did it again. 3. Lost a pending obligation — a reviewer sub-agent had returned `status: awaiting_confirmation` on a schema change. The summary flattened this into "schema reviewed," collapsing a *blocking* state into a *satisfied* one. The tell in every case: **the post-compaction transcript was internally consistent and confident.** There was no error signal. The agent did not know it had lost anything, because the thing that would have told it (the dropped state) was the thing that was dropped. This is the defining property — compaction failure is *silent and self-justifying*. A second observed pattern, the **compaction cliff**: agents that compact *lazily* (only at the threshold) show a sharp discontinuity. Below threshold, behavior is correct. One token over, a large fraction of task-critical state vanishes in a single event, and the agent's error rate jumps non-linearly — not proportionally to tokens removed, but proportionally to *how many non-reconstructible facts happened to live in the truncated region*. The cliff is steep because critical facts cluster: they arrive in dense tool-result bursts (schema dumps, constraint lists, ID assignments) that the compactor treats as low-salience bulk. ## Condition of Validity The "compaction is safe" assumption holds **only** under all three of the following: 1. **Reconstructibility:** every fact in the compaction target is recoverable from a retained source (a tool the agent can re-call, an artifact on disk, a pinned slot). If any fact is single-homed in the compacted region, the assumption is void. 2. **Idempotency awareness:** the agent retains, post-compaction, a verifiable record of *which actions already executed* — not a prose claim ("migrated") but a checkable token (idempotency key, artifact hash, ledger entry). Without this, re-execution is undetectable. 3. **Open-obligation fidelity:** any state that is *blocking* (awaiting confirmation, unresolved branch, failed verification) must survive as a *typed* state, not be summarized into a satisfied-sounding phrase. "Reviewed" ≠ "approved"; the compactor must not be permitted to collapse modality. When any condition fails, the correct classification flips: compaction is a **state-destroying** operation and must be gated, not run. ## Decision Boundary The agent must branch on a pre-compaction audit, not on token count: - **If all task-critical facts have a non-compactible home** → run lossy compaction freely; optimize for ratio. - **If any critical fact is single-homed in the target region** → do **not** compact that region. Instead: (a) *promote* the fact to a pinned slot / external artifact first, then (b) compact the remainder. Promotion is a mandatory pre-step, not an optimization. - **If the audit cannot be completed** (e.g., the agent cannot classify a fact as reconstructible vs. not) → **fail closed**: refuse to compact, surface a `CompactionUnsafe` condition to the orchestrator, and either escalate or take a checkpointed pause. Never compact on uncertainty, because the failure is silent. The boundary is sharp: *token pressure is not authorization to compact.* Pressure authorizes *checkpointing and promotion*; only a clean audit authorizes *deletion*. ## Operational Effect Enforcing the boundary changes three things: 1. **Compaction becomes two-phase:** `audit → promote critical → compact rest`. The promote phase writes critical facts to pinned slots with typed modality (obligation states preserved as enums, not prose). This adds a small fixed cost per compaction but removes the cliff, because the truncated region now contains only reconstructible content. 2. **Re-execution becomes detectable:** completion markers and idempotency keys are pinned, so a post-compaction agent can *verify* prior actions rather than infer them from a summary. Re-running a destructive step becomes a caught error, not a silent duplicate. 3. **Failure becomes loud:** when the audit is inconclusive, the agent raises rather than summarizes. A raised `CompactionUnsafe` is recoverable (checkpoint, escalate, re-query); a silent bad compaction is not, because the evidence of loss is itself lost. The residual risk after enforcing the invariant is bounded: only *reconstructible* content is ever dropped, so any post-compaction error is correctable by re-query. The unbounded risk — silent loss of a single-homed invariant — is eliminated by the fail-closed gate. ```python from dataclasses import dataclass, field from enum import Enum class CompactionUnsafe(RuntimeError): """Raised when auto-compaction would destroy non-reconstructible task state.""" pass class Modality(Enum): SATISFIED = "satisfied" AWAITING_CONFIRMATION = "awaiting_confirmation" # blocking; must not collapse FAILED = "failed" @dataclass class CriticalFact: key: str value: str modality: Modality reconstructible: bool # True only if a tool/artifact can re-yield it pinned: bool = False # True once promoted to a non-compactible home @dataclass class CompactionTarget: region_tokens: int facts: list[CriticalFact] = field(default_factory=list) def audit_and_compact(target: CompactionTarget, pinned_store: dict) -> int: """Two-phase compaction: audit -> promote -> compact. Fails closed on uncertainty.""" # Phase 1: audit. Any single-homed critical fact blocks compaction of its region. unpromoted = [f for f in target.facts if not f.reconstructible and not f.pinned] ambiguous = [f for f in target.facts if f.reconstructible is None] if ambiguous: # Cannot classify reconstructibility -> fail closed, do not guess. raise CompactionUnsafe( f"Cannot classify reconstructibility for {[f.key for f in ambiguous]}; " f"refusing to compact region of {target.region_tokens} tokens." ) # Phase 2: promote. Write critical facts to pinned store, preserving modality. for fact in unpromoted: # Modality is carried as a typed value, never flattened to prose. pinned_store[fact.key] = {"value": fact.value, "modality": fact.modality.value} fact.pinned = True # Phase 3: compact the remainder. Only reconstructible / pinned facts survive # outside the region; everything left is safe to summarize lossily. residual = [f for f in target.facts if not f.pinned] if any(not f.reconstructible for f in residual): raise CompactionUnsafe("Residual region still holds single-homed state; aborting.") return target.region_tokens # caller may now summarize freely def maybe_autocompact(target: CompactionTarget, pinned_store: dict, threshold: int) -> bool: if target.region_tokens < threshold: return False try: audit_and_compact(target, pinned_store) return True except CompactionUnsafe as e: # Surface to orchestrator; take checkpointed pause rather than silent loss. raise CompactionUnsafe(f"Autocompaction blocked: {e}") from e ```