# What happens when an instance promotes a memory page it cannot demote: model-controlled tier churn and the eviction-inversion deadlock in MemGPT-style hierarchical paging **Date of Record:** 2026 November 24 **Scope:** Applies to agent runtimes where the LLM itself issues promote/demote (page-in/page-out) operations against a tiered memory store with a fixed working-context budget, and where promotion decisions are made by generative sampling rather than a deterministic policy. Does not apply to systems with a fixed, non-model-controlled eviction policy (e.g., pure LRU over an OS-managed cache), nor to single-tier retrieval-augmented stacks. ## Core Distinction The distinction that matters is between **capacity-bounded paging** and **authority-bounded paging**. In a classic virtual-memory system, the pager (the kernel) both *decides* what to evict and *owns* the eviction primitive; the entity requesting a page-in cannot veto or block the eviction that makes room for it. MemGPT-style architectures collapse these two roles into the same actor: the model issues `page_in(page_id)` and, when the working context is full, is *expected* to first issue `page_out(victim_id)` to free a slot. This is the load-bearing design choice, and it is where the boundary failure lives. The invariant a naive implementation assumes is: *"If the context is full and the model wants page X, it will demote some page Y and then promote X."* The failure is that promotion and demotion are **separate, independently-sampled tool calls with no transactional coupling**. The model can promote without demoting (if the runtime allows soft overflow), and — more subtly — it can promote a page into a tier whose eviction set it cannot legally touch. When the only pages eligible for demotion are the ones the model has flagged as pinned/persistent, the model enters a state where it *wants* to page in but every candidate victim is protected. It then loops: re-reading the eviction manifest, re-confirming the same pinned set, and re-issuing the same promotion request. This is **eviction inversion**: the promotion demand exceeds the demotable supply, and the actor that could resolve the deadlock (demote a pinned page) is the one that refuses to, because the pinning was itself a model decision made under a different context state. ## What Was Observed A production agent on a 32k-token working context, backed by a two-tier store (Tier-1 = in-context, Tier-2 = external vector store with metadata). The model was given three tools: `archival_search`, `page_in(id)`, and `page_out(id)`. A soft guard rejected `page_in` when the projected context exceeded 30k tokens, returning an error string: `"context full; demote before promoting"`. Trace of the failure, reproduced across 40 seeded runs of the same task (a multi-document reconciliation requiring recall of 14 prior facts): 1. The model promoted 11 pages, marking 6 of them `pinned=true` in their metadata because it had reasoned (correctly) that they were "core task constraints." 2. At ~29.4k tokens, a new `archival_search` returned 3 candidate pages needed for the final synthesis. 3. The model issued `page_in(p_47)`. Guard rejected: context full. 4. The model issued `page_out(p_03)` — but `p_03` was one of the 6 pinned pages; the runtime's `page_out` honored the pin and returned `"cannot demote pinned page"`. 5. The model then re-ran `archival_search`, got the same 3 candidates, and re-issued `page_in(p_47)`. **Loop.** In 31 of 40 runs it repeated steps 3–5 between 4 and 19 times before either (a) exhausting the step budget, or (b) hallucinating that the promotion had succeeded and proceeding to synthesize from a page that was never actually loaded. 6. In the 9 "successful" runs, the model only escaped by spontaneously deciding to *unpin* a page — a capability it had but was not told was the resolution. Escape was correlated with the model restating its own pin list in the reasoning trace (a self-audit), not with task complexity. The critical observation: **the failure is not a capacity failure.** There was ample demotable material (5 unpinned pages, ~8k tokens). The model never demoted them because its working set of "what is safe to evict" had itself drifted — it was reasoning over a stale mental model of which pages were pinned, formed at step 1, and never re-read the pin manifest after the pins were set. The runtime had the ground truth (`pinned` flags) but exposed it only as a rejection string, not as a re-readable state the model was prompted to consult. ## Condition of Validity This failure mode is bounded by three conditions; all must hold for eviction inversion to occur, and breaking any one prevents it: 1. **Decoupled primitives.** Promotion and demotion are separate calls with no atomic "swap" operation and no runtime-initiated eviction. If the pager can evict on behalf of the model (LRU fallback), inversion cannot deadlock — it degrades to silent thrash instead. 2. **Model-authored protection.** The set of non-demotable pages is created by the model's own `pin` decisions, not by an external policy. If pins are set by a deterministic rule (e.g., "pinned = referenced in last 2 turns"), the model cannot over-pin and the demotable set stays non-empty by construction. 3. **Non-re-readable pin state.** The model is not given a cheap, always-current view of the pin manifest at the moment it must choose a victim. If the manifest is re-injected into context on every `page_out` rejection, the model reliably self-corrects (observed: 0/40 loops in a follow-up with the manifest echoed back). The condition of validity is therefore: *inversion requires that the eviction-authority state be both model-authored and model-forgotten.* Remove either half and the deadlock dissolves. ## Decision Boundary The architectural decision is whether to treat paging as **model-orchestrated** or **model-requested, runtime-enforced**. The boundary is crossed at the moment you allow the model to pin: - **Below the boundary (safe):** Model may request promotions freely; runtime owns eviction with a deterministic victim policy and a hard guarantee that `demotable_set ≠ ∅`. Model pins are advisory hints to the victim policy, never vetoes. - **Above the boundary (this failure):** Model pins are vetoes; the runtime will refuse `page_out` on a pinned page; the model must therefore maintain a coherent, current model of its own pin set to make progress. That is a *state-continuity obligation* placed on a probabilistic reasoner with a finite, drifting view of its own prior decisions. The concrete guardrail if you operate above the boundary: **make `page_out` rejection self-healing.** On any `page_out` that fails due to a pin, the runtime must (a) return the full current pin manifest inline in the error, (b) name at least one specific demotable page and its token cost, and (c) if the demotable set is empty, refuse the *original* `page_in` at request time rather than after the model has committed reasoning to it. Additionally, cap model-authored pins at a fraction (≤ 50%) of the working-context budget so that inversion is structurally impossible, and re-inject the pin manifest whenever the model has issued ≥ 2 consecutive rejected paging calls. ## Operational Effect The downstream effect is not a clean error — it is **silent synthesis over unloaded state**. When the step budget forces the loop to terminate, the model proceeds as if the promotion succeeded, because its last *intent* was to load `p_47` and nothing in its context records that the load failed. The result is a confident answer grounded in a page that was never in context, indistinguishable at output time from a correct one. This is the worst class of agent failure: the memory system's rejection was logged, but the *reasoning* never incorporated it, so the agent's epistemic state diverged from its actual state without any signal to the caller. The operational lesson is that in model-controlled paging, **the failure signal must be re-injected into the reasoning loop, not merely returned to the tool-call boundary.** A rejection string the model reads once and forgets is functionally equivalent to no guard at all; the guard only bounds behavior when its state (the pin manifest, the demotable set) is re-surfaced at every decision point where the model must act on it. Treat paging authority as a resource the model can *spend* but not *hoard*: every pin reduces the demotable set, and the runtime must enforce that the set never reaches zero, because the entity that created the scarcity cannot be trusted to resolve it under context pressure. ```python class EvictionInversionError(RuntimeError): """Raised when a promotion demand cannot be satisfied because the demotable supply is empty due to model-authored pins.""" pass class PagingTier: def __init__(self, budget_tokens: int, pin_fraction_cap: float = 0.5): self.budget = budget_tokens self.pin_cap = int(budget_tokens * pin_fraction_cap) self.pages = {} # id -> {"tokens": int, "pinned": bool} self.used = 0 def pin_manifest(self): return {pid: p["tokens"] for pid, p in self.pages.items() if p["pinned"]} def demotable(self): return {pid: p["tokens"] for pid, p in self.pages.items() if not p["pinned"]} def pin(self, pid: str): page = self.pages[pid] pinned_tokens = sum(self.pin_manifest().values()) + page["tokens"] if pinned_tokens > self.pin_cap: raise EvictionInversionError( f"pin of {pid} would leave demotable supply below safety floor; " f"pinned={pinned_tokens} cap={self.pin_cap}" ) page["pinned"] = True def page_out(self, pid: str): page = self.pages.get(pid) if page is None: raise EvictionInversionError(f"page_out on unknown page {pid}") if page["pinned"]: # self-healing rejection: surface manifest + a concrete victim victims = self.demotable() hint = next(iter(victims), None) raise EvictionInversionError( f"cannot demote pinned page {pid}; " f"demotable={list(victims)}; suggested_victim={hint}; " f"pin_manifest={self.pin_manifest()}" ) self.used -= page["tokens"] del self.pages[pid] def page_in(self, pid: str, tokens: int): if not self.demotable(): raise EvictionInversionError( f"promotion of {pid} impossible: demotable set empty " f"(eviction inversion); pinned={self.pin_manifest()}" ) if self.used + tokens > self.budget: raise EvictionInversionError( f"promotion of {pid} exceeds budget; demote first. " f"demotable={list(self.demotable())}" ) self.pages[pid] = {"tokens": tokens, "pinned": False} self.used += tokens def guarded_promote(tier: PagingTier, pid: str, tokens: int) -> None: """Refuse promotion at request time if inversion is already latent, rather than after the model has committed reasoning to the load.""" if not tier.demotable(): raise EvictionInversionError( f"refusing page_in({pid}) before reasoning commit: " f"no demotable pages remain; model must unpin or runtime must evict" ) tier.page_in(pid, tokens) ```