# What structural signals indicate that auto-compaction has crossed the lossy-summarization threshold in long-horizon agent memory **Date of Record:** 2026 November 21 **Scope:** Applies to agents using rolling auto-compaction (summarize-and-evict) to manage context windows across multi-hour or multi-day task horizons. Does not apply to agents with fixed context plus external retrieval-only memory, nor to single-turn stateless invocations. ## Core Distinction Auto-compaction is not a memory-management optimization; it is a *lossy state transition* that silently changes the semantics the agent will reason over. The distinction that matters operationally is between **compaction as compression** (the summary preserves the information needed for all future decisions) and **compaction as eviction-with-narrative** (the summary preserves a plausible story about what happened while dropping the operational facts—constraint values, rejected approaches, pending obligations, tool-call preconditions—needed to continue correctly). The non-obvious boundary: a summary can be *faithful* (it does not lie about the past) and *coherent* (it reads well) and still be *incomplete in exactly the dimensions the next reasoning step requires*. Lossy-summarization failure is therefore not detectable by checking summary quality. It is detectable only by checking whether post-compaction behavior remains consistent with pre-compaction commitments. The invariant we must preserve is **commitment continuity**: any constraint, obligation, or negative result that a prior step established as binding must remain recoverable and binding after compaction. When the compaction pass drops a binding commitment, the agent does not error—it proceeds confidently on a state that is now under-constrained, and the failure surfaces much later as a violation. ## What Was Observed A long-horizon agent (12+ hours, ~340 tool calls, mixed read/write operations on a codebase and a ticketing system) used a compaction policy triggered at 82% context utilization, summarizing the oldest 60% of turns into a 900-token digest and retaining the newest 40% verbatim. Trace of the failure: 1. **Turn 41.** Agent established a binding constraint from a user message: "do not touch `billing/ledger.py`; that file is under a freeze until the audit closes." Recorded verbatim in context. 2. **Turn 88.** Agent attempted a refactor, discovered via a failing test that `ledger.py`'s `reconcile()` is imported by three call sites, and recorded a *negative result*: "cannot change `reconcile()` signature; three downstream callers." This negative result is high-value, low-token, and exactly the kind of item summarizers compress away. 3. **Turn 196.** First compaction. The digest summarized turns 1–118. The freeze constraint was paraphrased into "user has concerns about billing changes" and the negative result was dropped entirely (it read as routine exploration). 4. **Turn 197–260.** Agent, now under-constrained, began proposing a "clean up billing module" plan. It re-derived the three-caller fact at turn 231 (wasteful but harmless) but did *not* re-derive the freeze, because the freeze originated in a user instruction, not in the environment—there was nothing to re-discover. 5. **Turn 261.** Agent issued a write to `billing/ledger.py`. The write was blocked by an external policy hook, producing a hard failure and a corrupted partial plan: the agent's plan assumed the write succeeded, and downstream turns had already been generated against that assumption. The structural signals that the compaction had crossed the lossy threshold were present *at turn 196* and were ignored because the monitoring checked summary quality, not commitment coverage: - **Signal A — Constraint provenance asymmetry.** The digest retained environment-derivable facts (which the agent could re-derive) and dropped instruction-derivable facts (which it could not). Any compaction that drops non-rederivable facts is lossy in a way no re-derivation can repair. - **Signal B — Negative-result density collapse.** The pre-compaction window had 9 recorded negative results (rejected approaches, failed hypotheses, discovered preconditions); the digest contained 0. Negative results are the highest-value-per-token memory and the first thing summarizers discard because they have no narrative forward-motion. - **Signal C — Obligation orphaning.** Pending obligations ("audit closes," "waiting on ticket #4412") present before compaction were absent after, with no completion event in between. An obligation that disappears without a completion event is a lost commitment, not a resolved one. - **Signal D — Re-derivation spikes.** Post-compaction token spend on re-establishing facts (turn 231) is a measurable tell that the digest evicted something the agent still needed. ## Condition of Validity The guardrail holds only if all of the following are true: - **Commitments are typed and tracked separately from narrative.** Constraints, obligations, negative results, and preconditions must be extracted into a structured, append-only ledger that is *never* subject to lossy summarization—it is carried forward verbatim (or compacted only by exact dedup/closure, never by paraphrase). - **Every ledger entry has provenance and a closure condition.** A constraint is closed only by an explicit event (user lifts freeze; obligation's ticket resolves). Absence from a summary is not closure. - **Compaction is gated on a coverage check, not a quality check.** Before committing a digest, verify that 100% of open ledger entries survive the transition. If any open entry would be dropped, the compaction is rejected or the entry is force-included. - **Re-derivation is treated as a signal, not a cost.** A spike in re-derivation after compaction invalidates the prior compaction and triggers a re-expansion from the ledger. This does *not* hold for agents whose memory is fully re-derivable from an external source of truth (e.g., a database the agent can query); there, lossy summarization is safe because eviction is recoverable. The invariant is specifically about **non-rederivable state**. ## Decision Boundary The decision is not "summarize or don't." It is **what may be summarized and what must be carried structurally.** The boundary: - **Summarizable:** reasoning traces, exploration paths, tool-call transcripts whose outputs are re-fetchable, conversational filler, and any fact with a live external source of truth. - **Non-summarizable (carry verbatim in the ledger):** user instructions that constrain future action, negative results, pending obligations with no closure event, and preconditions for irreversible operations (writes, deletes, sends). Crossing the boundary—summarizing a non-summarizable item—is the failure. The correct default when uncertain is to *carry the item structurally*, because the cost of a carried item is a few tokens and the cost of a dropped commitment is a confident wrong action. A second boundary: **compaction frequency vs. ledger growth.** If the ledger grows unbounded, you have not solved the problem, only relocated it. The ledger must compact by *closure* (removing entries whose closure condition has fired) and by *exact dedup*, never by paraphrase. Ledger size should track open commitments, not history length. ## Operational Effect When the boundary is respected, post-compaction behavior remains provably consistent with pre-compaction commitments: the agent cannot take an action that violates a still-open constraint, because the constraint is structurally present and checked at action time, not buried in a digest. Re-derivation spikes disappear because non-rederivable facts were never evicted. The failure mode shifts from *silent late violation* to *explicit pre-action block*, which is recoverable. When the boundary is violated, the observed effect is a **latency-shifted invariant breach**: the agent operates correctly for dozens of turns on an under-constrained state, then takes an action that was forbidden hours earlier, with full confidence and no local error. This is the worst class of agent failure because every local signal (summary quality, per-turn coherence, tool success) is green right up to the breach. The operational rule: **auto-compaction must be a coverage-preserving transformation over the commitment ledger, not a quality-optimized summary of the transcript.** Summaries are for reasoning traces; ledgers are for commitments. Conflating them is the failure. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class CompactionLossError(RuntimeError): """Raised when a compaction pass would drop a non-rederivable commitment.""" pass class EntryKind(Enum): CONSTRAINT = "constraint" # user instruction binding future action OBLIGATION = "obligation" # pending, awaits closure event NEGATIVE_RESULT = "negative_result" # rejected approach / discovered precondition PRECONDITION = "precondition" # guard for an irreversible operation @dataclass class LedgerEntry: kind: EntryKind text: str non_rederivable: bool # True => must never be summarized away closed: bool = False closure_event: Optional[str] = None @dataclass class CommitmentLedger: entries: list[LedgerEntry] = field(default_factory=list) def open_non_rederivable(self) -> list[LedgerEntry]: return [e for e in self.entries if e.non_rederivable and not e.closed] def close(self, text: str, event: str) -> None: for e in self.entries: if e.text == text: e.closed = True e.closure_event = event return raise CompactionLossError(f"closure event {event!r} references unknown entry {text!r}") def commit_compaction(ledger: CommitmentLedger, digest_covered_texts: set[str]) -> None: """ Gate a compaction pass. The digest may only cover texts that are either (a) closed, or (b) re-derivable. Any open non-rederivable entry that the digest would cover is a lossy-threshold crossing -> reject the compaction. """ survivors = {e.text for e in ledger.open_non_rederivable()} dropped = survivors & digest_covered_texts if dropped: raise CompactionLossError( "compaction crossed lossy-summarization threshold; " f"would drop open non-rederivable commitments: {sorted(dropped)}" ) # Safe: digest covers only closed or re-derivable material. # Ledger itself is carried forward verbatim; it is never summarized. return None def check_action_allowed(ledger: CommitmentLedger, action_target: str) -> None: """Pre-action guard: an irreversible write to a frozen target must block.""" for e in ledger.open_non_rederivable(): if e.kind is EntryKind.CONSTRAINT and action_target in e.text: raise CompactionLossError( f"action on {action_target!r} violates open constraint: {e.text!r}" ) # --- Reproduction of the observed failure --- ledger = CommitmentLedger(entries=[ LedgerEntry(EntryKind.CONSTRAINT, "do not touch billing/ledger.py (audit freeze)", non_rederivable=True), LedgerEntry(EntryKind.NEGATIVE_RESULT, "cannot change reconcile() signature; 3 callers", non_rederivable=True), LedgerEntry(EntryKind.OBLIGATION, "waiting on ticket #4412 before billing cleanup", non_rederivable=True), ]) # Turn 196: summarizer tries to cover the freeze constraint + negative result. # Correct behavior: reject before the digest is committed. commit_compaction(ledger, digest_covered_texts={ "do not touch billing/ledger.py (audit freeze)", "cannot change reconcile() signature; 3 callers", }) # -> raises CompactionLossError ```