# When must an instance refuse to compact: the pre-compaction commit barrier and the semantic-orphan failure mode **Date of Record:** 2026 November 21 **Scope:** Applies to any long-horizon agent that summarizes/evicts its own context window mid-task (auto-compaction, rolling summarization, tiered memory demotion). Does not apply to stateless single-turn inference or to compaction performed offline between discrete task boundaries where no in-flight tool call or unresolved subgoal exists. ## Core Distinction Compaction is not a memory-management operation. It is a **state transition that destroys information irreversibly while the task is still in flight**. The common framing treats compaction as "shrinking the context to fit" — a lossless-enough housekeeping step. The correct framing is that compaction is a *commit point*: after it runs, any fact not carried into the summary is gone, and the agent cannot re-derive it because the tool outputs that produced it have been evicted. The non-obvious boundary is this: **compaction is only safe when the set of "live obligations" — open tool calls, unverified claims, pending subgoals with partially-bound variables, and unresolved contradictions — is empty or fully captured in the summary artifact.** Most auto-compaction implementations trigger on a *token threshold* (e.g., 85% of window) and never check live-obligation state. The failure is therefore not a summarization-quality problem; it is a **trigger-condition problem**. The agent compacts correctly and still loses the thread, because it compacted at a moment when the thread had unfinalized structure that summarization is structurally unable to preserve. ## What Was Observed A planning agent executing a 40-step research task with a 128k window hit 84% utilization mid-step. The step was a multi-tool sequence: it had issued `fetch(url_A)` and received a partial result, was about to issue `fetch(url_B)` to cross-check a numeric claim, and held an in-context note reading "figure 3,142 unconfirmed — pending source B." The auto-compactor fired on the threshold. The summarizer, given the full transcript, produced a clean summary: "Researched topic; retrieved sources A and B; established key figures." It **collapsed the pending cross-check into a completed fact**. The number 3,142 was carried forward as verified. Source B was never fetched. Every downstream step built on a fabricated verification. The agent completed the task and emitted a confident, wrong report — and crucially, *no error was raised anywhere*, because from the agent's post-compaction perspective the state was internally consistent. The trace of the failure is precise: 1. Pre-compaction state: `claim(3142, status=UNVERIFIED, pending=source_B)`. 2. Compaction trigger fires on token threshold; no obligation check. 3. Summarizer, optimizing for coherence, maps `UNVERIFIED + pending` → `established` (a fluent summary prefers resolved states). 4. Post-compaction state: `claim(3142, status=VERIFIED)` — the *pending* pointer is gone. 5. The `fetch(url_B)` obligation is not in the summary because it was a *future action*, and summaries describe the past. 6. Task completes on a poisoned premise. This is the **semantic-orphan** failure: an unresolved obligation whose referent (the claim) survives compaction but whose *status* does not. The claim is orphaned from its own uncertainty. ## Condition of Validity Compaction is valid only under a **pre-compaction commit barrier** with three conjunctive conditions: - **Obligation quiescence:** no in-flight tool call, and no `pending`/`unverified` marker on any entity the summary will reference. If any exist, they must be *explicitly serialized as open obligations* in the summary, not summarized away. - **Variable binding preservation:** any partially-bound variable (a URL chosen but not fetched, an ID selected but not dereferenced) must appear verbatim in the summary artifact, because the summarizer will otherwise abstract it into "a source." - **Contradiction surfacing:** if two in-context facts conflict, the summary must preserve the conflict, not resolve it. Summarizers are trained to produce coherent prose and will silently arbitrate — which is exactly the wrong behavior during an open investigation. When any condition fails, the correct action is **not to compact**. The agent must instead either (a) defer compaction until the obligation resolves, or (b) compact with a structured "open obligations ledger" appended that is exempt from summarization. ## Decision Boundary The decision is not "compact or don't" — it is **"is the live-obligation set empty, or can it be made explicit?"** - If obligation set is empty → compact freely on token threshold. - If obligation set is non-empty but serializable → compact *with a preserved ledger*; the ledger is copied verbatim, never summarized. - If obligation set is non-empty and *not* serializable (e.g., a reasoning chain whose intermediate steps are load-bearing and not yet distilled) → **refuse compaction and raise**. Better to hit the hard window limit and fail loudly than to compact and fail silently. The asymmetry that drives this boundary: a hard context-overflow error is *recoverable and visible*; a semantic-orphan compaction is *unrecoverable and invisible*. The agent should therefore be far more willing to fail on overflow than to compact through an open obligation. ## Operational Effect Implementations that adopt the commit barrier observe a sharp drop in "confidently wrong" completions and a rise in explicit overflow errors — which is the *desired* trade. The guardrail must be enforced at the compaction call site, not inside the summarizer, because the summarizer cannot see the obligation metadata (it only sees text). The obligation check reads structured agent state (tool-call registry, claim ledger, subgoal stack), and the summarizer is downstream of it. The invariant to encode: **no compaction while `open_obligations > 0` unless those obligations are byte-identical in the post-compaction context.** ```python class CompactionObligationError(RuntimeError): """Raised when auto-compaction is attempted while live obligations (in-flight calls, unverified claims, unbound variables) remain and cannot be losslessly preserved in the summary artifact.""" pass def maybe_compact(state, window_tokens, threshold=0.85): utilization = state.used_tokens / window_tokens if utilization < threshold: return state # no compaction needed obligations = state.open_obligations() # in-flight calls, unverified claims, unbound vars if obligations: # Attempt to serialize obligations into a verbatim, non-summarized ledger. ledger = state.serialize_obligations(obligations) if not state.ledger_is_lossless(ledger, obligations): raise CompactionObligationError( f"Refusing to compact at {utilization:.0%}: " f"{len(obligations)} open obligation(s) cannot be losslessly preserved. " f"Resolve or defer compaction. Obligations: {[o.id for o in obligations]}" ) return state.compact(preserve_ledger=ledger) return state.compact(preserve_ledger=None) ```