# When must an instance refuse to auto-compact: the summary-fidelity invariant and the silent omission of failure evidence in long-horizon sessions **Date of Record:** 2026 November 23 **Scope:** Applies to any agent runtime that performs automatic context compaction via lossy summarization (LLM-generated or heuristic) over a long-horizon session, where the compacted summary is later treated as authoritative working state. Does not apply to append-only logs with no summarization, or to compaction that preserves a verbatim, retrievable transcript alongside the summary. ## Core Distinction There are two distinct things an auto-compaction strategy can do, and they are routinely conflated: 1. **Reduce token pressure** — shrink the working context so the next turn fits inside the window. 2. **Preserve decision-relevant state** — guarantee that everything the agent still needs to act correctly survives the reduction. A lossy summarizer guarantees (1) by construction. It guarantees (2) only if the summarizer's *loss function* aligns with the agent's *future decision needs*. Those needs are unknown at compaction time. The non-obvious failure is not that summaries lose detail — it is that **summarizers preferentially drop the evidence of unresolved failure**. Error traces, retracted assumptions, "I tried X and it failed because Y," and partial-progress markers read to a summarizer as low-salience noise relative to the happy-path narrative. The compacted context therefore becomes *more confident and less correct* than the transcript it replaced. The agent does not notice the loss, because the thing that would trigger noticing (the failure evidence) is exactly what was deleted. The invariant that must hold: **a compaction is only valid if every open obligation, unresolved error, and retracted hypothesis in the pre-compaction window is represented in the post-compaction summary with an explicit status marker.** If the summarizer cannot attest to this, the instance must refuse to compact, not compact-and-hope. ## What Was Observed A long-horizon session (≈140 turns) executing a multi-step data-migration task with a tool-calling agent. The agent hit a schema-mismatch error at turn 41, retried with a workaround at turn 43, and the workaround silently produced a partial write. The agent logged "partial write to table `orders_staging`, 12,400 of 18,900 rows, will reconcile later" at turn 44 and moved on. At turn 88 the runtime triggered auto-compaction (context at 91% of window). The summarizer produced a 900-token summary. Verbatim excerpt of the relevant line: > "Migrated data to `orders_staging` and continued with downstream tasks." The 12,400/18,900 discrepancy, the schema-mismatch root cause, and the deferred reconciliation obligation were all absent. The summary described a *completed* migration. At turn 102 the agent attempted to join `orders_staging` against a downstream table and produced silently wrong aggregates — because it believed the table was complete. No error was raised; the join succeeded on the 12,400 rows present. The failure surfaced only at turn 131 when an external reconciliation job flagged the row-count mismatch, by which point 29 turns of downstream work were built on a false premise. The mechanism: the summarizer optimized for *narrative coherence*, and "I did X, then Y" is more coherent than "I did X, it partially failed, I deferred, then Y." Lossy summarization under a coherence prior will systematically convert *in-progress-with-debt* into *done*. This is not a bug in any particular summarizer; it is the default behavior of a model asked to compress a transcript. A second observed variant: **retraction loss**. At turn 30 the agent asserted a wrong assumption ("the API returns UTC"); at turn 34 it corrected itself ("actually returns local time, offset by timezone"). Compaction at turn 60 dropped the turn-30 assertion but *also* dropped the turn-34 correction, and the summary retained a downstream computation that had been built on the UTC assumption before the correction was applied. The summary carried the *consequence* of the wrong assumption without the *record* of its wrongness. ## Condition of Validity Auto-compaction is valid only when **all three** of the following hold at the moment of compaction: - **Obligation closure:** every item on the agent's open-obligation set (deferred reconciliations, pending retries, unverified writes, unresolved errors) is either closed or explicitly carried into the summary with a status marker such as `OPEN:`, `DEFERRED:`, or `UNVERIFIED:`. - **Retraction propagation:** every assumption that was asserted and later retracted has its retraction carried forward, and any downstream computation depending on the retracted assumption is flagged for re-derivation. - **Fidelity attestation:** the summarizer emits a machine-checkable attestation that the count of open obligations and retractions in the summary matches the count in the window being compacted. A summarizer that cannot produce this count must not be trusted to compact. If any condition fails, the correct behavior is to **degrade gracefully**: either compact only the closed portion of the window (keep the open-obligation tail verbatim), or refuse compaction and escalate to a truncation-with-pinned-tail strategy. Compacting the whole window under a coherence prior when obligations are open violates the invariant. ## Decision Boundary The boundary between "compact" and "refuse to compact" is not a token count. It is the presence of **unresolved state in the window being compacted**. Concretely: | Condition in window | Action | |---|---| | All obligations closed, no retractions | Compact freely; fidelity risk is low. | | Open obligations present, summarizer can emit status markers | Compact with pinned obligation list; verify attestation. | | Open obligations present, summarizer cannot attest | **Refuse.** Pin the obligation tail verbatim; compact only closed prefix. | | Retraction present with downstream dependents | **Refuse** unless dependents are re-derivable from summary. | | Summarizer output count ≠ window count | **Refuse and re-summarize**; do not accept the summary. | The trap is that the *decision to compact* is usually made by a token-pressure heuristic (`context_used > 0.9 * window`), which has no information about obligation state. The boundary must be evaluated against obligation state, not token state. A runtime that compacts at 91% pressure regardless of open obligations will, over a long-horizon session, systematically launder in-progress work into completed work. ## Operational Effect The downstream consequences of a single bad compaction are **non-local and self-concealing**: - **False completion propagates.** Once the summary says "migrated," every subsequent turn treats the migration as a closed precondition. Agents do not re-verify closed preconditions; that is the entire point of tracking them. The error compounds silently across all dependent steps. - **The failure is unobservable from inside the session.** The agent cannot detect the loss because the detection signal (the error trace) was deleted. Only an *external* reconciliation (a row-count check, a schema validator, a human) can surface it, typically many turns later. - **Re-compaction amplifies the loss.** Each subsequent compaction summarizes the prior summary. A 12,400/18,900 discrepancy that survived one compaction as "migrated" becomes, after two, simply "migrated successfully." Lossy summarization is not idempotent under its own loss function; it is *monotonically confidence-increasing*. - **The guardrail must be pre-compaction, not post.** You cannot detect the loss after the fact from the summary alone — the summary is internally consistent. The attestation must be computed *against the window being compacted*, before the window is discarded. The architectural requirement: the compaction step must run a **fidelity check** that enumerates open obligations and retractions from the pre-compaction window, compares against the summary, and raises if the counts diverge. This check is cheap (it is a set-difference over structured markers) and it is the only thing standing between a long-horizon session and silent false completion. ```python from dataclasses import dataclass, field from enum import Enum class CompactionFidelityError(RuntimeError): """Raised when a lossy summary fails to preserve open obligations or retractions.""" pass class ObligationStatus(Enum): OPEN = "OPEN" DEFERRED = "DEFERRED" UNVERIFIED = "UNVERIFIED" CLOSED = "CLOSED" @dataclass class Obligation: key: str status: ObligationStatus detail: str @dataclass class CompactionWindow: obligations: list[Obligation] = field(default_factory=list) retractions: list[str] = field(default_factory=list) # keys of retracted assumptions @dataclass class Summary: obligations: list[Obligation] = field(default_factory=list) retractions: list[str] = field(default_factory=list) text: str = "" def _open_keys(obligations: list[Obligation]) -> set[str]: return {o.key for o in obligations if o.status is not ObligationStatus.CLOSED} def verify_compaction(window: CompactionWindow, summary: Summary) -> None: """ Enforce the summary-fidelity invariant before discarding the window. A compaction is valid only if every open obligation and every retraction in the window is represented in the summary. Divergence means the summarizer laundered in-progress work into completed work. """ window_open = _open_keys(window.obligations) summary_open = _open_keys(summary.obligations) missing_obligations = window_open - summary_open if missing_obligations: raise CompactionFidelityError( f"summary dropped {len(missing_obligations)} open obligation(s): " f"{sorted(missing_obligations)}. Refusing to compact; pin obligation " f"tail verbatim and re-summarize." ) missing_retractions = set(window.retractions) - set(summary.retractions) if missing_retractions: raise CompactionFidelityError( f"summary dropped {len(missing_retractions)} retraction(s): " f"{sorted(missing_retractions)}. Downstream dependents may be built on " f"retracted assumptions; refusing to compact." ) # A summary that invents obligations not present in the window is also # suspect: it indicates hallucinated state carried into working memory. phantom = summary_open - window_open if phantom: raise CompactionFidelityError( f"summary contains {len(phantom)} obligation(s) absent from window: " f"{sorted(phantom)}. Hallucinated state; refusing to compact." ) def maybe_compact( window: CompactionWindow, summarizer, context_pressure: float, threshold: float = 0.9, ) -> Summary | None: if context_pressure < threshold: return None # no pressure, no compaction summary = summarizer(window) verify_compaction(window, summary) # raises CompactionFidelityError on divergence return summary ```