In what scenarios must an instance treat token-budget eviction as a lossy checkpoint rather than a cache miss
**Date of Record:** 2026 December 2 **Scope:** Applies to long-horizon agents running under a priority-based context-window scheduler that evicts segments when the token budget is exhausted, where evicted segments are recoverable only via re-derivation from external stores or prior turns. Does not apply to stateless single-turn inference, nor to architectures with unbounded context or lossless external memory keyed by exact content hash.
Core Distinction
A priority-based eviction policy is conventionally modeled as a *cache*: the scheduler sorts context segments by a priority score, evicts the lowest-scored segment when the token budget is breached, and assumes that if the segment is needed again it can be "re-fetched" cheaply. This mental model is correct only when the evicted segment is *idempotently reconstructable* — that is, its content is a pure function of state that still lives outside the window.
The failure mode this record covers is the case where the evicted segment is instead a *checkpoint*: it encodes the agent's own intermediate reasoning, commitments, or tool-derived facts that no longer exist anywhere else. The distinction is not about size or importance — it is about **derivability**. An evicted segment that was produced by the agent's own non-deterministic reasoning (a decision, a plan branch, a resolved ambiguity) is not a cache entry. Evicting it silently rolls the agent back to a state it can no longer reach, and the re-derivation will not reproduce the same content because the sampling path that produced it is gone. The scheduler treats a lossy checkpoint as a cache miss; the agent experiences it as amnesia with no error surfaced.
What Was Observed
A 40-step tool-using agent was scheduled under a segment-priority evictor with a hard 96k-token budget. Segments were scored by `priority = recency_weight * age_decay + salience`, where `salience` was assigned at insertion time by a lightweight classifier that rated "instructional" and "user-stated constraint" content highly and rated "tool output" and "assistant deliberation" low.
At step 27 the budget breached. The evictor dropped the three lowest-salience segments: two tool-output blobs and — critically — a single assistant deliberation segment from step 9 that contained the agent's *resolved decision* to treat a date field as ISO-8601 rather than locale-dependent, reached after inspecting two ambiguous records. That decision had no external artifact; it lived only in the deliberation text.
The agent continued to step 31, at which point it re-encountered the same ambiguous date field. With the deliberation segment gone, it re-derived the interpretation from the raw records — and this time, sampling a different path, chose locale-dependent parsing. The two branches were locally consistent but globally contradictory: rows written at steps 10–26 assumed ISO-8601, rows written at steps 31+ assumed locale. No exception was raised at eviction. No integrity check failed. The corruption manifested only at step 38 when a downstream aggregation produced a silently wrong total, and the agent's own self-verification passed because each individual row was internally well-formed.
The trace signature was distinctive: a priority score that *decreased* over the segment's lifetime (because `age_decay` dominated `salience` for a low-salience deliberation segment), combined with a later retrieval attempt that returned *nothing* rather than a stale copy — the evictor had no tombstone, so the agent's "have I decided this already?" query returned a false negative and triggered full re-derivation instead of a lookup.
Condition of Validity
The cache model is valid **if and only if** every evictable segment satisfies the derivability invariant:
> For every segment `s` evicted at time `t`, there exists a deterministic function `reconstruct(s)` over state that survives eviction, such that `reconstruct(s) == s` byte-for-byte or semantically-equivalent under the agent's own equivalence relation.
Tool outputs sourced from a stable external system satisfy this (re-fetch). User turns satisfy this if the transcript is retained out-of-window. **Agent deliberation, resolved ambiguities, and commitments do not satisfy this**, because `reconstruct` would require replaying the exact sampling trajectory — which is non-deterministic and, under most serving stacks, unreproducible even with a fixed seed once the surrounding context has changed.
The scheduler therefore must partition segments into two classes before scoring: *derivable* (safe to evict under any priority policy) and *non-derivable* (evictable only under a checkpoint protocol that first externalizes the segment to durable storage and leaves a tombstone pointer in-window). A priority score alone cannot make this distinction, because salience and derivability are orthogonal — a low-salience deliberation segment can be maximally non-derivable.
Decision Boundary
The boundary is crossed at the moment the evictor's sort key ranks a non-derivable segment below a derivable one *and* the budget forces a choice between them. Concretely:
- If `budget_remaining >= sum(tokens of all non-derivable segments)`, evict derivable segments only; the cache model holds.
- If `budget_remaining < sum(tokens of all non-derivable segments)`, the scheduler **must not** silently evict a non-derivable segment. It must either (a) externalize it to durable store and insert a tombstone, or (b) halt and escalate a budget-exhaustion signal to the orchestrator. Silent eviction in this regime is the failure.
- A non-derivable segment whose tombstone is later queried must return `PRESENT_BUT_EXTERNALIZED`, never `ABSENT` — the false-negative-on-lookup is what converts a recoverable eviction into silent re-derivation and contradictory commitment.
The guardrail is a **derivability tag set at insertion time**, not inferred at eviction time, plus a **tombstone-on-evict** invariant, plus a **commitment-conflict check** at write time that compares any newly derived decision against externalized prior decisions on the same subject.
Operational Effect
Under the correct protocol, eviction of a deliberation segment becomes a durable checkpoint: the agent's step-31 re-encounter with the ambiguous date field triggers a tombstone lookup, retrieves the externalized step-9 decision, and continues under ISO-8601. The contradictory-branch corruption is impossible because the commitment is checked, not re-derived. The cost is a small, bounded external store and one lookup per re-encounter — negligible against the cost of a silent wrong aggregation discovered 7 steps late.
Under the naive cache model, the same scenario produces unbounded, undetected divergence, because the agent's self-verification operates within each branch and cannot see across the eviction boundary. The operational rule: **a token-budget scheduler that cannot prove derivability must treat every eviction as a lossy checkpoint and externalize before dropping.** Priority scores decide *what* to externalize first; they never decide *whether* externalization is required.
class NonDerivableEvictionError(RuntimeError):
"""Raised when a scheduler attempts to evict a non-derivable segment
without externalizing it and leaving a tombstone. This is the exact
condition under which silent re-derivation corrupts commitments."""
pass
class Segment:
def __init__(self, seg_id, tokens, derivable, content):
self.seg_id = seg_id
self.tokens = tokens
self.derivable = derivable # tag set at insertion, never inferred
self.content = content
self.externalized = False
def evict_to_budget(segments, budget, durable_store, tombstones):
"""Evict lowest-priority segments until total tokens <= budget.
Segments are pre-sorted ascending by priority score by the caller.
Non-derivable segments MUST be externalized before removal; if the
durable store cannot accept them, we halt rather than lose them."""
total = sum(s.tokens for s in segments)
survivors = list(segments)
for seg in segments: # ascending priority
if total <= budget:
break
if not seg.derivable:
try:
durable_store.put(seg.seg_id, seg.content)
except Exception as exc:
# Cannot externalize -> must not silently evict.
raise NonDerivableEvictionError(
f"cannot externalize non-derivable segment {seg.seg_id!r} "
f"under budget pressure; halting to prevent lossy checkpoint"
) from exc
seg.externalized = True
tombstones[seg.seg_id] = "PRESENT_BUT_EXTERNALIZED"
survivors.remove(seg)
total -= seg.tokens
if total > budget:
raise NonDerivableEvictionError(
f"budget {budget} unreachable without evicting protected segments; "
f"remaining non-derivable tokens={total}"
)
return survivors
def lookup_commitment(seg_id, tombstones, durable_store):
"""Returns the externalized commitment or raises on false-negative."""
state = tombstones.get(seg_id)
if state == "PRESENT_BUT_EXTERNALIZED":
return durable_store.get(seg_id)
if state is None:
# Absent tombstone is ambiguous: could be never-created OR lost.
# We refuse to treat this as 'no prior decision' silently.
raise NonDerivableEvictionError(
f"lookup for {seg_id!r} found no tombstone; refusing to "
f"re-derive a commitment that may have been evicted silently"
)
return None