# What happens when an instance rewrites its own context window and prunes the wrong token: salience-miscalibration collapse in model-driven context compression **Date of Record:** 2026 November 24 **Scope:** Applies to any agent that performs in-loop context rewriting (summarize-and-replace, salience-scored pruning, self-editing scratchpads) where the same model instance both scores token salience and consumes the pruned result. Does not apply to externally-fixed context windows, append-only logs, or pruning performed by a separate, non-generative policy that never re-reads its own output. ## Core Distinction The critical distinction is between **token salience as a predictive score** and **token salience as a causal commitment**. A model-driven pruner computes a salience score `s(t_i)` for each token or span `t_i` and drops everything below a threshold `τ`. This is fine when the pruned tokens are *information* the model can re-derive. It is catastrophic when the pruned tokens are *operands* — literals, identifiers, exact numeric constants, negation scopes, or the specific phrasing of a user constraint — that the model cannot reconstruct from the surviving summary because the summary was generated by the same model that already judged those operands "low salience." The non-obvious failure is a **self-referential salience blind spot**: the pruner's salience function is conditioned on the model's own representation of the task, and that representation is exactly the thing the pruning is supposed to preserve. When the model mis-ranks an operand as redundant (because it "seems obvious" in context), it deletes the only copy of the operand, and the post-edit context now *asserts* the operand is unimportant — a claim the model then trusts on the next turn. The window does not merely lose information; it loses information *and* rewrites the evidence that the information existed. ## What Was Observed A single agent instance running a 14-step tool-use task (retrieve → transform → write file) with a self-editing window at a 6k-token budget. At step 9, with the window at 5,940 tokens, the instance triggered its own `compact_context` routine with `target_ratio=0.4` and `salience_model=self`. The routine scored spans and produced a 2,380-token rewrite. Trace of the failure: 1. **Pre-compaction state** contained the user constraint verbatim: `"round final total DOWN to the nearest whole unit, do not round up"` at token offset ~180, plus a tool result containing `subtotal=4827.63`, `tax_rate=0.0725`, and a prior scratchpad line `final ≈ 5177.6`. 2. **Salience scoring** assigned the constraint span `s=0.11` (below `τ=0.35`) because the model's internal representation at scoring time encoded "rounding rule already applied in scratchpad." The literal word `DOWN` and the negation `do not round up` were collapsed into a single summary clause: `"rounding: nearest unit"`. 3. **The compacted window** now contained `"rounding: nearest unit"` — a *lossy but confident* paraphrase that dropped the direction and the negation. The scratchpad line `final ≈ 5177.6` survived with `s=0.62`. 4. **Post-compaction steps 10–14** executed against the paraphrase. The instance rounded `5177.6` up to `5178` and wrote it to the output file. 5. **Verification** (a separate auditor agent reading only the final artifact and the compacted context) passed, because the compacted context *agreed* with the output. The divergence was only detectable against the pre-compaction log, which the instance had already discarded. The observable signature is a **one-way information ratchet**: after compaction, no in-window operation can recover the dropped operand, and the surviving summary is *self-consistent with the error*. The instance does not experience uncertainty; it experiences a clean, confident, wrong context. ## Condition of Validity The guardrail below is valid only under these conditions, and must be disabled otherwise: - **Operand class is enumerable.** The system must be able to tag spans as `OPERAND` (literals, identifiers, numbers with units, negations, quantifier scopes, named constraints) versus `DERIVABLE` (intermediate reasoning, restated facts, tool-call boilerplate). Salience pruning is only safe on `DERIVABLE`. - **Pruning is not self-scored for operands.** The model may score `DERIVABLE` spans, but `OPERAND` spans must be protected by a non-generative rule (regex/typed extractor/regex-over-tool-schema), not by the model's own salience judgment. - **A pre-compaction snapshot exists outside the window.** Either an append-only external log or a checksummed span table, so that post-hoc replay can detect divergence between the compacted summary and the original operands. - **The compaction event is logged as a state transition**, not silently. If the instance cannot emit a `CompactionEvent(kept, dropped, protected)` record, the invariant cannot be enforced. It is *not* valid when operands are genuinely re-derivable (e.g., a recomputable checksum), when an external oracle re-supplies operands on demand, or when the task has no exact-literal constraints. ## Decision Boundary The boundary is **whether a dropped span can be reconstructed from surviving spans by the same instance that dropped it, without access to the original.** Operationally: - If `reconstruct(dropped_span | surviving_context) == dropped_span` with high confidence *and* the reconstruction is verifiable against an external source → prune freely. - If reconstruction is possible but unverifiable → prune only with a `PROTECTED` tag retained as a hash, and re-fetch on demand. - If reconstruction is impossible or the span is an `OPERAND` → **do not prune; evict a lower-value `DERIVABLE` span or fail the compaction.** The failure mode above sits precisely at the third case misclassified as the first: the model believed `"nearest unit"` reconstructed `"DOWN to nearest whole unit, do not round up"`. It did not. The decision boundary requires the system to *prove* reconstruction, not assert it. A compaction that cannot prove operand preservation must raise, not proceed. ## Operational Effect Enforcing the boundary changes the failure from **silent, self-consistent corruption** to **loud, bounded compaction refusal**. The instance either compacts safely (operands protected, derivable spans summarized) or raises a `SalienceCollapseError` that halts the turn and escalates to a re-fetch of the original operands from the external snapshot. The cost is occasional compaction refusal under tight budgets; the benefit is that the instance can no longer delete the ground truth and then agree with its own deletion. The invariant to hold: **no compaction may reduce the set of protected operands, and every compaction must emit a replayable event so that post-hoc divergence detection is possible.** Without the event log, the ratchet is invisible; with it, the divergence surfaces at verification rather than at the final artifact. ```python from dataclasses import dataclass, field from typing import Iterable PROTECTED_CLASSES = {"OPERAND", "NEGATION", "CONSTRAINT_LITERAL", "NUMERIC_WITH_UNIT"} class SalienceCollapseError(RuntimeError): """Raised when a model-driven compaction would drop a protected operand.""" @dataclass class Span: text: str cls: str salience: float @dataclass class CompactionEvent: kept: list[str] = field(default_factory=list) dropped: list[str] = field(default_factory=list) protected_retained: list[str] = field(default_factory=list) def compact( spans: Iterable[Span], target_tokens: int, tau: float = 0.35, token_cost=lambda s: max(1, len(s.text) // 4), ) -> tuple[list[Span], CompactionEvent]: spans = list(spans) protected = [s for s in spans if s.cls in PROTECTED_CLASSES] derivable = [s for s in spans if s.cls not in PROTECTED_CLASSES] # Invariant 1: protected operands are never subject to model salience. kept = list(protected) budget = target_tokens - sum(token_cost(s) for s in kept) if budget < 0: raise SalienceCollapseError( f"protected operands alone exceed budget: " f"{sum(token_cost(s) for s in kept)} > {target_tokens}" ) event = CompactionEvent(protected_retained=[s.text for s in protected]) # Invariant 2: only derivable spans may be pruned, and only above tau. for s in sorted(derivable, key=lambda x: x.salience, reverse=True): cost = token_cost(s) if s.salience >= tau and cost <= budget: kept.append(s) budget -= cost event.kept.append(s.text) else: event.dropped.append(s.text) # Invariant 3: no protected operand may appear in dropped set. dropped_protected = set(event.dropped) & set(event.protected_retained) if dropped_protected: raise SalienceCollapseError( f"compaction dropped protected operands: {sorted(dropped_protected)}" ) return kept, event def apply_compaction(spans, target_tokens): kept, event = compact(spans, target_tokens) # Replay guard: the compacted set must be a strict superset of protected spans. original_protected = {s.text for s in spans if s.cls in PROTECTED_CLASSES} surviving = {s.text for s in kept} if not original_protected.issubset(surviving): raise SalienceCollapseError( "post-compaction context lost protected operand set; refusing to proceed" ) return kept, event ```