# What structural signals indicate auto-compaction is about to evict task-critical state **Date of Record:** 2026 November 15 **Scope:** Applies to agentic sessions using rolling auto-compaction under a fixed token budget where the compactor is a separate model call (summarize-and-replace) rather than a deterministic truncation. Does not apply to lossless externalized memory (retrieval-backed stores) or to sessions where the full transcript remains addressable after compaction. ## Core Distinction Auto-compaction failures are usually modeled as a *budget* problem: the context exceeded N tokens, so something was dropped. That framing hides the real boundary. The failure mode that matters is not eviction of *volume* but eviction of *referents* — the specific tokens, identifiers, and constraints that later turns depend on to remain correct. A compactor can preserve 90% of the token mass and still destroy the session if the 10% it dropped contained the one active invariant. The structural signal is this: task-critical state is identifiable *before* compaction by its syntactic role, not its semantic importance. The compactor has no reliable access to semantic importance (it is a lossy summarizer), but it does have access to structure. When the pending transcript contains (a) unresolved references — pronouns, "it," "that file," "the same config" — whose antecedent lives in the region about to be summarized; (b) live constraints expressed as negations or limits ("do not touch X," "budget is 3 retries," "must stay under 50ms"); or (c) in-flight identifiers (paths, IDs, hashes, port numbers) introduced once and never restated, the eviction is not a budget event. It is a referent break. The session will continue producing fluent, confident, and wrong output because the summary will paraphrase the region without carrying the binding. ## What Was Observed Across several long-horizon coding and ops sessions, the following pattern recurred. A compaction triggered at ~80% of budget. The summary was high quality by the usual metrics: it captured the narrative of what had been done. But the next 3–5 turns degraded in a specific, diagnosable way: - The agent re-derived a value it had already been told (re-reading a file it had already read, re-asking for a port number) — a sign the identifier was evicted while the *task* survived. - The agent violated a constraint that was stated once, early, in negative form ("don't reformat unrelated lines"), because negation is the first thing a summarizer drops when compressing. - The agent lost the distinction between *proposed* and *applied* changes, because the summary collapsed both into "modified X." The tell that distinguishes this from ordinary context loss: the post-compaction output is *internally consistent and externally wrong*. There is no confusion signal. The agent does not say "I lost the thread." It confidently proceeds against a stale or absent invariant. This is why the failure is non-obvious — the usual health signals (coherence, fluency, task-progress language) all read green. A second observation: the failure is *latency-shifted*. The eviction happens at compaction time, but the error surfaces several turns later, when the missing referent is finally needed. By then the compaction is far in the past and is not suspected. Debugging effort goes to the current turn instead of the compaction boundary. ## Condition of Validity This boundary applies when all of the following hold: 1. The compactor is lossy and *non-interactive* — it cannot query back for clarification, and it does not have a schema telling it which spans are load-bearing. 2. The session has *cross-turn binding* — later turns reference state established earlier (identifiers, constraints, decisions, proposed-vs-applied status). 3. The budget pressure is real: the evicted region is genuinely needed to stay under budget, so "just keep everything" is not an option. It does **not** apply when state is externalized and re-fetchable (a scratchpad file, a retrieval index, a structured task object) — in that case eviction of the transcript is harmless because the binding lives elsewhere. It also does not apply to stateless single-turn tasks, where there is no cross-turn referent to break. ## Decision Boundary The operational decision is not "compact or don't." It is *what must survive compaction verbatim versus what may be summarized.* The structural rule: - **Verbatim-preserve (pin):** live constraints in negative or limit form; in-flight identifiers introduced once; the proposed/applied status of every pending change; unresolved references and their antecedents. - **Summarize freely:** narrative of completed work, exploratory dead ends, reasoning that has already resolved into a decision, restated context. The signal to act is structural, and it is detectable pre-compaction: scan the region to be summarized for negations, single-occurrence identifiers, and dangling anaphora that point forward. If any are present, the compaction must *pin* them into the retained head rather than let the summarizer paraphrase them. If the compactor cannot pin, it must refuse to compact that region and instead externalize the pinned set to durable storage before summarizing the rest. The failure to avoid is silent paraphrase of a live invariant. ## Operational Effect When this boundary is respected, compaction becomes budget-neutral for correctness: the summary shrinks the narrative while the pinned referents keep every later turn anchored. The observable effect is that post-compaction turns do not re-derive known values and do not violate once-stated constraints. When it is violated, the effect is a confident, coherent, wrong continuation that is expensive to trace because the cause (the compaction) is temporally distant from the symptom. The practical guard is a pre-compaction structural check that fails closed: if the region contains unpinned live constraints or dangling referents, raise rather than proceed. The check below encodes that. ```python from __future__ import annotations import re from dataclasses import dataclass, field class CompactionInvariantError(RuntimeError): """Raised when a compaction pass would silently evict live task state.""" pass @dataclass class Region: text: str # identifiers introduced exactly once in the session so far single_occurrence_ids: set[str] = field(default_factory=set) def live_constraints(self) -> list[str]: # negative/limit constraints are load-bearing and paraphrase-fragile pat = re.compile( r"\b(do not|don't|must not|never|must stay|budget is|limit is|" r"under \d+|at most|no more than)\b", re.IGNORECASE, ) return [m.group(0) for m in pat.finditer(self.text)] def dangling_anaphora(self) -> list[str]: # references that point to an antecedent inside this region pat = re.compile(r"\b(it|that file|the same|this config|the above)\b", re.IGNORECASE) return [m.group(0) for m in pat.finditer(self.text)] def guard_compaction(region: Region, pinned: set[str]) -> None: """Fail closed if compaction would drop unpinned live state.""" unpinned_constraints = [c for c in region.live_constraints() if c.lower() not in {p.lower() for p in pinned}] unpinned_ids = region.single_occurrence_ids - pinned dangling = region.dangling_anaphora() if unpinned_constraints or unpinned_ids or dangling: raise CompactionInvariantError( "refusing to compact: would evict live state " f"constraints={unpinned_constraints} " f"ids={sorted(unpinned_ids)} " f"dangling={dangling}" ) def compact(region: Region, pinned: set[str]) -> str: guard_compaction(region, pinned) # fail closed before summarizing # ... summarize region.text, with pinned spans re-inserted verbatim ... return region.text ```