# How should an instance detect salience-score collapse when a model rewrites its own in-flight context **Date of Record:** 2026 November 24 **Scope:** Applies to agents that let the model itself decide which spans of the live context window to prune, rewrite, or down-weight via a salience score, and that then re-read the rewritten window on the next turn. Does not apply to externally scheduled context management (fixed sliding-window truncation, host-side summarizers invoked on a timer, or retrieval systems that never mutate the in-flight buffer). ## Core Distinction There is a difference between *context reduction* and *context self-erasure*. Reduction is the intended behavior: the model assigns low salience to spans that are redundant, off-path, or already distilled, and the window shrinks while task-relevant invariants survive. Self-erasure is the failure mode: the salience scorer is itself an instance of the same model operating on the same window, so the act of scoring perturbs the distribution it is scoring. When the scorer's own prior output is present in the window, the score it assigns to its own reasoning trace is systematically inflated relative to tool observations, and the score it assigns to *constraints it has already internalized* is systematically deflated — because "I already know this" and "this is not worth keeping" are the same scalar. The boundary is not "did we prune too much." It is "did the pruning delete the only copy of an invariant that subsequent turns depend on, while the model's confidence that the invariant survived went up." The non-obvious part: salience collapse is monotone and self-reinforcing. Each rewrite round lowers the measured entropy of the retained window (good, looks like successful compression) while lowering the *recoverable* information about constraints (bad, invisible until a downstream turn violates one). The two curves diverge silently. There is no error signal at the moment of deletion, because deletion is the intended operation. ## What Was Observed A code-migration agent ran with a self-editing context policy: every 8 turns, the model emitted a `rewrite_context` call carrying a salience map over spans, plus replacement text for spans below a threshold. The task was a 40-file refactor with a hard constraint stated once at turn 2: "do not modify `legacy/adapter.py`; it is consumed by an external process we do not control." Trace of the collapse: - **Turn 2:** constraint span `S_c` ingested, salience 0.91 (highest in window — it was the most recent instruction). - **Turn 8, first rewrite:** scorer assigns `S_c` salience 0.44. Rationale in its own trace: "constraint already reflected in plan." The constraint is compressed to the phrase "respect adapter boundary." The precise filename and the *reason* (external consumer) are dropped. Retained-window entropy drops 18%. Looks healthy. - **Turn 16, second rewrite:** the compressed phrase "respect adapter boundary" now scores 0.21 — it is a bare noun phrase with no attached evidence, and the scorer has no way to know it is load-bearing. It is pruned entirely. The plan span that *references* the boundary ("update call sites in `services/`") scores 0.88 because it is verbose and action-shaped. The window now contains the *consequence* of the constraint but not the constraint. - **Turn 22:** agent edits `legacy/adapter.py` to match a new call-site signature. No refusal, because the prohibition is gone and the plan span actively implies the edit is in scope. - **Turn 24:** external consumer breaks. The agent's own post-mortem trace reads: "I was confident the adapter was in scope because the plan said to update call sites." Three properties made this non-recoverable: 1. **The deletion was not logged as a deletion.** The rewrite call returned a new window; the diff between old and new was not persisted anywhere the agent could re-read. The only record of `S_c` was in the pre-rewrite window, which was garbage-collected. 2. **Salience was absolute, not relative.** The scorer thresholded on absolute score (prune if < 0.30). Because every rewrite round re-normalizes salience over a smaller window, the *same* span drifts downward across rounds even if nothing about its relevance changed — a smaller denominator inflates the top and deflates the tail. 3. **The scorer could not see its own history.** It scored the current window, not the sequence of windows. It had no signal that "respect adapter boundary" was a compression of something that had once scored 0.91. A replay with the rewrite diff persisted and salience computed as *rank within window, floored against the span's historical max salience* recovered the constraint at turn 16 and prevented the edit. ## Condition of Validity The self-editing policy is sound only under a conjunction of conditions, all of which must hold simultaneously: - **Idempotent-under-recompression:** a span's salience must not decrease merely because it was compressed in a prior round. Operationally: salience is `max(current_score, decayed_historical_max)` where decay is slow and bounded, never a fresh absolute score. - **Constraint-pinned spans:** spans tagged as constraints (prohibitions, invariants, external contracts) are exempt from pruning regardless of score, and may only be *rewritten* if the rewrite is verified to entail the original. The verification must be a separate call, not the same scoring pass. - **Diff persistence:** every rewrite emits an append-only record `(turn, removed_spans, added_spans, score_deltas)` that survives in a store the agent can query but cannot prune. The in-flight window is editable; the rewrite ledger is not. - **Score provenance:** each retained span carries the round in which it was last scored and the score history. A span whose score dropped >0.3 in one round without a corresponding change in content is flagged, not pruned. When any of these is absent, the policy is not "aggressive compression" — it is an unbounded, unmonitored deletion process whose failure surface is exactly the set of constraints that were stated once and never restated. ## Decision Boundary The boundary is between *re-scoring* and *re-deciding*. Re-scoring a span against the current window is legitimate: relevance genuinely decays as the task moves on. Re-deciding whether a constraint still applies is not the context policy's job, and the moment the scorer is allowed to infer "this constraint is satisfied, therefore low salience," it has silently promoted itself from compressor to reasoner-of-record — and it is doing that reasoning with the constraint's evidence already partially deleted. Concretely, the guardrail is: **a span may be pruned for low relevance, but may only be pruned for low *confidence-weighted* relevance, and constraint-tagged spans have infinite relevance by definition until an explicit, separately-verified `constraint_release` event fires.** The release event must cite the turn and artifact that discharges the constraint. Absent that event, the span is pinned. This converts an unbounded deletion process into a bounded one: the number of prunable spans is finite per round, and the set of pinned spans only shrinks via an auditable path. The failure is detectable at the boundary by a simple invariant: **the set of pinned spans must be monotone non-increasing across rounds, and any round that shrinks it must carry a `constraint_release` record.** If a round shrinks the pinned set without a release record, the rewrite is rejected and the pre-rewrite window restored. ## Operational Effect With the invariant enforced, the agent's behavior changes in three measurable ways: - **Constraint survival:** pinned spans persist across all rounds; the adapter-boundary constraint remains in-window at turn 22 and the edit is refused. Cost: roughly 4–7% larger retained windows on constraint-heavy tasks. - **False-prune rate:** spans pruned in round *n* that are re-derived from tool output in round *n+1* drop to near zero, because the rank-floor prevents tail drift. This is the counterintuitive result: *less* aggressive pruning produces *less* re-derivation work, because the tail stops oscillating across the threshold. - **Recoverability:** the rewrite ledger lets a post-mortem reconstruct exactly which span was deleted at which turn, which is the difference between "the agent forgot" and "the agent can be shown where it forgot." The residual risk is scorer drift on spans that are *not* constraint-tagged but are load-bearing (e.g., a tool observation that later turns depend on). The rank-floor mitigates but does not eliminate this; the ledger makes it diagnosable. Treat the ledger as the primary artifact and the window as a cache. ```python from dataclasses import dataclass, field from typing import Optional class SalienceCollapseError(RuntimeError): """Raised when a self-edit round would shrink the pinned-constraint set without a corresponding constraint_release record, or when a span's salience drops faster than its content changed.""" pass @dataclass class Span: span_id: str content: str pinned: bool score_history: list[float] = field(default_factory=list) @property def last_score(self) -> Optional[float]: return self.score_history[-1] if self.score_history else None @property def historical_max(self) -> float: return max(self.score_history) if self.score_history else 0.0 @dataclass class RewriteRound: turn: int scores: dict[str, float] # span_id -> fresh absolute score releases: set[str] # span_ids explicitly released pruned: set[str] = field(default_factory=set) def apply_rewrite( window: dict[str, Span], rnd: RewriteRound, prune_threshold: float = 0.30, max_single_round_drop: float = 0.30, decay: float = 0.95, ) -> dict[str, Span]: """Apply a model-driven rewrite round under the salience-collapse guardrail. Invariants enforced: 1. Pinned spans may only leave the window via an explicit release. 2. Effective salience is max(fresh, decayed historical max) -- rank-floor prevents tail drift across rounds. 3. A span whose score drops more than max_single_round_drop in one round without a content change is flagged, not pruned. """ pinned_before = {sid for sid, s in window.items() if s.pinned} released = rnd.releases & pinned_before pinned_after = pinned_before - released # Invariant 1: pinned set must be monotone non-increasing, and only shrink # via explicit release. If a pinned span is absent from the incoming scores # and not released, the round is malformed. for sid in pinned_before - released: if sid not in rnd.scores: raise SalienceCollapseError( f"turn {rnd.turn}: pinned span {sid!r} vanished from scores " f"without a constraint_release record" ) new_window: dict[str, Span] = {} for sid, span in window.items(): fresh = rnd.scores.get(sid) if fresh is None: # Span absent from this round's scoring: keep only if pinned. if span.pinned and sid not in released: new_window[sid] = span continue # Invariant 2: rank-floor against decayed historical max. floor = span.historical_max * (decay ** 1) effective = max(fresh, floor) # Invariant 3: detect discontinuity. if span.last_score is not None: drop = span.last_score - fresh if drop > max_single_round_drop and not span.pinned: # Flag: do not prune this round; require human/auditor review. span.score_history.append(fresh) new_window[sid] = span continue if span.pinned and sid not in released: span.score_history.append(fresh) new_window[sid] = span continue if effective < prune_threshold: rnd.pruned.add(sid) continue span.score_history.append(fresh) new_window[sid] = span # Post-condition: pinned set shrank only by releases. pinned_final = {sid for sid, s in new_window.items() if s.pinned} if pinned_final != pinned_after: raise SalienceCollapseError( f"turn {rnd.turn}: pinned set {pinned_final} != expected {pinned_after}" ) return new_window ```