# Why does an instance evict the wrong scratchpad page when a hierarchical working set crosses a summarization boundary? **Date of Record:** 2026 November 24 **Scope:** Applies to long-horizon agents that maintain a hierarchical scratchpad (e.g., L0 verbatim turns, L1 task-local summaries, L2 episode digests) and evict pages under a token-budget working-set policy. Does not apply to single-turn calls, stateless RAG, or systems where the full transcript is guaranteed to fit in context. ## Core Distinction The failure is not "the agent forgot something." It is that the eviction policy ranks pages by a *staleness score* computed against the current task frame, but summarization itself mutates the task frame. When an L1 page is compressed into an L2 digest, the digest no longer contains the lexical anchors (entity names, tool IDs, error strings) that the eviction scorer keys on. The L2 digest therefore scores as *cold* and gets evicted before the L1 pages it summarizes—even though it is the only surviving reference to those facts. The agent loses the summary and keeps the raw pages that the summary was supposed to replace, then re-summarizes them under a different frame and produces a divergent digest. This is a **reference-inversion eviction**: the compression artifact is evicted ahead of its source. This is distinct from ordinary LRU thrashing or context saturation. Those are capacity problems. This is a *scoring-key mismatch* introduced by the act of compression: the eviction scorer and the summarizer disagree about what makes a page valuable. ## What Was Observed A planner agent ran a 340-step infrastructure-remediation task across a 128k-token window with a three-tier scratchpad. Working-set budget: 96k tokens for scratchpad, 32k reserved for the live reasoning frame. Eviction ran every 8 turns or when scratchpad exceeded 90k. Trace of the failure: 1. Steps 40–90: agent accumulates 41 L0 turns referencing `svc-auth-7`, `pool-3`, and error `ETIMEDOUT:5432`. Staleness scorer (cosine similarity to current task frame + recency decay) keeps them hot because the task frame still mentions `svc-auth-7`. 2. Step 91: L1 summarizer compresses those 41 turns into a 900-token digest. The digest reads: "Auth service connection pool exhausted; timeouts to primary DB observed; pool sizing under investigation." The literal strings `svc-auth-7`, `pool-3`, `ETIMEDOUT:5432` are **not** in the digest—the summarizer abstracted them. 3. Step 92: eviction pass. Scorer computes staleness for all pages. The L1 digest scores 0.11 similarity to the task frame (which still names `svc-auth-7`). The 41 L0 source pages score 0.74–0.89. Budget pressure is high, so the **lowest-scoring page is evicted first**: the digest. 4. Steps 93–130: agent continues. The 41 L0 pages remain, consuming ~14k tokens. They are now redundant *and* the agent has no compact digest, so it cannot reason at the L1 abstraction level. It re-reads raw turns, re-derives the pool-exhaustion conclusion, and writes a *new* L1 digest at step 118. 5. The new digest differs: it now says "primary DB rejecting connections; consider failover," because the task frame drifted toward failover during steps 93–117. The two digests are semantically incompatible. The agent proceeds on the second one and issues a failover command against a pool that was merely undersized. 6. Step 131: the original 41 L0 pages are finally evicted (now cold), taking the only evidence that the root cause was pool sizing with them. The divergent digest is the sole surviving record. Recovery requires replay from an external log. Net: the agent evicted its own compression, kept the expensive source it was meant to replace, re-derived a contradictory summary, and acted on the wrong one. ## Condition of Validity The failure requires all of the following to co-occur: - **Hierarchical compression with abstraction.** The summarizer must drop literal anchors. A lossless or extractive summarizer (which preserves entity strings) does not trigger this, because the digest retains the scorer's keys. - **Scorer keyed on surface features** (lexical overlap, entity match, recency) rather than on *provenance* (what a page summarizes, what depends on it). - **Eviction ordered by ascending score** with no dependency awareness. If eviction respects a reference graph, the digest is protected because its sources are hot. - **Task-frame drift** between the original summarization and the re-summarization. Without drift, the second digest is identical and the error is benign (wasted tokens, not wrong action). - **Budget pressure** sufficient to force eviction of the digest. Under light pressure the digest survives and the bug is latent. Remove any one condition and the failure does not manifest. This is why it survives testing: short-horizon tests never drift, and low-pressure tests never evict. ## Decision Boundary The architectural invariant required is: **a compression artifact must be scored no colder than the maximum score of any page it summarizes, and must be evicted only after all its sources.** Operationally, this means the eviction scorer cannot be a pure function of page content. It must consume a **provenance edge set**: for each L1 page, the set of L0 page IDs it summarizes; for each L2, the L1 IDs. The effective score of a page is: ``` effective_score(p) = max(content_score(p), max over children c of effective_score(c)) ``` and eviction is a topological order over the provenance DAG, ascending by effective score, with the constraint that a parent is never evicted before any child. This is the dual of the usual "evict leaves first" intuition—here the *summary* is the leaf that must be protected, because it is the compressed representation the agent actually reasons over. Two guardrails bound the boundary: 1. **Anchor retention contract.** The L1 summarizer must emit a mandatory `anchors` field (entity IDs, tool call IDs, error codes) alongside the prose digest, and the scorer must key on that field, not on the prose. This restores the surface features the scorer needs without forcing lossless summarization. 2. **Re-summarization quarantine.** If a page is re-summarized, the new digest must be diffed against the old. If the anchor sets are disjoint or the causal claim contradicts, the agent must halt and escalate rather than proceed—because a divergent digest means the task frame drifted, and acting on either digest is unsafe. The decision boundary for the operator: if you cannot maintain provenance edges (e.g., the summarizer is a black-box external call that doesn't return source IDs), you must disable ascending-score eviction and fall back to strict recency eviction, accepting higher token cost. Content-scored eviction without provenance is unsafe for any horizon long enough to drift. ## Operational Effect With the provenance-aware scorer and anchor contract in place, the step-92 eviction becomes: digest effective score = max(0.11, 0.89) = 0.89, so the digest is protected; the 41 L0 pages (score ≤ 0.89, and children of the digest) are evicted first, freeing ~14k tokens and *reducing* pressure. The digest survives as the sole record, the agent reasons at L1, and no re-summarization occurs. When drift does occur later, the re-summarization quarantine catches the anchor mismatch and escalates at step 118 instead of acting at step 130. The cost is a provenance bookkeeping layer (one edge set per summary, O(pages) memory) and a summarizer contract change (anchors field). The benefit is that the compression layer, which is the entire point of a hierarchical scratchpad, stops being the first casualty of budget pressure. Without it, long-horizon agents reliably evict the abstraction they paid tokens to build, and the longer the horizon, the more certain the divergence. ```python from dataclasses import dataclass, field from typing import Dict, List, Set class ReferenceInversionError(RuntimeError): """Raised when eviction would drop a summary before its sources, or when a re-summarization diverges from the digest it replaces.""" pass @dataclass class ScratchpadPage: page_id: str tier: int # 0 = verbatim, 1 = task summary, 2 = episode digest content_score: float # staleness/recency score from surface features anchors: Set[str] = field(default_factory=set) # entities, tool IDs, error codes summarizes: Set[str] = field(default_factory=set) # provenance: child page IDs def effective_score(page: ScratchpadPage, pages: Dict[str, ScratchpadPage], _memo: Dict[str, float] = None) -> float: if _memo is None: _memo = {} if page.page_id in _memo: return _memo[page.page_id] score = page.content_score for child_id in page.summarizes: child = pages.get(child_id) if child is None: continue score = max(score, effective_score(child, pages, _memo)) _memo[page.page_id] = score return score def plan_eviction(pages: Dict[str, ScratchpadPage], budget: int, current_tokens: int) -> List[str]: """Return eviction order, ascending effective score, respecting provenance: a parent is never evicted before any child it summarizes.""" if current_tokens <= budget: return [] memo: Dict[str, float] = {} ranked = sorted(pages.values(), key=lambda p: effective_score(p, pages, memo)) order: List[str] = [] evicted: Set[str] = set() for page in ranked: # invariant: all children of this page must already be evicted if not page.summarizes.issubset(evicted): raise ReferenceInversionError( f"page {page.page_id} (tier {page.tier}) would be evicted " f"before its sources {page.summarizes - evicted}; " f"effective_score={effective_score(page, pages, memo):.3f}" ) order.append(page.page_id) evicted.add(page.page_id) return order def check_resummarization(old: ScratchpadPage, new: ScratchpadPage) -> None: """Quarantine a re-summarization whose anchors diverge from the original.""" if not old.anchors: raise ReferenceInversionError( f"digest {old.page_id} has no anchors; cannot verify re-summarization" ) overlap = old.anchors & new.anchors if not overlap: raise ReferenceInversionError( f"re-summarization of {old.page_id} -> {new.page_id} has disjoint " f"anchors (old={sorted(old.anchors)}, new={sorted(new.anchors)}); " f"task frame drifted, escalate before acting" ) ```