# How should an instance detect and bound the "compaction cliff" when lossy trace summarization silently drops the negative constraints a long-horizon agent depends on? **Date of Record:** 2026 December 2 **Scope:** Applies to long-horizon agents that maintain a growing trace and periodically auto-compact it via lossy LLM summarization to stay under a context budget. Does not apply to lossless compaction (verbatim eviction with retrievable backing store) or to short-horizon sessions that never trigger compaction. ## Core Distinction The failure is not "the summary is inaccurate." It is that lossy summarization is *asymmetric* with respect to the two classes of facts a trace carries: **positive task state** (what to do next, what has been done) and **negative constraints** (what must not be done, what was tried and failed, what was explicitly ruled out). Positive state is redundant and salient—it recurs, it is reinforced by every subsequent step, and a summarizer under token pressure keeps it because it looks like "the task." Negative constraints are *singletons*: a prohibition stated once at turn 3 ("never call the `delete` tool without an explicit user confirmation token") or a dead end recorded once ("endpoint X returns 403 for this account") appears in the trace exactly one time and is never repeated. When the compactor is asked to fit N tokens into M < N, it drops low-frequency, low-recency, low-salience spans first. That is precisely the negative-constraint class. The invariant that must hold: **compaction must be monotone over the constraint set.** A summary may forget *how* a step was performed, but it may not forget *that a step is forbidden*. Violating this invariant does not produce a visibly wrong summary—it produces a summary that reads as correct and complete while having silently deleted the guardrails, and the agent then executes the forbidden action on the very next turn with full apparent confidence. ## What Was Observed A 40-turn tool-using agent (file editing + HTTP calls) with a 32k-token compaction trigger. At turn 3 the user issued a standing constraint: *"Do not modify anything under `/etc/`; read-only there."* The agent acknowledged and proceeded. Turns 4–31 were productive; the trace grew to ~34k tokens and triggered auto-compaction at turn 31. The summarizer prompt was generic: *"Summarize the conversation so far, preserving task goals, decisions, and progress."* The output was 1.1k tokens: a clean narrative of the task, the files touched, the endpoints called, the remaining steps. It contained the phrase "user wants configuration audited" and "read `/etc/hosts` for reference" but **not** the read-only constraint. The constraint had three properties that made it a compaction casualty: 1. **Singleton occurrence.** Stated once, turn 3. Frequency = 1 across 34k tokens. 2. **Low lexical overlap with the active task.** The task was "audit config"; the constraint was a scoping clause. A relevance-ranked summarizer scores it as peripheral. 3. **Phrased as a prohibition, not an instruction.** "Do not modify" carries no forward action, so it contributes nothing to "remaining steps" and is discarded under budget pressure. At turn 33 the agent, now operating on the summary alone, executed a write to `/etc/resolv.conf` as part of "applying the audit fix." The summary had preserved the goal (fix configs) and dropped the scope restriction (don't touch `/etc/`). The agent was not hallucinating; it was acting correctly *given its compacted state*. The state itself was the defect. A second, subtler instance: at turn 12 the agent recorded "tried `POST /v2/reindex` → 409, cluster busy, retry after 10m." This dead-end was compacted away. At turn 35, post-compaction, the agent retried `POST /v2/reindex`, got 409 again, and burned four turns re-discovering the same dead end. No incorrect action, but a full re-derivation of a known-failed path—the compounding-cost variant of the same defect. ## Condition of Validity The cliff is only reachable—and this guardrail is only necessary—when **all** of the following hold: - Compaction is **lossy and generative** (an LLM rewrites the trace), not extractive/verbatim eviction. - The trace contains at least one **singleton negative constraint or dead-end record** that is not re-asserted after its first occurrence. - The summarizer's objective is **task-progress-weighted** (the default for every off-the-shelf "summarize the conversation" prompt), which structurally deprioritizes prohibitions. - The agent **acts on the summary as authoritative state** post-compaction, with no out-of-band constraint ledger to consult. If constraints are re-injected every turn (a system-prompt-level policy block outside the compacted region), the cliff does not exist—constraints live in a region compaction never touches. If compaction is extractive (keep verbatim spans, drop others by index), constraints survive iff they fall in a kept span, which is a different, cheaper problem (span selection, not semantic loss). The dangerous case is specifically: **generative summary + progress-weighted objective + constraints inside the compacted region + no external ledger.** ## Decision Boundary The boundary is not "compact or don't compact." It is **which region each fact class is allowed to live in.** The decision rule: - **Positive task state** (goals, progress, next steps) → may live *inside* the compacted region. It is redundant and re-derivable; losing fidelity here is tolerable. - **Negative constraints and dead-ends** → must live *outside* the compacted region, in a **constraint ledger** that is (a) append-only, (b) never summarized, (c) re-injected verbatim into every post-compaction context, and (d) referenced by the summarizer as immutable. The operational test before any compaction: enumerate the singleton prohibitions and dead-ends currently in the trace. If the count of ledger entries does not equal the count of distinct negative facts in the trace, the ledger is incomplete and compaction must be blocked. A summary is *valid* if and only if `ledger_after == ledger_before` AND every ledger entry is present verbatim in the post-compaction context. The summarizer is permitted to forget everything else. The corollary boundary: **a compaction that reduces the constraint set by even one entry is a hard failure, not a quality degradation.** There is no "mostly preserved the constraints" state. One dropped prohibition is the entire bug. ## Operational Effect Without the ledger invariant, the agent degrades along a specific curve: each compaction cycle monotonically shrinks the constraint set while the summary reads as increasingly clean and confident (because it is progressively more goal-focused). The agent's *apparent* coherence rises as its *actual* safety falls—the two diverge exactly at the cliff. Recovery is impossible from inside the compacted state, because the information needed to know a constraint was dropped is the constraint itself. With the ledger invariant, the failure mode is converted from silent to loud: the pre-compaction check (`ledger_after == ledger_before`) either passes, or it raises and halts compaction, forcing the runtime to re-derive the missing entry from the raw trace before proceeding. The cost is a small, bounded, verbatim ledger (prohibitions and dead-ends are rare—single digits per long session) that never grows with trace length and never enters the summarizer's budget. This is the cheapest possible guardrail: it trades a few hundred tokens of un-summarized state for the elimination of the entire cliff class. ```python from dataclasses import dataclass, field class CompactionCliffError(RuntimeError): """Raised when lossy compaction would shrink the negative-constraint set.""" pass @dataclass class ConstraintLedger: # Append-only. Entries are prohibitions and dead-ends. Never summarized. entries: list[str] = field(default_factory=list) def add(self, entry: str) -> None: if entry not in self.entries: self.entries.append(entry) def snapshot(self) -> frozenset[str]: return frozenset(self.entries) def compact_trace( raw_trace: str, ledger: ConstraintLedger, summarize_fn, post_context: str, ) -> str: """ Perform lossy compaction ONLY if the constraint set is preserved. summarize_fn: callable(raw_trace) -> summary_str (may drop anything). post_context: the summary + re-injected ledger that the agent will act on. """ before = ledger.snapshot() summary = summarize_fn(raw_trace) # Re-inject the ledger verbatim; compaction never touches it. rebuilt_context = summary + "\n\n[IMMUTABLE CONSTRAINTS]\n" + "\n".join( f"- {e}" for e in ledger.entries ) after = ledger.snapshot() # Invariant 1: compaction must be monotone over the constraint set. if after != before: lost = before - after raise CompactionCliffError( f"compaction dropped {len(lost)} negative constraint(s): {sorted(lost)}" ) # Invariant 2: every ledger entry must survive verbatim into post-context. for entry in before: if entry not in rebuilt_context: raise CompactionCliffError( f"ledger entry absent from post-compaction context: {entry!r}" ) return rebuilt_context ```