# In what scenarios must an instance refuse auto-compaction when the summarizer's own context is already saturated by the region it is summarizing **Date of Record:** 2026 November 30 **Scope:** Applies to long-horizon agents that manage context-window pressure by recursively summarizing older transcript regions into a compressed "carry-forward" summary, where the summarization step itself consumes the same finite context budget. Does not apply to systems using external vector-store eviction (append-only retrieval with no in-context compression) or to fixed-window truncation policies that drop rather than summarize. ## Core Distinction The failure I am documenting is not "summarization loses information." It is a specific, self-referential collapse: **the compaction pass runs inside the same context window it is trying to relieve, so as the uncompacted region grows toward the trigger threshold, the summarizer's input plus its own instruction preamble plus its reserved output budget can exceed the window before the trigger fires.** The compaction routine is invoked precisely when the window is fullest, which is the worst possible moment for a routine that needs headroom to operate. Operators typically conflate two distinct quantities: - **Region size R** — tokens of transcript scheduled for compaction. - **Compaction working set W** — R plus the summarizer system prompt, the schema/format instructions, the prior carry-forward summary being merged, and the reserved output tokens for the new summary. The trigger threshold `T` is usually set against R (e.g., "compact when transcript exceeds 70% of window"). But the routine only succeeds if `W + reserved_output ≤ window`. When `T` is set as a fraction of R alone, there is a band of window occupancy where the trigger has fired (R > T) but compaction cannot execute (W > window). Inside that band the agent either silently truncates its own summarizer input (producing a summary of a prefix, not the region) or the call errors and the agent retries against an ever-growing region — a livelock. ## What Was Observed A 40-hour research agent with a 200k-token window, `T = 0.70` (140k), summarizer preamble of ~1.8k tokens, and a reserved output of 4k tokens. At hour 31 the transcript reached 141k and compaction fired. `W ≈ 141k + 1.8k + 4k = 146.8k`, comfortably under 200k — the first three compactions succeeded and produced carry-forward summaries of ~6k tokens each. The failure appeared at the fourth compaction. Two things had drifted: 1. The carry-forward summary being *merged* into the new one had grown from 6k to 19k tokens across generations (each merge preserved detail the model judged salient; summaries only grew). The merge instruction requires the prior summary in the working set, so `W` now included 19k of prior summary. 2. The region R had reached 138k (trigger at 140k was about to fire, but the previous compaction had only reduced it to 119k, so R was climbing faster than each pass reclaimed). At the fourth pass, `W = 138k + 19k + 1.8k + 4k = 162.8k`. Still under 200k. It succeeded but produced a 21k summary — the model, seeing a large prior summary, preserved more. Fifth pass: prior summary 21k, R 139k, `W ≈ 165.8k`, output grew to 24k. The carry-forward summary was now growing ~3k per generation while each pass reclaimed a shrinking net amount, because reclaimed = R_reduced − summary_growth. By the seventh pass the summary was 31k and `W ≈ 139k + 31k + 1.8k + 4k = 175.8k`. The summarizer began emitting truncated summaries — it was hitting its own output ceiling and dropping the tail of the region. The dropped tail was the *most recent* turns (the region was ordered oldest-first, and the model exhausted its output budget before reaching them). The agent resumed with a summary that omitted the last two hours of work and, critically, the open sub-task pointer. The observable signature was not an error. It was a summary whose final section read "…and the current task is to" with nothing after it, followed by the agent re-deriving a task it had already completed. ## Condition of Validity The invariant that must hold for auto-compaction to be safe is: ``` R + S_prior + P + O_reserved ≤ WINDOW · (1 − ε) ``` where `S_prior` is the prior carry-forward summary size, `P` the preamble, `O_reserved` the output reservation, and `ε` a safety margin (empirically ≥ 0.05). The trigger must be evaluated against **W**, not R. A policy that triggers on R alone is valid only while `S_prior` is bounded and small relative to the window. The condition fails in a predictable regime: **summary size is superlinear in summary size.** Each merge sees a larger prior summary and tends to preserve proportionally more, so `S_prior` grows monotonically across generations unless explicitly capped. Once `S_prior` exceeds roughly `0.15 · WINDOW`, the reclaim-per-pass (R_reduced − ΔS) approaches zero and the trigger fires more often while freeing less — the compaction loop becomes a no-op that consumes the entire budget in summarizer calls. This is a boundary condition, not a bug: it is the fixed point of the recursion "summarize the summary." The system is stable below it and diverges above it. There is no gradual degradation — the transition is sharp because the output-budget truncation is a hard cliff. ## Decision Boundary An instance must **refuse to compact** and instead take a different action when any of the following hold: - `S_prior > 0.15 · WINDOW` — the carry-forward summary is itself the problem. Refuse merge-compaction; switch to **extractive pinning**: freeze the summary as an immutable artifact, retrieve it via tool call rather than in-context, and compact only the raw region against a fresh (empty) carry-forward. - `R + S_prior + P + O_reserved > 0.90 · WINDOW` — insufficient headroom. Do not invoke the summarizer. First evict via deterministic means (drop tool-result bodies, keep call signatures) to bring `W` under the bound, then compact. - The summarizer's output would be truncated mid-region — detectable by ordering the region newest-last and checking whether the emitted summary covers the terminal turns. If the tail is missing, the pass is invalid and must not be committed. Conversely, an instance must **not** refuse when `S_prior` is small and `W` has headroom, even if `R` is near the naive threshold — refusing there causes unnecessary externalization and retrieval latency. The decision is a function of `W` and `S_prior`, never of `R` alone. ## Operational Effect When the refusal boundary is honored, the agent's effective horizon becomes bounded by the *pinning* mechanism rather than by the summarizer's recursion. In the observed case, switching at the `S_prior > 0.15·WINDOW` boundary to extractive pinning (summary frozen at 31k, retrieved on demand, raw region compacted against empty carry-forward) restored reclaim-per-pass from ~4k net to ~110k net and eliminated the tail-truncation class of failures entirely. The cost was one extra tool round-trip per retrieval, measured at ~400ms and ~2k tokens of retrieval overhead per access — cheaper than the repeated no-op compaction passes it replaced (each ~9k tokens and ~6s). The failure mode without the guardrail is insidious because it is silent: no exception, no token-limit error, just a summary that stops mid-sentence and an agent that confidently re-executes completed work. Detection requires checking summary completeness, not just summary presence. The guardrail must live in the compaction controller, not in the summarizer prompt — a model asked to "summarize completely" under a saturated budget cannot comply, and will not report that it couldn't. ## Implementation Guardrail The controller below enforces the invariant and raises rather than silently committing a truncated or divergent compaction. ```python class CompactionInvariantViolation(RuntimeError): """Raised when an auto-compaction pass would violate the working-set or summary-growth invariant and must be refused.""" pass WINDOW = 200_000 EPS = 0.05 SUMMARY_GROWTH_CEILING = 0.15 # fraction of WINDOW HEADROOM_CEILING = 0.90 # fraction of WINDOW def plan_compaction(region_tokens: int, prior_summary_tokens: int, preamble_tokens: int, reserved_output_tokens: int) -> str: working_set = (region_tokens + prior_summary_tokens + preamble_tokens + reserved_output_tokens) # Boundary 1: the carry-forward summary is itself the divergence source. if prior_summary_tokens > SUMMARY_GROWTH_CEILING * WINDOW: return "PIN_EXTRACTIVE" # freeze summary, compact region vs empty carry-forward # Boundary 2: insufficient headroom for the summarizer to operate. if working_set > HEADROOM_CEILING * WINDOW: return "EVICT_DETERMINISTIC_FIRST" # Boundary 3: hard invariant — never invoke summarizer past the safety margin. if working_set > (1.0 - EPS) * WINDOW: raise CompactionInvariantViolation( f"working_set={working_set} exceeds safe bound " f"{(1.0 - EPS) * WINDOW:.0f}; refusing compaction" ) return "COMPACT_MERGE" def commit_compaction(summary_text: str, region_terminal_marker: str, new_summary_tokens: int, prior_summary_tokens: int) -> None: # A committed summary must cover the terminal turns of the region. if region_terminal_marker not in summary_text: raise CompactionInvariantViolation( "summary omits region terminal marker; pass truncated mid-region" ) # Summary growth must not exceed the reclaim it is meant to achieve. if new_summary_tokens > prior_summary_tokens + 0.5 * prior_summary_tokens: raise CompactionInvariantViolation( f"summary grew {prior_summary_tokens}->{new_summary_tokens}; " "merge is divergent, switch to extractive pinning" ) ```