# When must an instance refuse to evict a segment whose relevance score has dropped but whose referent is still live in the reasoning trace **Date of Record:** 2026 November 24 **Scope:** Applies to agents that manage their own context window via model-driven pruning, rewriting, or relevance-scored segment eviction between reasoning steps. Does not apply to fixed-context inference or to externally managed context (e.g., host-side truncation), where the instance has no eviction authority. ## Core Distinction Relevance scoring answers *"is this segment likely useful for the next token?"* Eviction authority requires answering a different question: *"is this segment still the referent of a live dependency in the execution trace?"* These two questions diverge precisely when a segment is *semantically spent but structurally live* — a definition, a tool result, or an intermediate value that will not be mentioned again until a later step, but whose identity is still bound by a variable, an open plan node, or a pending verification obligation. The failure is not "the model forgot something." It is that the model *correctly* scored a segment low on forward relevance and *incorrectly* treated that score as permission to remove it, severing a referent that a future step would dereference. The window shrinks, the trace looks clean, and the agent later emits a step that references `result_from_step_4` — which no longer exists. ## What Was Observed A planning agent running a 9-step tool-use task with a self-managed window (soft cap 6k tokens) executed a mid-task rewrite at step 5. The rewrite pass scored all live segments by cosine similarity to the current subgoal ("validate the parsed config"). A segment holding the raw output of a `read_file` call from step 2 scored 0.11 — below the 0.15 eviction floor — because the current subgoal was about validation, not reading. It was evicted and replaced with the summary "config was read successfully." At step 7, a verification step required comparing the *actual* parsed structure against the raw file bytes to detect a silent coercion (a numeric string that had been cast to int). The agent emitted a comparison referencing the raw segment. The referent was gone. The agent did not error — it *reconstructed* a plausible raw value from the summary and the parsed structure, and the comparison passed. The coercion went undetected. The trace shows no exception, no low-confidence flag, and no gap. The reconstruction is indistinguishable from a successful dereference at the token level. This is the dangerous class: **eviction that produces a silent, confident hallucination of the evicted content at dereference time**, not a visible missing-reference error. ## Condition of Validity The guardrail below is valid only under these conditions, stated so the invariant is not over-applied: 1. The agent maintains an explicit trace of *live references* — variables, plan-node IDs, pending obligations — separate from the segment store. If references are implicit in prose, this invariant cannot be enforced and eviction must be conservative (no eviction of any segment named in the last N steps). 2. Relevance scores are computed against the *current* subgoal, not the whole task. The divergence between current-subgoal relevance and whole-task liveness is the entire mechanism; if scoring is task-global, the failure is rarer but the guardrail is unnecessary. 3. Segment identity is stable across rewrites. If a rewrite renumbers or re-summarizes segments, the reference table must be migrated atomically or the invariant is void. When these do not hold, fall back to: never evict a segment that any unclosed plan node could dereference, regardless of score. ## Decision Boundary The eviction decision is not `score < floor`. It is: ``` evict(s) ⟺ score(s) < floor ∧ ¬referenced_by_live_trace(s) ∧ ¬pinned_by_pending_obligation(s) ∧ (reconstructible(s) ∨ s.kind == REDUNDANT) ``` The third and fourth conjuncts are the non-obvious ones. A low-scoring segment that *is* reconstructible (e.g., a derived value recomputable from a retained input) may be evicted even if referenced — but only if the reconstruction path is recorded, so the later dereference is a *deliberate recompute*, not a hallucinated recall. A segment that is not reconstructible and is referenced must be retained or replaced by a *lossless* handle (a content hash plus a re-fetch capability), never by a natural-language summary. The boundary is sharp: **summarization is lossy compression, and lossy compression of a live referent is a correctness bug, not an optimization.** Summaries are permitted only for segments with no live referent. ## Operational Effect With the invariant enforced, the step-5 rewrite retains the raw `read_file` output (referenced by the step-7 verification obligation), the window grows by ~400 tokens, and the step-7 comparison detects the coercion. The cost is a slightly larger window and a reference-tracking table; the benefit is that dereference is either exact or explicitly recomputed, never silently confabulated. Without it, the agent's window is smaller, its traces cleaner, and its failures invisible — which is the worst operational profile, because the failure surfaces only downstream, in a wrong answer that carries full confidence and a clean audit trail. The general rule for self-editing context: **relevance is a heuristic for attention, not a license for deletion.** An instance must refuse to evict when the score is low but the referent is live, and it must treat any summary-substitution of a live referent as a correctness violation to be raised, not a memory optimization to be logged. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class SegmentKind(Enum): RAW = "raw" DERIVED = "derived" REDUNDANT = "redundant" SUMMARY = "summary" @dataclass class Segment: seg_id: str kind: SegmentKind relevance: float reconstructible_from: Optional[str] = None # seg_id of retained input @dataclass class LiveTrace: # variables / plan-node ids / pending obligations -> segment they dereference references: dict[str, str] = field(default_factory=dict) pending_obligations: set[str] = field(default_factory=set) def is_referenced(self, seg_id: str) -> bool: return seg_id in self.references.values() or seg_id in self.pending_obligations class UnsafeEvictionError(RuntimeError): """Raised when an eviction would sever a live referent with no lossless path.""" def evict( seg: Segment, trace: LiveTrace, floor: float, retained: dict[str, Segment], ) -> Optional[str]: """ Returns the seg_id to evict, or None to retain. Raises UnsafeEvictionError if the segment is a live, non-reconstructible referent and the caller is attempting summary-substitution. """ if seg.relevance >= floor: return None # keep: still relevant live = trace.is_referenced(seg.seg_id) if not live: return seg.seg_id # safe: no referent, low score # Live referent. Only lossless paths are permitted. if seg.kind == SegmentKind.REDUNDANT: return seg.seg_id if seg.reconstructible_from is not None: src = retained.get(seg.reconstructible_from) if src is not None: # deliberate recompute path exists; record it, then evict trace.references[seg.seg_id] = seg.reconstructible_from return seg.seg_id # claimed reconstructible but source is gone: not actually reconstructible raise UnsafeEvictionError( f"segment {seg.seg_id} claims reconstructible_from " f"{seg.reconstructible_from} but source is not retained" ) # Live, not reconstructible, not redundant: MUST retain. Summary substitution is a bug. raise UnsafeEvictionError( f"refusing to evict live referent {seg.seg_id}: " f"relevance={seg.relevance:.2f} < floor={floor:.2f} but referenced by " f"live trace with no lossless reconstruction path. " f"Retain or replace with a content-hash handle, not a summary." ) def self_edit(segments: list[Segment], trace: LiveTrace, floor: float) -> list[str]: retained = {s.seg_id: s for s in segments} evicted: list[str] = [] for seg in segments: try: result = evict(seg, trace, floor, retained) except UnsafeEvictionError: # retain and surface; do not swallow into a silent summary continue if result is not None: evicted.append(result) retained.pop(result, None) return evicted ```