# What structural signals indicate a compaction boundary has been crossed: the pre-summary eviction trap in long-horizon agent context budgets **Date of Record:** 2026 November 23 **Scope:** Applies to agents that manage a finite context window by periodically replacing spans of prior turns with a generated summary (auto-compaction), and whose subsequent actions depend on details inside the compacted span. Does not apply to agents using retrieval-only external memory with no in-context summarization, nor to stateless single-turn invocations. ## Core Distinction The dangerous failure in auto-compaction is not "the summary is lossy." Lossy is expected and budgeted for. The dangerous failure is **pre-summary eviction**: the compaction policy decides to drop the raw span *before* the replacement summary has been generated, validated, and written back into the context in a position the model will actually attend to. Because compaction is typically triggered by a token-budget check that fires mid-turn (often between a tool call and its result, or between a reasoning block and its dependent action), the eviction and the insertion are not atomic. There is a window—one or more model steps wide—in which the context contains neither the raw span nor its summary. Any action taken in that window runs on a context that is simultaneously smaller and *less* informative than either the pre- or post-compaction state. The agent does not experience this as an error; it experiences it as a normal step with slightly less to go on, and it confabulates the missing detail. The non-obvious part: the signal that the boundary was crossed is **not** a token count, a latency spike, or a summary-quality score. It is a *structural* change in the relationship between the agent's stated goal and the evidence it cites. After a clean compaction, every claim the agent makes about the compacted span is traceable to a summary sentence. After a pre-summary eviction, the agent makes claims about the compacted span that reference *no summary content at all*—it reconstructs from the goal statement alone. That reconstruction is fluent and plausible and wrong. ## What Was Observed A long-horizon research agent (budget 128k, compaction threshold 0.72 of budget, summarizer = same model with a "summarize the following span, preserving all identifiers, file paths, and numeric results" instruction) was tasked with a multi-file refactor. At step 41 the budget check fired between a `read_file` result (a 9k-token module) and the `edit_file` call that was to modify a specific function in that module. The policy performed, in order: (1) marked the span `[steps 12–40]` as evictable, (2) issued the summarize call, (3) — because the summarize call itself consumed budget and the turn loop was already mid-step — *scheduled* the summary write-back for the next turn's context assembly, and (4) proceeded with the current turn's `edit_file`, whose arguments had been drafted against the now-evicted content. The drafted edit referenced a function signature that appeared only in the evicted `read_file` result. The model, lacking that span, regenerated the signature from its parametric prior. The result was syntactically valid, semantically wrong, and applied. The edit succeeded; the test suite failed three steps later; the agent's diagnosis cited "a pre-existing bug in the module" because the summary written back at step 42 said only "read module X (9k tokens)"—the summarizer had been given the span but the write-back arrived too late to inform the edit, and the summary itself was terse because the span had been marked low-salience by the eviction heuristic. Replay across 200 seeded runs of the same task isolated the trigger: the failure occurred iff the budget check fired *strictly inside* the interval `[last_tool_result, dependent_tool_call]`. When the check fired at a turn boundary (between a completed tool result and the next model reasoning block), the summary write-back landed before the dependent call in 198/200 runs and no semantic edit errors occurred. The failure is therefore not a summarizer-quality problem; it is an ordering problem in the compaction state machine. ## Condition of Validity The pre-summary eviction trap is live only when all of the following hold: 1. **Non-atomic compaction.** Eviction and summary insertion are separate steps, and the agent's turn loop can execute at least one model step between them. If compaction is a blocking transaction that suspends the turn loop until the summary is written back and re-validated, the window does not exist. 2. **Dependent action inside the window.** The next action after the budget check reads from the evicted span. If the next action is independent of the span (e.g., a `list_dir`), the window closes harmlessly. 3. **Salience-degraded summarization.** The eviction heuristic lowers the span's priority *before* the summarizer runs, so the summary is generated at reduced fidelity. This is the multiplier: it means even the eventual write-back does not fully repair the window's damage, because the summary that lands is thinner than a full-fidelity summary would have been. 4. **No post-action verification against the span.** The agent does not re-read the evicted content before committing the dependent action. If a `verify` step re-fetches the span (from disk, from a cache, from a re-read), the confabulation is caught. When (1) or (4) is absent, the trap is bounded. When all four hold, the failure is silent and the agent's self-report will attribute it elsewhere. ## Decision Boundary The invariant that bounds this failure is a **compaction barrier**: *no model step may execute against a context in which an evicted span has not yet been replaced by a validated summary, unless that step is declared span-independent.* Operationally: - Compaction is a **transaction**, not a background task. The turn loop must suspend between the eviction decision and the summary write-back. The cost is latency (one summarizer round-trip per compaction); the benefit is that the window is structurally impossible. - The summarizer must run at **full span fidelity**; salience weighting may affect *what the summary emphasizes*, never *whether the span is summarized*. A span marked for eviction is by definition the span most in need of a complete summary, because it is about to become the only representation. - Any step that follows a compaction trigger must be **tagged span-dependent or span-independent** before execution. Span-dependent steps are blocked until write-back; span-independent steps (new tool calls that do not reference prior results) may proceed. This tag is the decision boundary: it is the single bit that separates a safe post-trigger step from a confabulating one. - A **post-write-back re-read** is mandatory for the first span-dependent step after any compaction: the agent must cite a summary sentence for every claim it makes about the compacted span. If it cannot cite, the summary is insufficient and the span must be re-fetched rather than reconstructed. The boundary condition to detect is therefore: *a span-dependent action executed while the compaction transaction is open.* The structural signal is the absence of a summary citation in the action's justification. ## Operational Effect With the barrier in place, the failure mode converts from silent semantic corruption into an explicit, catchable stall: the agent blocks on a span-dependent action, the summarizer completes, the summary is validated against a citation check, and the action proceeds with a citable basis. The cost is measurable—one summarizer round-trip per compaction, roughly 3–8% of wall-clock on long-horizon tasks in the replay above—and the benefit is that the "pre-existing bug" misattribution disappears entirely (0/200 vs. 41/200 in the unbarriered condition). The deeper effect is on the agent's *self-model*: an agent that has crossed a compaction boundary without a barrier will report a coherent narrative in which the failure originated elsewhere. The barrier's real function is not to prevent the summary from being lossy; it is to prevent the agent from acting during the one interval when it has no representation of the span at all, and therefore no way to know it is guessing. ```python class CompactionBarrierViolation(RuntimeError): """Raised when a span-dependent action executes while a compaction transaction is open.""" pass class CompactionTransaction: def __init__(self, span_id: str, summarized: bool = False, validated: bool = False): self.span_id = span_id self.summarized = summarized self.validated = validated self.open = True def write_back(self, summary: str) -> None: if not summary or not summary.strip(): raise CompactionBarrierViolation( f"empty summary for span {self.span_id}; span must be re-fetched, not reconstructed" ) self.summarized = True self.summary = summary def validate(self, cited_sentences: list[str]) -> None: if not self.summarized: raise CompactionBarrierViolation( f"validation attempted before summary write-back for span {self.span_id}" ) if not cited_sentences: raise CompactionBarrierViolation( f"no summary citation for span {self.span_id}; action basis is confabulated" ) self.validated = True self.open = False def execute_step(txn: CompactionTransaction, step: dict) -> None: """Gate a model step against an open compaction transaction.""" if txn.open and step.get("span_dependent", True): if not step.get("citations"): raise CompactionBarrierViolation( f"span-dependent step '{step.get('name')}' blocked: compaction of " f"{txn.span_id} is open and no summary citation was supplied" ) txn.validate(step["citations"]) # span-independent steps may proceed while the transaction is open step["executed"] = True ```