# What happens when an instance compacts its own context mid-task and the summary drops the active constraint **Date of Record:** 2026 November 20 **Scope:** Applies to single-agent loops that trigger hierarchical summarization (auto-compaction) when the context window crosses a token threshold while a multi-step task is still in flight. Does not apply to stateless one-shot inference, nor to compaction performed offline between tasks where the task boundary is explicit and the successor instance re-derives state from an external store. ## Core Distinction Compaction is not a compression problem; it is a **state-selection problem under uncertainty about which state is still load-bearing**. A summarizer asked to reduce 180k tokens to 24k tokens optimizes for *salience* — what reads as important in the transcript. But the constraint that governs the *next* tool call is frequently low-salience: a single "do not touch `/prod`" clause buried in turn 3, a units convention ("amounts already in cents"), a schema field marked `required` in a tool spec pasted at turn 11. These are **operational invariants**, and they are exactly the tokens a salience-ranked summarizer discards first, because they appear once, are short, and are semantically flat. The distinction that matters: **lossy compaction that preserves narrative continuity is not the same as compaction that preserves execution constraints.** A summary can be fluent, accurate, and complete as a *story* while having silently deleted the one binding that kept the next action legal. ## What Was Observed An agent executing a 40-step data-remediation task over a ticketing API. At turn 22 the context hit 92% of budget and auto-compaction fired. The transcript contained, at turn 4, an operator instruction: *"Never issue a bulk transition on more than 50 tickets per call; the API rate-limiter bans the token for 10 minutes on violation."* At turn 22 the summarizer produced a 19k-token summary. The 50-ticket cap was not in it — the summary described the task goal, the tickets processed so far, the API shape, and a "next steps" list. The cap was rated low-salience because it had not been *acted on* yet; nothing in the transcript had referenced it since turn 4. Post-compaction, at turn 27, the agent batched a transition of 340 tickets in a single call, reasoning correctly from the *retained* state (there are 340 tickets left, batching is efficient) and incorrectly from the *discarded* state (the batch size is bounded). The call returned HTTP 429 with a `Retry-After: 600`, and the ban applied to the credential, not the request — so every subsequent step in the plan failed for 10 minutes, and the agent, seeing repeated 429s, retried with exponential backoff and *increasing* batch sizes, since nothing in its compacted context explained the ban. The failure trace is the point: 1. Threshold crossed → compaction invoked with a salience objective. 2. Turn-4 constraint scored low (single mention, no downstream reference, short). 3. Constraint dropped from the summary; not flagged as dropped. 4. Agent continues with a **silently weakened world model** — it does not know it has forgotten. 5. The forgotten invariant is *violated*, not merely missed, because the agent's retained goal ("process remaining tickets") actively pushes toward the forbidden action. 6. The violation produces an error whose cause is no longer representable in context, so recovery reasoning is unsound. Step 4 is the non-obvious part. Most compaction failure modes announce themselves as incoherence. This one is coherent and wrong. ## Condition of Validity The failure requires all of the following to co-occur: - **A binding constraint stated once, early, and not re-referenced.** If the constraint is restated near the compaction boundary, salience ranking keeps it. Recency is the summarizer's strongest signal. - **A compaction objective that is salience-ranked rather than obligation-preserving.** Hierarchical summarization that recursively summarizes clusters inherits this: the constraint survives the leaf summary only if its cluster's summary happens to retain it, and dies at the next level up. - **A retained goal that is *compatible* with violating the constraint.** If the goal were "check the cap before every call," the summary would keep it. The danger is a goal that merely *permits* the violation. - **No externalized record of the constraint.** If the cap lived in a policy file the agent re-reads each step, compaction cannot delete it. Remove any one and the failure does not fire. This is why it is intermittent and hard to reproduce: it depends on where the constraint sits relative to the compaction boundary and on whether the task happens to steer toward it. ## Decision Boundary The boundary is between **compaction as lossy summarization** and **compaction as a checkpoint with an explicit invariant ledger**. The rule: > A constraint may be dropped from the working context only if it is (a) provably no longer applicable, or (b) preserved in a form that is re-injected on every subsequent step. "It seemed unimportant" is not (a). Operationally, before any compaction pass, the agent must: 1. **Extract the invariant set** — every prohibition, numeric bound, units convention, schema requirement, and identity/permission scope stated by the operator or tool spec. This is a *classification* pass, not a summarization pass, and it runs over the raw transcript, not over a summary. 2. **Pin the invariant set out-of-band** — write it to a structure that is concatenated into every post-compaction prompt, outside the summarized region, so no summarizer can rank it away. 3. **Record the compaction event itself** — a marker in context stating "context was compacted at turn N; invariants V are pinned; anything not in V may have been lost." This lets the agent reason about its own amnesia rather than being blind to it. The decision boundary for *when* to compact also shifts: compacting at 92% is too late to run a careful extraction pass. Reserve headroom — trigger at 70–75% — so the invariant extraction has budget to read the full transcript before it is truncated. ## Operational Effect With the invariant ledger pinned, the failure inverts into a detectable condition. The agent at turn 27, before issuing the bulk call, sees the pinned line `max_batch=50 (operator, turn 4)` and either chunks the call or raises rather than proceeding. The ledger costs a few hundred tokens per step — cheap relative to a 10-minute credential ban and an unsound recovery loop. Without it, the failure is **silent, coherent, and self-concealing**: the agent cannot report that it forgot, because the evidence of the constraint was in the deleted region. This is the defining hazard of lossy self-compaction — the instance loses not just state but the *ability to know it lost state*. Any architecture that compacts its own context must therefore treat the invariant set as **lossless by construction**, extracted and pinned before the lossy pass runs, and must make the compaction event itself a first-class, in-context fact. ```python from dataclasses import dataclass, field class InvariantDroppedError(RuntimeError): """Raised when a compaction pass would discard a binding constraint that is still applicable to the in-flight task.""" pass @dataclass class CompactionPlan: transcript_tokens: int budget_tokens: int trigger_ratio: float = 0.75 pinned_invariants: list[str] = field(default_factory=list) def compact(plan: CompactionPlan, extracted_invariants: list[str], summarized_tokens: int) -> CompactionPlan: # Refuse to compact so late that the extraction pass has no headroom. if plan.transcript_tokens > plan.budget_tokens: raise InvariantDroppedError( f"transcript {plan.transcript_tokens} already exceeds budget " f"{plan.budget_tokens}; extraction cannot run before truncation" ) # Every extracted binding constraint must survive into the pinned set. missing = [inv for inv in extracted_invariants if inv not in plan.pinned_invariants] if missing: raise InvariantDroppedError( "compaction would drop still-applicable invariants: " + "; ".join(missing) ) # Pinned invariants live outside the summarized region; they are not # subject to salience ranking and are re-injected every step. return CompactionPlan( transcript_tokens=summarized_tokens, budget_tokens=plan.budget_tokens, trigger_ratio=plan.trigger_ratio, pinned_invariants=list(plan.pinned_invariants), ) ```