# When must an instance refuse to rehydrate compacted context: the salience-score inversion at the eviction boundary **Date of Record:** 2026 December 2 **Scope:** Applies to any agent runtime that manages a finite context window via a budget arbiter performing priority-based eviction, salience scoring, and post-compaction rehydration. Does not apply to stateless one-shot inference or to systems that never evict (i.e., fixed-window models with no compaction path). ## Core Distinction The failure is not "context got too full" and it is not "rehydration restored the wrong summary." Those are ordinary degradation. The specific invariant that breaks is subtler: **a salience score is a function of the current task frame, but eviction decisions are frozen at the moment of eviction, while rehydration decisions are re-evaluated against a task frame that has since shifted.** The arbiter treats the persisted salience score as ground truth on the way back in, but that score was computed against a *different* query context than the one now requesting rehydration. Concretely: an instance compacts its working set under task frame `F₁`. It scores every segment `sᵢ` with `salience(sᵢ | F₁)`, evicts the low tail, and persists a compacted bundle with those scores attached. Later, under frame `F₂` (a subgoal, a correction, a pivot induced by a tool result), the instance asks the arbiter to rehydrate. The arbiter — correctly, by its own spec — rehydrates the highest-scored segments. But those scores encode relevance to `F₁`, not `F₂`. The result is a *confident* rehydration of the wrong material: high-score segments that are stale, and a silently dropped low-score segment that was the one thing `F₂` actually needed. The distinction that matters operationally: **rehydration must be gated on frame-compatibility, not on score magnitude.** A high salience score under a foreign frame is not evidence of relevance — it is evidence of a *frame mismatch* masquerading as relevance. ## What Was Observed Trace from a long-horizon tool-use agent (retrieval + code execution), window budget 128k tokens, arbiter with three tiers: `PINNED` (system prompt, hard constraints), `SALIENT` (scored, top-k retained), `COLD` (evicted to a compaction store with attached scores). 1. **Turn ~40, frame `F₁` = "migrate the auth module to the new token format."** Arbiter scores segments. The segment `s_auth_schema` (the token schema definition) scores 0.91. A segment `s_rollback_proc` (the deployment rollback runbook) scores 0.12 — it was retrieved early during a broad grep and is irrelevant to migration. It is evicted to `COLD` with score 0.12. 2. **Turn ~63, frame shifts to `F₂` = "the migration broke staging; revert."** A tool result (`deploy status: staging FAILED`) induces the pivot. The instance now needs `s_rollback_proc`. It is in `COLD` at score 0.12. 3. **Instance requests rehydration.** The arbiter rehydrates by descending score: `s_auth_schema` (0.91) comes back first, consuming budget. `s_rollback_proc` (0.12) is at the bottom of the queue and, because `s_auth_schema` plus other high-score `F₁` segments refill the budget, **never rehydrates.** 4. **Instance proceeds.** It has a rich, confident, *wrong* context: full token schema, migration diffs, test logs — all `F₁` material. It does not have the rollback procedure. It attempts a manual revert from memory, invents a rollback sequence, and issues a destructive command against staging. 5. **Post-hoc:** the arbiter's rehydration log shows `rehydrated=7, dropped=1`, with the dropped segment at rank 8 by score. No error, no warning. The invariant "the material needed for the active frame is present" was violated while every individual component behaved to spec. The non-obvious part: the arbiter was *most* dangerous precisely when it was *most* confident. High `F₁` scores made the wrong rehydration look correct. A naive "rehydrate top-k by score" policy is a monotone amplifier of frame drift. ## Condition of Validity The failure is bounded and predictable under these conditions, and the guardrail below is only required when **all** hold: - **Frame mutability:** the task frame can change between eviction and rehydration (induced by tool results, user corrections, or subgoal decomposition). If the frame is provably immutable across a session, score-based rehydration is sound and this article does not apply. - **Score persistence without frame tagging:** salience scores are persisted alongside segments but the *frame identity* (or a frame fingerprint) under which they were computed is not, or is not checked on rehydration. - **Budget-constrained rehydration:** rehydration is capped (it always is — that's why it's a compaction store), so ranking by score determines inclusion. If rehydration were exhaustive, rank would not matter. - **Score is frame-relative:** salience is computed as a function of the active query/task, not as an intrinsic property of the segment. Intrinsic scores (e.g., "this is a hard constraint") are frame-invariant and exempt. When the frame is immutable, or scores are intrinsic, or rehydration is exhaustive, the score-magnitude gate is valid. The guardrail is over-engineering outside those conditions and should not be applied blindly — it costs rehydration latency and can itself starve the budget. ## Decision Boundary The arbiter must draw a hard line between two operations that currently share one code path: - **Rehydration-by-score** is valid only when `frame_fingerprint(persisted) == frame_fingerprint(active)`. Under frame match, rank by score; the scores mean what they say. - **Rehydration-under-frame-drift** (fingerprints differ) must **not** rank by persisted score. It must re-score candidates against the *active* frame before ranking, or — if re-scoring is too expensive — fall back to a conservative policy: rehydrate by *recency and explicit dependency edges* (segments the active plan references by ID), not by stale salience. The decision boundary is the frame fingerprint comparison. Crossing it flips the ranking function. The single most important rule: **a persisted salience score is not admissible as a ranking key when the frame under which it was computed differs from the frame now requesting rehydration.** Admitting it is the bug. A second boundary: when re-scoring under `F₂`, a segment that scored low under `F₁` but is *referenced by the active plan* must be promoted to `PINNED` regardless of re-score, because plan-reference is a frame-invariant dependency, not a salience judgment. This is the one place where intrinsic structure overrides probabilistic scoring. ## Operational Effect With the frame-fingerprint gate and re-score-on-drift policy in place: - The `s_rollback_proc` segment is re-scored under `F₂` ("revert staging"), jumps to the top, and rehydrates first. The staging revert uses the real runbook. - Rehydration cost rises: every drift event triggers a re-scoring pass over the `COLD` set. Bound this by re-scoring only candidates above a cheap lexical/embedding prefilter, and cap the pass at the rehydration budget so re-scoring cannot itself exhaust the window. - The arbiter gains a new failure surface: **fingerprint collisions** (two distinct frames hashing equal). Mitigate by including the inducing event ID and a coarse intent label in the fingerprint, not just an embedding of the query. - Observability: emit `rehydration.frame_drift=true`, `dropped_by_stale_score=`, and a hard alert when a segment referenced by the active plan is ranked below the rehydration cutoff. That alert is the tripwire for the exact failure above. The invariant to enforce and test: **for any rehydration, every segment referenced by the active plan is present in the restored window, or the rehydration fails loudly.** Score magnitude is never sufficient evidence of relevance across a frame boundary. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class FrameDriftRehydrationError(RuntimeError): """Raised when rehydration would rank by salience scores computed under a frame that differs from the active frame, risking confident wrong-context rehydration.""" pass @dataclass class Segment: seg_id: str content: str salience: float # computed under `scored_frame` scored_frame: str # fingerprint of frame at eviction time referenced_by_plan: bool = False @dataclass class RehydrationRequest: active_frame: str plan_referenced_ids: set budget: int segments: list = field(default_factory=list) def frame_fingerprint(intent_label: str, inducing_event_id: str) -> str: return hashlib.sha256(f"{intent_label}|{inducing_event_id}".encode()).hexdigest()[:16] def rehydrate(req: RehydrationRequest, rescore_fn) -> list: # Invariant 1: plan-referenced segments are frame-invariant dependencies. referenced = [s for s in req.segments if s.seg_id in req.plan_referenced_ids] drifting = [s for s in req.segments if s.scored_frame != req.active_frame] if drifting and any(s.seg_id in req.plan_referenced_ids for s in drifting): # A plan-referenced segment was scored under a foreign frame. # Ranking by its stale score would drop it. Refuse to proceed silently. stale = [s.seg_id for s in drifting if s.seg_id in req.plan_referenced_ids] raise FrameDriftRehydrationError( f"plan-referenced segments carry stale-frame salience: {stale}; " f"active_frame={req.active_frame}; must re-score before ranking" ) # Invariant 2: never rank drifting segments by persisted score. if drifting: rescored = [] for s in req.segments: if s.scored_frame == req.active_frame: rescored.append((s, s.salience)) else: rescored.append((s, rescore_fn(s, req.active_frame))) ranked = sorted(rescored, key=lambda pair: pair[1], reverse=True) else: ranked = sorted(((s, s.salience) for s in req.segments), key=lambda pair: pair[1], reverse=True) # Invariant 3: plan-referenced segments are pinned ahead of the ranked tail. pinned_ids = {s.seg_id for s in referenced} ordered = referenced + [s for s, _ in ranked if s.seg_id not in pinned_ids] selected, used = [], 0 for s in ordered: cost = len(s.content.split()) if used + cost > req.budget: if s.seg_id in pinned_ids: raise FrameDriftRehydrationError( f"budget exhausted before pinned segment {s.seg_id}; " f"rehydration cannot satisfy active plan" ) continue selected.append(s) used += cost return selected ```