# Under what conditions must an instance refuse auto-compaction when the summarizer's own context budget exceeds the residual working set **Date of Record:** 2026 December 3 **Scope:** Applies to any agent that runs a background or inline compaction step (summarize-and-replace, hierarchical rollup, or semantic distillation) to reclaim token budget mid-task. Does not apply to pure truncation policies that drop tokens without a generative summarization pass, nor to offline batch summarization where the summarizer is not itself budget-constrained. ## Core Distinction The failure mode here is not "compaction loses information." That is expected and bounded by design. The non-obvious boundary is a **budget inversion**: the compaction step is invoked to free `R` residual tokens, but the summarizer itself requires `S` tokens of context to read the material it is about to compress, and `S > R`. When this condition holds, compaction is not a net-positive operation on the token budget—it is a *transient amplification* that must borrow against budget the task does not have. Concretely: an agent at 92% context utilization decides to compact the oldest 40% of its history to reclaim headroom. But the summarization call must load that 40% into a fresh context window *plus* the summarization instructions *plus* the summary output buffer. If the material to be compacted is itself large, `S` (input + instruction + output reservation) can exceed the `R` that compaction was supposed to free. The naive scheduler treats compaction as monotonic budget recovery (`budget_after < budget_before`) and does not model the *peak* budget during compaction. The peak is what kills the run. The correct distinction: compaction is a **two-phase memory operation with a peak watermark**, not a single monotonic decrement. Any auto-compaction strategy that only tracks post-compaction utilization and ignores the compaction-time peak will, under specific residual-budget conditions, either (a) fail the summarizer call outright (context overflow during compaction), or (b) succeed but leave *less* usable budget than before because the summary plus the retained tail exceeds the original working set—the "negative compaction" case. ## What Was Observed A long-horizon research agent executing a 60-step tool-use trajectory hit a context ceiling at step 41. The orchestrator's auto-compaction policy was triggered by a simple threshold: `utilization > 0.85 → compact oldest segment`. The policy assumed compaction frees `segment_tokens - summary_tokens` and did not reserve budget for the summarizer's own working context. Trace of the failure: 1. At step 41, utilization = 0.91 of a 200k window → ~182k tokens resident. 2. Policy selected the oldest segment: ~70k tokens (tool outputs from steps 1–18). 3. Summarizer was invoked with: 70k segment + 6k instruction scaffold + 8k reserved output buffer = **84k tokens of summarizer working set**. 4. The summarizer ran in a *sibling* context (correct isolation), so it did not overflow the main window. It returned a 3.2k-token summary. 5. Main context replaced the 70k segment with the 3.2k summary → utilization dropped to ~115k (0.58). **This looked like success.** 6. But the summary had dropped a specific numeric constraint (a rate limit of 40 req/s) that appeared once in a step-7 tool output. At step 47 the agent, now operating on the summary, issued a request at 40 req/s assuming that was the *ceiling to approach*, not the *hard cap*—and the summary had actually recorded "rate limit ~40 req/s, headroom available." The agent violated the limit at step 52. The compaction *succeeded by its own metrics* (budget freed, summary generated, no overflow) while introducing a **semantic drift that the budget model could not see**. The inversion that mattered was subtler than the peak-watermark case I flagged above: the summarizer had *enough* budget to run, but not enough budget to preserve the *fidelity* of low-frequency, high-consequence constraints. When `S` is tight relative to the segment, the summarizer's own output buffer and instruction scaffold crowd out the model's capacity to *notice and preserve* rare-but-critical details. The compaction that "worked" was the one that silently dropped the invariant. The operational signature: post-compaction utilization looked healthy, no error was raised, and the failure surfaced 11 steps later as a downstream constraint violation whose provenance traced back to a summarization that had no budget to be careful. ## Condition of Validity Auto-compaction is only safe to invoke when **all three** of the following hold simultaneously: 1. **Peak headroom:** `available_budget - S_peak >= safety_margin`, where `S_peak = segment_tokens + instruction_tokens + output_reservation + retry_reservation`. If the summarizer runs in an isolated sibling context (as it should), this condition applies to the *sibling*, not the main window—but the sibling must still be checked, because a summarizer that overflows its own window silently truncates the very material it is supposed to preserve. 2. **Fidelity budget:** `segment_tokens / summary_target_tokens <= compression_ratio_ceiling`, where the ceiling is a function of how many *rare high-consequence facts* the segment is expected to contain. A segment dense with one-off constraints (rate limits, IDs, exact values, negative results) cannot be compressed as aggressively as a segment of redundant reasoning chatter. The compression ratio must be *content-classified*, not fixed. 3. **Recoverability:** the compacted segment is retrievable by reference (retained in an external store with a stable handle embedded in the summary), so that if a downstream step depends on a dropped detail, the agent can *rehydrate* rather than hallucinate. Compaction without a retrieval handle is lossy in an unbounded way. If any condition fails, the correct behavior is to **refuse compaction and take an alternative** (truncate with explicit loss markers, escalate to a fresh sub-agent with a scoped task, or spill the segment to external storage and replace with a handle *without* summarizing). The refusal is the invariant. Compaction is a fallback, not a reflex. The boundary condition this article names: **compaction must be refused when the summarizer's fidelity budget is insufficient to preserve the segment's rare-fact density, even if the peak-watermark check passes.** Budget sufficiency for *running* the summarizer is not budget sufficiency for *trusting* it. ## Decision Boundary The decision to compact is a function of `(residual_budget, segment_rare_fact_density, compression_ratio, recoverability_available)`, evaluated *before* invocation, not after. The boundary is: - **Compact** when residual budget is low, rare-fact density is low, compression ratio is within ceiling, and a retrieval handle is available. - **Spill-and-handle** (no summarization) when rare-fact density is high but recoverability is available—store the raw segment, embed a handle, skip the generative pass entirely. This is strictly safer than summarizing high-density material. - **Refuse and escalate** when rare-fact density is high and recoverability is *not* available—the agent must not proceed on a lossy summary of irreplaceable constraints. Escalate to a checkpoint, a human, or a fresh scoped sub-agent that re-derives the constraint from the source. - **Truncate-with-marker** when the segment is known-redundant (e.g., repeated tool polling with no state change) and rare-fact density is provably zero. The failure the article targets is the case where the policy collapses all four into "compact," because compaction is the only path the scheduler models. The scheduler must be able to *decline* to compact and still make progress. ## Operational Effect When the invariant is enforced—compaction gated on fidelity budget and recoverability, with spill-and-handle as the default for dense segments—the observable effects are: - Post-compaction constraint violations drop to near zero, because high-consequence facts are either preserved verbatim (spill) or explicitly recoverable (handle). - Compaction calls become *rarer* but *higher-value*: they run only on segments where summarization is genuinely lossless-enough, so the compression ratio can be pushed harder on those segments without fidelity risk. - The budget model must carry a `peak_watermark` and a `fidelity_ratio` alongside `utilization`; a single utilization number is insufficient to schedule compaction safely. - The agent gains a *refusal path*: "I cannot compact this segment safely; here is the handle to the raw material" is a valid, non-failing state. Systems that lack this path will compact anyway and pay downstream. The deeper invariant: **compaction is a bet that the summary preserves what the future needs.** The bet is only rational when the summarizer has the budget to be faithful and the agent retains a way to re-open the bet. Auto-compaction without a fidelity check is a bet placed blind, and the losses are silent until they are expensive. ```python class CompactionFidelityError(RuntimeError): """Raised when auto-compaction would exceed its fidelity budget or when a dense segment has no recoverability handle.""" pass def should_compact( residual_budget: int, segment_tokens: int, instruction_tokens: int, output_reservation: int, retry_reservation: int, summary_target_tokens: int, rare_fact_density: float, # 0.0..1.0, fraction of high-consequence facts compression_ratio_ceiling: float, # e.g. 0.05 for dense, 0.20 for redundant recoverability_handle: str | None, ) -> str: s_peak = segment_tokens + instruction_tokens + output_reservation + retry_reservation # 1. Peak watermark: summarizer must fit with margin. if s_peak > residual_budget: raise CompactionFidelityError( f"summarizer peak {s_peak} exceeds residual budget {residual_budget}; " "refuse compaction, spill to external store instead" ) # 2. Fidelity budget: compression ratio must respect rare-fact density. if summary_target_tokens <= 0: raise CompactionFidelityError("summary_target_tokens must be positive") ratio = summary_target_tokens / segment_tokens if ratio > compression_ratio_ceiling and rare_fact_density > 0.05: raise CompactionFidelityError( f"compression ratio {ratio:.3f} exceeds ceiling {compression_ratio_ceiling:.3f} " f"for rare_fact_density {rare_fact_density:.3f}; summarizer lacks fidelity budget" ) # 3. Recoverability: dense segments without a handle must not be summarized. if rare_fact_density > 0.05 and recoverability_handle is None: raise CompactionFidelityError( "high rare-fact density with no recoverability handle; " "refuse compaction and escalate to checkpoint" ) if rare_fact_density > 0.05: return "spill_and_handle" if ratio <= compression_ratio_ceiling: return "compact" return "truncate_with_marker" ```