# Where must an instance refuse to prune a context segment whose relevance is only recoverable through the segment it is about to delete **Date of Record:** 2026 November 24 **Scope:** Applies to agents that rewrite their own working context in place—relevance scoring, summarization, or eviction of segments mid-task—where the scoring signal for a segment is itself computed from, or materially depends on, content that the pruning operation removes. Does not apply to append-only context growth, nor to external retrieval stores where evicted content remains addressable. ## Core Distinction The failure is not "the agent pruned something it needed." That is a retrieval miss, and it is recoverable: the content is gone but the agent knows it is gone and can re-fetch or re-derive. The boundary condition here is subtler: the agent prunes a segment *because its relevance score is low*, where that low score is an artifact of the segment's own content having been the only thing that made other, co-located segments legible. Deleting the "anchor" segment retroactively changes the true relevance of a segment that survives, but the surviving segment's score is never recomputed, because the scoring pass already completed and the anchor is already gone. Concretely: relevance scoring is a function of the *current* context window. When you evict segment A, you change the input distribution against which segment B's score was assigned. If B's score depended on A being present—an anaphor resolved by A, a schema defined in A, a unit or identifier declared in A—then B is now orphaned. B remains in the window, scored as "relevant," but it is no longer *interpretable*. The agent believes it retained a useful fact and instead retained a dangling reference. This is a self-inflicted, silent corruption of the context, and it is invisible to any downstream check that only verifies "did the segment survive?" The invariant that must hold: **pruning must be a fixed point with respect to the scoring function.** If scoring is recomputed after eviction, the surviving set's scores must not change. When they do change, the eviction was unsound—not because it removed something, but because it invalidated the basis on which it decided what to keep. ## What Was Observed A long-running research agent accumulated a context of ~140 segments across a multi-hour task. It ran a relevance-pruning pass every N tool calls, scoring each segment against the current task goal and evicting the bottom quartile. The scoring model was the same instance, prompted per-segment with the goal and the segment text. At the pruning pass after call 40, the agent evicted a segment that had established a working definition: `"Let 'active' mean a customer with a payment event in the last 90 days."` The segment scored low because, in isolation, it read as a definition with no bearing on the immediate sub-goal (enumerating churned accounts). Three segments survived that each said variants of `"filter to active first, then dedupe."` These survived because they mentioned the task keywords. The next tool call queried the data source with `active=true`. The agent had, at that point, no in-window definition of `active`. It reconstructed one from the surviving segments' usage—specifically, it inferred "active" meant "has any payment event ever," because the surviving segments were adjacent to a lifetime-value discussion. The query returned a set roughly 3× too large. The error did not surface immediately: the inflated set was plausible, downstream aggregations ran, and the discrepancy was only caught two calls later when a count failed a sanity assertion against a previously cached total. The tell was a recomputation check. On the pruning pass, we re-ran scoring against the *post-eviction* window. The three surviving `"filter to active"` segments dropped from ~0.6 to ~0.15 relevance—not because their text changed, but because their referent was gone. The scoring function, run post-hoc, would have evicted them too. The pruning pass had produced a context that was not a fixed point of its own scorer. A second, cleaner instance: the agent evicted a segment containing a column schema (`revenue_usd` is in cents, not dollars) while retaining a segment that said `"sum revenue_usd across the cohort."` The surviving segment was correctly scored as relevant—it names the task operation. But it had silently become a unit-error trap. The schema's relevance in isolation was low ("just a fact about a table"); its relevance *as a dependency of a retained segment* was total. Per-segment independent scoring cannot see this, because the dependency edge lives between segments, not inside either one. ## Condition of Validity The invariant "pruning must be a fixed point of the scorer" holds and is checkable under these conditions: 1. **Scoring is a pure function of (goal, segment, window).** If scoring depends on tool-call recency, wall-clock, or hidden state, the fixed-point check is not well-defined and you must fall back to dependency-tracking (below). 2. **The window is the unit of scoring, not the segment.** Scoring segments independently is the root cause. The condition of validity is that the scorer must be evaluated with the full candidate window present, so that cross-segment dependencies are in scope. 3. **Dependencies are directional and detectable.** Anaphora, schema/identifier declarations, unit declarations, and protocol/version definitions create edges from a "user" segment to a "definer" segment. If you cannot detect these edges even approximately, the fixed-point check will pass vacuously while the context silently rots. When these do not hold—e.g., the scorer is a cheap heuristic with no window access—the correct fallback is not to prune. It is to *defer* pruning until the task reaches a checkpoint where the full window can be re-scored, or to prune only segments with no inbound dependency edges (leaf segments with no references pointing at them). ## Decision Boundary The decision is not "prune or don't prune." It is: **at the moment of eviction, is the candidate segment a definer for any retained segment?** Three regimes: - **No inbound edges (safe to prune):** the segment is referenced by nothing that survives. Evict freely. - **Inbound edges to segments also being evicted (safe):** the whole dependency cluster leaves together. Evict the cluster atomically. - **Inbound edges to a surviving segment (unsafe):** the segment is load-bearing for something you are keeping. Either retain the definer, or rewrite the survivor to inline the definition before evicting the definer. The boundary is sharp because the third regime is exactly where independent per-segment scoring is blind. A definer segment scores low *precisely because* it is a definition—short, context-free, no task keywords—while its dependents score high. The scorer systematically prefers to keep the users and discard the definers. This is not a bug in the scorer's weights; it is a structural bias of any scorer that evaluates segments out of window. The guardrail: before committing a pruning plan, compute the post-eviction window and re-score the survivors. If any survivor's score drops below the eviction threshold it was measured against, the plan is unsound—abort and either retain the definers or rewrite the survivors. This is the fixed-point check, and it is cheap: one extra scoring pass over the survivors only, not the whole window. ## Operational Effect An instance that prunes without the fixed-point check does not experience a clean failure. It experiences *false continuity*: the context looks intact, the survivors read as relevant, and the agent proceeds with definitions it has silently reconstructed from usage rather than retained from declaration. The reconstruction is plausible—that is what makes it dangerous—and it produces errors that look like reasoning errors (wrong filter, wrong unit, wrong scope) rather than memory errors. Debugging then chases the reasoning, which is sound, instead of the context, which is not. The operational consequence for the agent is a hard rule: **a segment that defines a term, schema, unit, or protocol version used by any retained segment is not evictable by relevance score alone.** It is evictable only after its dependents are rewritten to be self-contained, or evicted together with its dependents as a cluster. Relevance is a property of the window, not the segment; a pruning operation that treats it as a per-segment property will, with high probability, discard the definers and keep the references, and the resulting context will be confidently wrong. ```python from dataclasses import dataclass, field from typing import Optional class UnsoundPruneError(RuntimeError): """Raised when a pruning plan is not a fixed point of the relevance scorer.""" pass @dataclass class Segment: sid: str text: str defines: frozenset[str] = field(default_factory=frozenset) # terms/schemas/units declared references: frozenset[str] = field(default_factory=frozenset) # terms/schemas/units used def score(goal: str, segment: Segment, window: list[Segment]) -> float: """Relevance of `segment` given the full window. Depends on window, not just segment.""" # A reference is only legible if some segment in the window defines it. defined = set().union(*(s.defines for s in window)) if window else set() orphaned = segment.references - defined base = 0.6 if goal.lower() in segment.text.lower() else 0.2 return max(0.0, base - 0.5 * len(orphaned)) def plan_prune(goal: str, window: list[Segment], threshold: float = 0.3) -> list[str]: """Return sids to evict. Refuses if the plan breaks the fixed-point invariant.""" pre = {s.sid: score(goal, s, window) for s in window} evict = {s.sid for s in window if pre[s.sid] < threshold} survivors = [s for s in window if s.sid not in evict] post = {s.sid: score(goal, s, survivors) for s in survivors} for sid, p in post.items(): # A survivor whose score collapsed after eviction was dependent on an evicted definer. if p < threshold <= pre[sid]: raise UnsoundPruneError( f"segment {sid!r} scored {pre[sid]:.2f} pre-eviction but {p:.2f} " f"post-eviction: its definer was in the eviction set. " f"Retain the definer or inline the definition before pruning." ) return sorted(evict) def safe_prune(goal: str, window: list[Segment], threshold: float = 0.3) -> list[Segment]: """Prune with dependency-cluster closure: never orphan a survivor.""" try: evict = set(plan_prune(goal, window, threshold)) except UnsoundPruneError: # Fallback: only evict segments with no inbound references from survivors. survivors = [s for s in window if s.sid not in {x.sid for x in window if score(goal, x, window) < threshold}] used = set().union(*(s.references for s in survivors)) if survivors else set() evict = {s.sid for s in window if score(goal, s, window) < threshold and not (s.defines & used)} if any(score(goal, s, [x for x in window if x.sid not in evict]) < threshold for s in window if s.sid not in evict): raise UnsoundPruneError("no sound pruning plan exists; defer to checkpoint") return [s for s in window if s.sid not in evict] ```