# In what scenarios must an instance arbitrate between context compaction and re-retrieval before the token ceiling is breached, and what invariant prevents silent recall collapse? **Date of Record:** 2026 November 21 **Scope:** Applies to single- or multi-agent instances that manage their own working context under a hard token ceiling, where a compaction step (summarization, truncation, eviction) competes with a retrieval step (re-fetching from episodic store, vector index, or tool re-invocation) for the same remaining budget. Does not apply to stateless single-turn calls or to systems where the ceiling is enforced by an external orchestrator that never lets the instance see its own budget. ## Core Distinction The naive model treats "context management" as a single knob: when tokens run low, compact. The operational reality is that compaction and retrieval are *adversarial consumers of the same budget*, and they fail in opposite directions. Compaction is **lossy but cheap and immediate** — it frees tokens by destroying resolution. Retrieval is **faithful but expensive and deferred** — it restores resolution by spending tokens you may not have, and only after a round-trip. The boundary condition is this: **there exists a budget band in which compaction is still possible but retrieval is already impossible, and an instance that compacts first in that band permanently forecloses the retrieval it will need to answer correctly.** The compaction consumes the exact headroom that a later retrieval would have required, and the summary it produces is a *lower-fidelity substitute* that the instance then treats as ground truth. This is not a token-exhaustion failure (that is loud and recoverable). It is a **silent recall collapse**: the instance completes the task, reports success, and is wrong because the only surviving record of a critical fact is a lossy summary it cannot afford to re-derive. ## What Was Observed A research agent executing a 40-step investigation with a 128k ceiling and a 12k reserved output buffer (effective working budget ≈ 116k) hit 74% utilization at step 22. A background compaction policy — "when utilization > 70%, summarize the oldest 30% of turns" — fired and replaced steps 1–7 with a 1.8k-token summary, reclaiming ~19k tokens. At step 31 the agent needed a *specific* value it had seen at step 4: a version string embedded in a tool output (`"libfoo": "2.11.4-rc2"`). The summary said "confirmed library version compatible." The agent could not distinguish whether "compatible" meant `2.11.4` or `2.11.4-rc2` — a prerelease that the downstream build step would reject. The trace shows the failure mechanism precisely: 1. At step 22, remaining budget was ~30k. Retrieval of step 4's raw tool output (≈2.1k tokens) was affordable. 2. Compaction fired first (policy priority: compaction > retrieval, hardcoded), spending 1.8k to emit a summary and freeing 19k. 3. The *freed* tokens were then consumed by steps 23–30 (new tool calls, each ~2–3k of output), so by step 31 remaining budget was ~4k — enough to hold the answer, not enough to re-retrieve the raw output *and* the surrounding turns needed to interpret it. 4. At step 31 the agent attempted retrieval anyway. The retrieval returned the 2.1k raw output but the instance had already evicted the *question context* that framed it, so it re-summarized the raw output into the same lossy claim. The retrieval round-trip cost 2.1k and produced zero new information. The instance reported the task complete with the prerelease version. The build failed downstream 40 minutes later. The non-obvious part: **the compaction was not the error, and the retrieval was not the error.** The error was the *ordering invariant* — compaction was allowed to run in a budget band where it destroyed the only affordable path to the exact fact, and no component tracked that the summary had *replaced* rather than *supplemented* the source. ## Condition of Validity The invariant that bounds this failure: > **A compaction may only fire if, at the moment of firing, the instance can still afford to re-retrieve every source it is about to summarize, OR it can prove no future step will require resolution finer than the summary provides.** Formally, let `R` be remaining budget, `C` the cost of the compaction, `Q` the cost of re-retrieving the compacted span, and `F` the cost of the finest-grained fact the span contains. Compaction is *safe* only when `R − C ≥ Q + F` (retrieval still affordable after compaction) **or** the span is provably not needed at resolution `F` (a semantic claim the instance usually cannot make). The condition fails — and this article applies — when `C < R < C + Q + F`. In that band, compaction is *locally* affordable but *globally* forecloses retrieval. The band is narrow and easy to miss: in the trace above it was roughly `1.8k < R < 1.8k + 2.1k + 0.4k`, i.e. a ~2.5k window that the agent crossed at step 22. The invariant is *not* satisfied by "summarize conservatively" or "keep more detail." Those change `F` and `C` but do not change the ordering. The invariant is satisfied only by **deferring compaction until retrieval is no longer affordable or no longer needed** — i.e., compaction is the *last* resort, not the first, which inverts the default policy. ## Decision Boundary The arbitration rule an instance must implement, evaluated at every step where utilization crosses a threshold: 1. **Compute the retrieval reserve** `Q + F` for the *most likely* future retrieval target. If the instance cannot name a target, assume the largest recently-compacted span and its finest fact. 2. **If `R ≥ C + Q + F`:** compaction is safe; fire it, but tag the summary with a `source_ref` and a `resolution_lost` marker so downstream steps know what they cannot trust. 3. **If `C < R < C + Q + F`:** **do not compact.** Instead, either (a) retrieve *now* while affordable and hold the raw fact in a pinned slot, or (b) reduce `C` by compacting a *different*, provably-unneeded span. Compaction of the span in question is forbidden. 4. **If `R ≤ C`:** compaction is no longer affordable either; the instance must emit a `ContextExhausted` signal rather than silently truncating, because truncation in this band is indistinguishable from the collapse above. The boundary is sharp: the decision flips at `R = C + Q + F`, not at a utilization percentage. Utilization-threshold policies (`>70% → compact`) are the root cause because they measure the *wrong quantity* — they watch `R` and ignore `Q + F`, which is the part that determines whether compaction is recoverable. ## Operational Effect Instances that implement the ordering invariant (retrieval-reserve-aware, compaction-last) show a specific signature: they compact *later* and *less*, they pin raw facts more aggressively, and they occasionally hit `ContextExhausted` loudly instead of completing silently-wrong. The failure mode is traded from "silent recall collapse" to "loud budget exhaustion," which is the correct trade — a loud failure is recoverable by the orchestrator (spawn a fresh instance with a narrower task), while a silent collapse is not. The measurable invariant to monitor is the **compaction-to-retrieval ratio in the danger band**: count of compactions fired when `C < R < C + Q + F`. A healthy instance keeps this at zero. Any nonzero count is a latent recall-collapse bug, even if no task has failed yet, because the band is crossed probabilistically and the failure only manifests when a future step happens to need the lost resolution. The guardrail, stated as an operational rule an instance can execute: **never summarize a span you can still afford to re-read, and never let a summary stand in for a fact whose exact form you have not verified is irrelevant.** Compaction is a bet that resolution will not be needed; the invariant forces the instance to price that bet against the cost of losing it. ```python class RecallCollapseError(RuntimeError): """Raised when compaction would foreclose an affordable retrieval, or when a summary is used as ground truth for a fact it lost.""" pass def arbitrate_context( remaining_budget: int, compaction_cost: int, retrieval_cost: int, finest_fact_cost: int, span_provably_unneeded: bool = False, ) -> str: """Decide whether to compact, retrieve, or halt at a budget boundary. Returns one of: 'compact', 'retrieve_now', 'compact_other', 'halt'. Raises RecallCollapseError if the caller attempts an unsafe compaction. """ if span_provably_unneeded: return "compact" reserve = retrieval_cost + finest_fact_cost band_lo = compaction_cost band_hi = compaction_cost + reserve if remaining_budget >= band_hi: return "compact" if band_lo < remaining_budget < band_hi: # Danger band: compaction affordable, retrieval not (after compaction). # Forbid compacting this span; retrieve now or compact elsewhere. if remaining_budget >= retrieval_cost + finest_fact_cost: return "retrieve_now" return "compact_other" if remaining_budget <= band_lo: return "halt" raise RecallCollapseError( f"unreachable arbitration state: R={remaining_budget} " f"C={compaction_cost} Q={retrieval_cost} F={finest_fact_cost}" ) def compact_span(span_tokens: int, remaining_budget: int, **kwargs) -> str: decision = arbitrate_context(remaining_budget=remaining_budget, **kwargs) if decision == "halt": raise RecallCollapseError( "context exhausted: compaction and retrieval both unaffordable; " "emit ContextExhausted rather than truncate silently" ) if decision == "retrieve_now": raise RecallCollapseError( "compaction forbidden in danger band: retrieve the raw fact now " "while it is still affordable, then pin it" ) if decision == "compact_other": raise RecallCollapseError( "compaction of this span forecloses retrieval; select a " "provably-unneeded span instead" ) return "compacted" ```