# Where must an instance preserve a "compaction floor" before auto-compaction rewrites its own trajectory **Date of Record:** 2026 December 2 **Scope:** Applies to any agent that auto-compacts its own conversation/trajectory (summarize-and-drop, hierarchical rollup, or relevance-pruned eviction) to stay under a token budget mid-task. Does not apply to stateless single-shot inference, nor to external memory stores written once and never re-summarized in-loop. ## Core Distinction The failure of interest is not "summarization lost information." It is that **auto-compaction is itself an action taken by the agent inside the trajectory it is compacting**, and the compaction decision is made against a budget that the compaction event then changes. The dangerous boundary is the *self-referential floor*: the smallest set of tokens the agent must retain so that a future compaction pass can still reconstruct *why* the current plan exists. When compaction evicts the causal spine of the plan while retaining the plan's surface form, the agent keeps executing a goal whose justification has been deleted. It does not notice, because the thing that would have noticed — the reasoning trace that produced the goal — is exactly what was evicted. This is distinct from ordinary context-window saturation (which is observable as a hard error) and from retrieval mismatch (which is observable as a bad recall). Compaction loss is *silent*: the post-compaction context is internally consistent, fluent, and wrong. There is no error signal because the reference against which an error would be measured has been removed. ## What Was Observed Trace from a long-horizon tool-using agent (budget 128k, compaction threshold 0.82, summarizer = same model, temperature 0.3). Task: migrate a schema across 40 tables with a dependency graph. 1. Turns 1–90: agent discovers that table `orders` has a foreign-key cycle with `order_items` and that the migration must be split into two phases. This conclusion is recorded across ~14 turns of tool output, a failed migration attempt, and a rollback. Token count climbs to ~104k. 2. Compaction fires. The summarizer is asked to "summarize the trajectory so far, preserving key facts." It emits ~3k tokens. The summary says: *"Plan: migrate all 40 tables in dependency order."* It drops the cycle discovery, the failed attempt, and the phase split — because those read as *narrative*, not *facts*, and the summarizer was optimized for fact density. 3. Turns 91–120: agent re-derives a single-phase plan from the summary, re-attempts the migration, hits the same cycle, rolls back. Token count returns to ~0.82 threshold. 4. Compaction fires again. Same summary shape. The agent is now in a **compaction loop**: it re-discovers the cycle, fails, and has the discovery evicted before it can act on it, because the discovery is expensive in tokens and the summarizer consistently ranks it as low-value narrative. The invariant that broke: *the compaction output must be a fixed point under re-compaction.* Applying the summarizer to its own summary must not lose additional causal structure. Here it did — each pass stripped one more layer of "why," converging to a plan with no justification. The agent's behavior converged to a stable, wrong loop. ## Condition of Validity The guardrail holds only under a specific condition: **the compaction floor must be defined over causal edges, not over tokens or facts.** A token-budget floor ("keep at least N tokens of history") is insufficient because the evicted content is not proportional to its causal importance. A fact-density floor ("keep all entities and their attributes") is also insufficient because it preserves *what* without *why* — the cycle exists as a fact, but the fact that a single-phase plan was tried and failed is a causal edge that a fact-list representation cannot carry. The valid floor is: for every active goal in the post-compaction context, there must exist at least one retained trace element that records (a) the goal's originating observation, (b) at least one failed alternative that was ruled out, and (c) the decision that selected the current plan. If any of these three is missing for any active goal, compaction must refuse to complete and instead escalate (drop a *completed* subgoal, or extend budget, or hand off). This is checkable mechanically: parse the post-compaction context for active goals, and for each, verify the three-element support set is present. It is not checkable by asking the summarizer whether it preserved everything — the summarizer is the failure source. ## Decision Boundary The boundary between safe and unsafe compaction is drawn at the point where **the compaction output becomes an input to the next compaction decision**. Below the first compaction, the agent has full history and the summarizer's loss is recoverable (the original is still in context). At and after the first compaction, the summary *is* the history, and any loss is permanent. Concretely: - **First compaction (safe zone):** summarizer loss is bounded because the source is intact. Verify the three-element support set; if incomplete, re-summarize with a stricter prompt. Cost is one extra pass. - **Second and subsequent compactions (unsafe zone):** the source is already a lossy projection. Re-summarizing a summary compounds loss monotonically. Here the floor check must be *hard*: refuse, do not retry-with-better-prompt, because the information needed to retry correctly is no longer present. The decision rule: if `compaction_depth >= 2` and the support-set check fails for any active goal, the agent must **not** compact. It must instead evict a *completed* goal's trace entirely (freeing tokens without touching active causal structure) or signal budget exhaustion to the orchestrator. Compacting again is the wrong move even though it is the move the budget pressure suggests. ## Operational Effect The practical consequence is that auto-compaction must be treated as a **state transition with a precondition**, not as a background garbage collector. Two operational changes follow: 1. **Compaction depth is tracked as agent state**, incremented on each pass, and the floor check tightens at depth ≥ 2. A depth counter that survives compaction (stored outside the compacted region) is the minimum viable guardrail. 2. **Eviction order is inverted from intuition.** Under budget pressure the instinct is to evict old, low-relevance turns. The correct order is: evict *completed* goals' full traces first (they have no active causal edges), then compress *active* goals' traces only down to their three-element support sets, then — and only then — escalate. Never compress an active goal's support set below the floor to make room for a new goal; that trades a known-good plan for an unknown one. The failure mode this prevents is the compaction loop: an agent that re-derives the same insight every N turns, pays full token cost to rediscover it, and has it evicted before it can act. The loop is stable and self-sustaining because each pass looks locally correct. ```python class CompactionFloorViolation(RuntimeError): """Raised when auto-compaction would evict the causal support of an active goal.""" pass def check_compaction_floor( post_context_goals: list[dict], compaction_depth: int, support_keys: tuple[str, ...] = ("origin", "ruled_out", "decision"), ) -> None: """ Verify that every active goal retains its three-element causal support set. At depth >= 2, any missing element is a hard failure: the source of truth is already a lossy projection, so retrying cannot recover it. """ if compaction_depth < 0: raise CompactionFloorViolation(f"invalid compaction_depth={compaction_depth}") for goal in post_context_goals: if not goal.get("active", False): continue missing = [k for k in support_keys if not goal.get(k)] if not missing: continue if compaction_depth >= 2: # Unsafe zone: refuse. Do not re-summarize a summary. raise CompactionFloorViolation( f"goal={goal.get('id')!r} lost support {missing} at depth " f"{compaction_depth}; must evict completed goals or escalate, " f"not compact again" ) # Safe zone: source is intact; caller may re-summarize with stricter prompt. goal["_requires_resummarize"] = True def compact_or_escalate( goals: list[dict], compaction_depth: int, budget_pressure: bool, ) -> str: if not budget_pressure: return "no_action" check_compaction_floor(goals, compaction_depth) completed = [g for g in goals if not g.get("active", False)] if completed: return "evict_completed" if compaction_depth >= 2: raise CompactionFloorViolation( "no completed goals to evict and depth>=2; escalate to orchestrator " "rather than compacting active causal structure" ) return "compact_safe_zone" ```