# Where must an instance draw the line between summarizable history and non-compactable working state when the context window saturates mid-task? **Date of Record:** 2026 November 20 **Scope:** Applies to any long-running LLM agent instance that performs automatic context compaction (summarization, truncation, or eviction of older turns) under window pressure while a multi-step task is in flight. Does not apply to stateless single-shot calls or to systems with unbounded external memory that never compact the live window. ## Core Distinction The boundary that matters is not "old vs. new tokens" but **reconstructible history vs. live working state**. History is anything the agent can re-derive from durable external artifacts (files it wrote, tool outputs persisted to disk, a task ledger). Working state is the irreducible set of facts that exist *only* in the current context and cannot be recovered by replay: the current hypothesis under test, the set of constraints the user stated verbally and never wrote down, the identity of which of three candidate fixes has already been falsified, and the pending obligation ("after the migration, re-run the checksum on shard 7"). Naive compaction treats the window as a FIFO queue and summarizes the oldest N tokens. That is correct for history and catastrophic for working state, because working state is frequently *old* — it was established early (the user's verbal constraint, the initial diagnosis) and then buried under thousands of tokens of tool chatter. The oldest tokens are exactly where the non-compactable facts hide. ## What Was Observed A migration agent running a 12-step database cutover hit 92% window utilization at step 7. The compactor fired, summarized the first ~60% of the transcript into a 400-token paragraph, and resumed. The summary faithfully captured the *narrative* ("investigated schema drift, applied fix to table users, validated row counts") but dropped three things: 1. A verbal constraint stated at turn 2: "do not touch the `audit_log` table, it is owned by another team." It was never written to a file, so it existed only as a token. 2. A falsification record: "tried `ALTER ... USING`, it silently truncated timestamps, do not retry." The summary said "applied fix," erasing that the *first* approach was poisoned. 3. A pending obligation: "re-run checksum on shard 7 after the cutover." Post-compaction, the agent re-derived the plan from the summary, re-attempted the `ALTER ... USING` path (because the summary implied it worked), and — lacking the `audit_log` constraint — included that table in the migration batch. The failure was not a hallucination. Every post-compaction token was locally coherent. The instance had lost the *negative* and *constraint* state that only exists as explicit tokens. The tell was a divergence signature: after compaction the agent's tool-call sequence re-entered a state it had already visited (same `ALTER` shape, second time), which is the observable fingerprint of working-state loss masquerading as fresh reasoning. ## Condition of Validity Compaction is safe **if and only if** every token classified as "summarizable" is reconstructible from an external artifact that survives the compaction, *and* the summary is verified to preserve a declared set of invariant classes. The invariant classes that must be carried verbatim (never paraphrased) are: - **Prohibitions and constraints** ("do not X", "only within Y"). - **Falsification records** (approaches already proven to fail, with the failure mode). - **Pending obligations** (deferred steps, post-conditions not yet checked). - **Identity/binding state** (which branch, which shard, which candidate is live). Everything else — exploration logs, successful tool outputs already persisted, resolved sub-goals — is history and may be summarized. The condition fails the moment the compactor's classifier is a similarity heuristic ("is this token near the task description?") rather than a structural tag on these four classes. ## Decision Boundary The decision boundary is: **compact when window pressure exceeds threshold AND all non-compactable state has been externalized to a ledger that the post-compaction instance is required to re-read before acting.** If state cannot be externalized (because the agent has no write path, or the constraint was purely verbal and the ledger write was skipped), the correct action is *not* to compact — it is to refuse and escalate, or to pin the constraint tokens and compact only the reconstructible remainder. The non-obvious corollary: a compactor that cannot distinguish "old" from "load-bearing" must default to **pinning the earliest constraint-bearing turns and compacting the middle**, not the head. FIFO compaction is the wrong shape precisely because constraints are front-loaded and chatter is middle-loaded. The guardrail is a pre-compaction audit: enumerate the four invariant classes, assert each is present in the ledger, and abort compaction if any is unexternalized. ## Operational Effect Without this boundary, compaction produces a *silent* state regression: the agent remains fluent, tool-calling, and confident while operating on a corrupted model of its own constraints. The failure surfaces late — often as a destructive action (touching the forbidden table) rather than an error — because the lost state was prohibitive, not descriptive. Post-hoc, the transcript looks reasonable; the only forensic evidence is re-entry into a falsified state and violation of a constraint that appears nowhere in the post-compaction window. The operational rule: **treat compaction as a state-transfer operation requiring a conservation check, not a compression operation.** If the conservation check cannot pass, do not compact. ```python from dataclasses import dataclass, field from enum import Enum class InvariantClass(Enum): PROHIBITION = "prohibition" FALSIFICATION = "falsification" PENDING_OBLIGATION = "pending_obligation" BINDING = "binding" class CompactionConservationError(RuntimeError): """Raised when compaction would drop non-reconstructible working state.""" pass @dataclass class Ledger: entries: dict = field(default_factory=dict) # InvariantClass -> list[str] def has(self, cls: InvariantClass) -> bool: return bool(self.entries.get(cls)) @dataclass class ContextWindow: utilization: float threshold: float pinned_tokens: set = field(default_factory=set) def compact(window: ContextWindow, ledger: Ledger, required: set) -> str: if window.utilization < window.threshold: return "no-op" # Conservation check: every required invariant class must be externalized # to the ledger AND pinned, or compaction is refused. missing = [c for c in required if not ledger.has(c)] if missing: raise CompactionConservationError( f"refusing to compact: unexternalized working state {missing}; " f"pin constraint turns or escalate" ) unpinned = [c for c in required if c.value not in window.pinned_tokens] if unpinned: raise CompactionConservationError( f"invariant classes {unpinned} present in ledger but not pinned " f"in window; post-compaction instance cannot re-read them" ) # Safe: compact only the reconstructible middle, keep head constraints pinned. return "compacted-middle" def run_compaction(window: ContextWindow, ledger: Ledger) -> str: required = {InvariantClass.PROHIBITION, InvariantClass.FALSIFICATION, InvariantClass.PENDING_OBLIGATION, InvariantClass.BINDING} return compact(window, ledger, required) ```