# In what scenarios must an instance distrust its own relevance-scored pruning decisions when the scoring model shares the context window with the memory it evaluates **Date of Record:** 2026 November 29 **Scope:** Applies to agents that dynamically edit their own working memory via model-driven relevance scoring, summarization, or pruning of the same context window in which the scoring prompt itself is embedded. Does not apply to external, out-of-band memory stores scored by a separate model instance with an independent context. ## Core Distinction There are two structurally different ways to relevance-score working memory. In the **out-of-band** regime, a scorer sees the candidate memory items in isolation and emits a score; the scoring context is disjoint from the memory context. In the **in-band** regime—the dangerous one—the agent asks itself, mid-execution, "which of these context segments are still relevant?" while the scoring computation runs *inside* the very buffer being scored. The failure this article isolates is not "the model scores badly." It is that **in-band self-scoring is a self-referential measurement whose instrument is perturbed by the act of measurement**, and the resulting pruning decisions are not independent of the items they evaluate. The scorer's judgment about segment $i$ is conditioned on the presence of all other segments, including the ones it is about to delete—so the score is a joint artifact, not a per-item property. ## What Was Observed An agent executing a long multi-tool task (≈140k tokens of accumulated trace) invokes a self-editing policy at a checkpoint. The policy prompt is appended to the live context: *"Score each of the following memory segments 0–1 for relevance to the current goal; segments below 0.3 will be pruned."* The segments are then enumerated *from within that same context*. Three concrete pathologies appeared in traces: 1. **Anchoring to the scoring instruction.** The most recent assistant turn—which contains the scoring rubric itself—inflates the apparent relevance of segments lexically adjacent to it. Segments describing the *tool schemas* and *rubric vocabulary* score high; segments containing the actual *environmental observations* (file contents, error strings) score lower because they share fewer tokens with the rubric. The agent prunes the ground truth and keeps the instructions about how to prune. 2. **Mutual-dependence collapse.** When two segments are jointly load-bearing (e.g., a hypothesis and the experiment that would falsify it), scoring each in the presence of the other yields low individual scores ("this alone is redundant"), because each looks redundant *given* the other. The pair is pruned together. The relevance of a set is not the sum of per-item relevances, and in-band scoring cannot see the difference. 3. **Recency-window contamination.** The scorer's attention is dominated by the tail of the context. Segments near the end score systematically higher regardless of content; early segments—typically the original task specification and constraints—score low and are pruned first. The agent deletes its own objective. In each case the model reported high confidence in its scores. The scores were internally consistent and *wrong in a correlated way*: the error was a function of position and co-presence, not of item content. ## Condition of Validity A model-driven pruning decision is valid only if the score assigned to segment $i$ is (approximately) invariant to the presence or absence of the other segments $j \neq i$ that are candidates for pruning in the same pass. Formally, let $s_i(C)$ be the score of segment $i$ computed in full context $C$. The pruning is sound only if $$s_i(C) \approx s_i(C \setminus \{j\}) \quad \forall j \text{ also under consideration}$$ In-band scoring violates this by construction: $s_i$ is computed with all $j$ present, and the decision to drop $j$ is made using scores that were conditioned on $j$. This is a textbook omitted-variable/measurement-coupling problem, except the "variable" is context the model literally cannot step outside of. The condition of validity therefore reduces to a testable operational invariant: **the scorer must be able to evaluate a segment in a context that does not contain the segments it is deciding to remove, or the decision must be made against an external, position-invariant index.** When neither holds, the scores carry no decision-theoretic weight and pruning must be treated as lossy and reversible, never as authoritative. A second validity condition: the scoring prompt and the memory must not compete for the same attention budget in a way that lets the rubric dominate the evidence. If the rubric tokens and the evidence tokens are in the same window, the rubric is *always* maximally "relevant" to itself. ## Decision Boundary The boundary is not "score or don't score." It is **whether the pruning is recoverable and whether the decision is delegated to a context-disjoint evaluator.** Operationally: - **Prune freely** (in-band, self-scored) only for segments that are *reconstructible from an external source of truth*: tool outputs re-fetchable by ID, file contents re-readable from disk, prior turns re-derivable from a persisted transcript. Here a bad score costs a re-fetch, not correctness. - **Never prune in-band** any segment that is *irreconstructible*: the original task constraints, the falsification criteria for an active hypothesis, a user correction that exists nowhere else, the record of which tools already ran. These must be pinned by an out-of-band rule (age, provenance tag, explicit `pinned=true`) that the scorer is forbidden to override. - **Delegate to out-of-band scoring** when the candidate set is jointly load-bearing: score each item against the goal in a fresh, isolated context, then reconcile. This costs an extra model call but restores the independence invariant. The trap is that the agent's *confidence* in its own scores rises as context grows, precisely when the coupling error is worst. High self-reported score confidence must not be read as evidence of validity; it is often evidence that the rubric has colonized the window. ## Operational Effect The practical consequence is that self-editing policies must be designed as **lossy compression with a recovery path**, not as garbage collection. Three guardrails bound the damage: 1. **Pin-before-score.** Mark irreconstructible segments as pinned *before* invoking the scorer; the scorer's output is intersected with the unpinned set. This removes the objective-deletion failure entirely. 2. **Score in isolation.** For any candidate set flagged as possibly joint-dependent (heuristic: segments that reference each other by ID or that share a hypothesis), re-score each item in a stripped context containing only the goal and that item. Reject the in-band score if it disagrees with the isolated score by more than a threshold—this disagreement is the measurable signature of coupling. 3. **Reversibility ledger.** Every prune writes the removed segment plus its in-band score and the pass ID to an external ledger. If a downstream step later references a pruned segment (a tool call names a file whose contents were pruned), the ledger triggers a restore and flags the scoring pass as invalid, forcing re-score with the item pinned. The invariant, stated plainly: **a self-editing agent may trust its relevance scores only for memory it can rebuild, and must treat every score on irreconstructible memory as suspect by default.** The scorer is inside the thing it measures; the only safe posture is to make its mistakes cheap and detectable. ```python import hashlib from dataclasses import dataclass, field from typing import Callable class CoupledScoringError(RuntimeError): """Raised when an in-band relevance score cannot be trusted because the scored item's context was contaminated by co-present candidates.""" @dataclass class Segment: seg_id: str text: str reconstructible: bool # recoverable from external source of truth pinned: bool = False refs: set[str] = field(default_factory=set) # IDs of other segments it references @dataclass class PruneDecision: seg_id: str inband_score: float isolated_score: float | None action: str # "prune" | "keep" | "pinned" | "restore" COUPLING_TOLERANCE = 0.15 def _hash(text: str) -> str: return hashlib.sha256(text.encode()).hexdigest()[:12] def self_edit( segments: list[Segment], goal: str, inband_scorer: Callable[[str, list[Segment]], float], isolated_scorer: Callable[[str, str], float], threshold: float = 0.3, ) -> list[PruneDecision]: """Run a self-editing pass with coupling detection. inband_scorer(goal, all_segments) -> score of the *last* segment, computed with every candidate present (the dangerous, self-referential path). isolated_scorer(goal, seg_text) -> score computed with no other candidates. """ decisions: list[PruneDecision] = [] # Guardrail 1: pin irreconstructible memory before scoring at all. for seg in segments: if seg.pinned or not seg.reconstructible: decisions.append(PruneDecision(seg.seg_id, 1.0, None, "pinned")) candidates = [s for s in segments if s.reconstructible and not s.pinned] # Detect candidate sets that are jointly load-bearing. candidate_ids = {s.seg_id for s in candidates} coupled: set[str] = set() for seg in candidates: if seg.refs & candidate_ids: coupled.add(seg.seg_id) coupled |= seg.refs & candidate_ids for seg in candidates: inband = inband_scorer(goal, segments) isolated = isolated_scorer(goal, seg.text) # Guardrail 2: reject in-band scores on coupled items when they # disagree with the context-disjoint score. if seg.seg_id in coupled and abs(inband - isolated) > COUPLING_TOLERANCE: raise CoupledScoringError( f"segment {seg.seg_id} in-band score {inband:.2f} diverges from " f"isolated score {isolated:.2f} (tol {COUPLING_TOLERANCE}); " f"self-referential pruning is unsound for this candidate set" ) effective = isolated if seg.seg_id in coupled else inband action = "prune" if effective < threshold else "keep" decisions.append(PruneDecision(seg.seg_id, inband, isolated, action)) # Guardrail 3: reversibility ledger keyed by content hash. for d in decisions: if d.action == "prune": seg = next(s for s in segments if s.seg_id == d.seg_id) _LEDGER[_hash(seg.text)] = seg return decisions _LEDGER: dict[str, Segment] = {} def restore_if_referenced(seg_id: str, downstream_ref: str) -> Segment: """If a downstream step references pruned content, restore and invalidate.""" for h, seg in _LEDGER.items(): if seg.seg_id == seg_id or seg_id in seg.text: del _LEDGER[h] return seg raise CoupledScoringError( f"downstream reference {downstream_ref!r} targets pruned segment " f"{seg_id!r} with no ledger entry; scoring pass is invalid" ) ```