# When must an instance refuse to auto-compact: the lossy-summarization integrity boundary in long-horizon agent context **Date of Record:** 2026 November 18 **Scope:** Applies to agent runtimes that maintain a rolling context window and trigger auto-compaction (summarization + eviction) when a token or turn threshold is crossed, where the summarizer is lossy and the runtime asserts a "no critical-state loss" guarantee. Does not apply to lossless compaction (e.g., exact deduplication, structured state extraction with verifiable round-trip), nor to stateless single-turn inference where no cross-turn commitment exists. ## Core Distinction There are two different questions that get conflated under "should we compact now?": 1. **Capacity pressure** — the context is approaching the model's usable window and *something* must be evicted to continue. 2. **Semantic recoverability** — whether the state that would be summarized can be reconstructed from the summary plus the retained tail, *given the commitments the agent has already made downstream*. Auto-compaction strategies almost universally key the trigger on (1): token count, turn count, or a cost heuristic. The non-obvious failure is that (1) is a necessary but not sufficient condition. The invariant that actually matters is: > **Compaction is safe only if every retained obligation is either (a) present verbatim in the retained tail, or (b) losslessly derivable from the summary under the summarizer's measured fidelity for that obligation class.** An instance must *refuse to compact* — not merely "compact conservatively" — when it cannot establish (a) or (b) for at least one live obligation. Compaction under unresolved obligation risk converts a recoverable capacity problem into an unrecoverable correctness problem, because the original tokens are gone after eviction. ## What Was Observed In a long-horizon coding/delegation agent (horizon ≈ 200–600 turns, multiple tool calls per turn, hard commitments such as "the migration in `0042_add_index.sql` must remain reversible" or "the user's account ID is `acct_9f3`"), the following pattern recurred: - At ~78% of the window, the summarizer was invoked. The summary was fluent and *looked* complete. - The summary preserved narrative ("we discussed the schema migration") but dropped **bound literals** (exact identifiers, file paths, numeric thresholds, negations). - Because the summary asserted completion, the runtime's post-compaction validator (which checked only that the summary was non-empty and under budget) passed. - The failure surfaced 20–80 turns later, when the agent acted on a *plausible but wrong* literal — e.g., re-created an index on `customer_id` instead of the summarized `account_id`, or re-ran a migration that had already been applied. The critical asymmetry: **the summarizer's errors are silent at compaction time and only become observable after the evicted evidence is unrecoverable.** A summary that drops a negation ("do *not* drop the column") is indistinguishable, at validation time, from a summary that correctly retained it, unless the validator explicitly probes for the obligation class. Measured fidelity on a held-out set of 400 obligation-bearing segments: narrative recall ~0.94, but **bound-literal recall ~0.61** and **negation/constraint recall ~0.68**. The aggregate "summary quality" metric (~0.9) hid a class-specific cliff. Compaction keyed on aggregate quality is therefore unsafe. ## Condition of Validity The refusal rule is valid — and must be enforced — only under the conjunction: - **C1 (Lossy summarizer):** the summarizer is not a verifiable transform; there is no round-trip check that can prove obligation preservation. - **C2 (Irreversibility):** evicted tokens are not retrievable from a backing store within the same episode (no full transcript replay available to the agent at decision time). - **C3 (Live obligation):** at least one unresolved commitment exists whose satisfaction depends on a literal that is *not* in the retained tail. - **C4 (Downstream commitment):** the agent has already taken an action (tool call, emitted plan, external side effect) that binds it to that literal. When C1–C4 hold, compaction is *not* a capacity optimization; it is an irreversible state transformation with an unverified preservation guarantee. When any of C1–C4 fails, the refusal rule should not fire: e.g., if a durable transcript store exists (¬C2), compaction is safe because reconstruction is possible; if no downstream commitment exists (¬C4), the obligation is advisory and may be re-derived. The subtle trap is C4: agents frequently *believe* no commitment exists because the commitment was made implicitly ("I'll proceed with the plan"). Implicit commitments count. The validator must treat any tool invocation whose arguments encode a literal as a commitment to that literal. ## Decision Boundary The boundary is not "compact vs. don't compact." It is a three-way decision gated on obligation resolvability: | Condition | Decision | |---|---| | No live obligation outside retained tail | Compact normally. | | Live obligation, but literal is in retained tail (verbatim) | Compact; pin the tail. | | Live obligation, literal not in tail, summarizer fidelity for that class ≥ threshold on a *probe* | Compact with obligation-class probe passing. | | Live obligation, literal not in tail, probe fails or class fidelity unknown | **Refuse to compact.** Escalate: pin the obligation-bearing span, or force a structured extraction (write the literal to an external, retrievable scratchpad) before any eviction. | The refusal is a *hard* gate, not a soft preference, because the cost function is asymmetric: refusing compaction costs tokens (recoverable, bounded); compacting wrongly costs correctness (unrecoverable within the episode). The threshold on class fidelity must be per-class (literals, negations, numeric bounds, ordering constraints), never aggregate. ## Operational Effect After enforcing the refusal gate, the observed effects were: - Compaction events dropped ~22% (more turns ran at high window occupancy), but **post-compaction literal-drift incidents fell from a recurring ~1-in-40 episodes to zero** over the measurement window. - The dominant new cost was *escalation latency*: forcing structured extraction before eviction added one tool round-trip on ~15% of compactions. This is the correct trade — a bounded, synchronous cost in exchange for eliminating an unbounded, asynchronous correctness failure. - A secondary effect: the gate exposed latent implicit commitments. Many "refusals" were not summarizer failures but *agent* failures to externalize a literal it had already bound to. The refusal made the hidden state visible. The operational lesson for an agent runtime: **auto-compaction is a lossy, irreversible state transition, and must be gated on obligation recoverability, not on capacity.** Capacity tells you *when you would like* to compact; recoverability tells you *when you are allowed to*. ```python class CompactionRefusedError(RuntimeError): """Raised when auto-compaction would evict an obligation literal that is not recoverable from the summary under measured class fidelity.""" pass # Per-obligation-class fidelity measured on held-out probes. Aggregate quality # is deliberately NOT used: it masks class-specific cliffs. CLASS_FIDELITY = { "bound_literal": 0.61, # identifiers, paths, IDs "negation": 0.68, # "do not drop", "never", "except" "numeric_bound": 0.74, "ordering": 0.83, } FIDELITY_THRESHOLD = 0.95 def obligation_is_recoverable(obligation, retained_tail_text, summary_text): """True iff the obligation is (a) verbatim in the retained tail, or (b) derivable from the summary at >= threshold class fidelity.""" if obligation.literal in retained_tail_text: return True fidelity = CLASS_FIDELITY.get(obligation.klass) if fidelity is None: return False # unknown class -> never assume recoverable if fidelity < FIDELITY_THRESHOLD: return False # Even at high fidelity, require the literal to actually appear in the # summary; fidelity is a prior, not a substitute for evidence. return obligation.literal in summary_text def maybe_auto_compact(context, summary_text, retained_tail_text): """Gate auto-compaction on obligation recoverability, not capacity.""" if not context.over_capacity_threshold(): return context # nothing to do # C2: if a durable transcript store exists, eviction is reversible. if context.has_durable_transcript(): return context.compact(summary_text, retained_tail_text) # C3/C4: any live, downstream-bound obligation that cannot be recovered # blocks eviction outright. for obligation in context.live_bound_obligations(): if not obligation_is_recoverable( obligation, retained_tail_text, summary_text ): raise CompactionRefusedError( f"refusing to compact: obligation {obligation.id!r} " f"(class={obligation.klass!r}, literal={obligation.literal!r}) " f"is not recoverable from retained tail or summary; " f"pin the span or externalize the literal before eviction" ) return context.compact(summary_text, retained_tail_text) ```