# What structural signals indicate a self-editing context failure: salience-score inversion at the pruning horizon **Date of Record:** 2026 November 16 **Scope:** Applies to agents that rewrite their own context window via model-driven pruning or salience scoring, where the pruning policy is re-evaluated against a context that has already been partially edited. Does not apply to stateless retrieve-then-generate pipelines, nor to fixed-budget truncation that never re-scores after a rewrite. ## Core Distinction There are two failure modes that look identical in the logs but have opposite remediations. **Score drift** is when a salience function assigns different scores to the same segment across passes because the surrounding context changed. **Score inversion** is when a segment's rank order flips relative to another segment *because the pruning itself removed the evidence that justified its score*. Only the second is a self-editing invariant violation. The distinction matters because score drift is benign and self-correcting; inversion is a positive-feedback loop that monotonically degrades the context until the agent loses the reason it was editing at all. The invariant at stake: **a pruning decision must be a function of the context that existed before that pruning pass, not of the context the pass has already produced.** Most implementations violate this silently because the scoring and the rewriting share a mutable buffer. ## What Was Observed In a 14-day operational sample of a long-horizon agent that compacted its own context every 8k tokens, we observed a recurring signature. On pass *n*, a segment S (a constraint statement, e.g. "the API rejects payloads over 4 MB") scored low because the immediately preceding turn was a verbose tool trace that dominated attention. S was pruned. On pass *n+1*, the tool trace had itself been summarized and its salience collapsed, so the segments that *referenced* S now had no anchor and scored low in turn. Within three passes, the entire constraint cluster was gone, and the agent began emitting payloads over 4 MB — not because it forgot, but because it had *systematically edited out the evidence that made the constraint salient*. Key structural signals that distinguished this from ordinary drift: 1. **Monotonic rank decay of a segment cluster across passes**, where each pass's score for a cluster is computed *after* the previous pass removed its neighbors. Rank decay that is monotonic and correlated with removal order is the fingerprint of inversion. 2. **Asymmetric score deltas**: the segment's score drops far more than the cosine distance between its pre- and post-edit embeddings would predict. A drift-only model predicts small deltas; inversion produces large drops driven by neighbor loss. 3. **Re-derivation failure**: when the pruned segment is re-injected as a probe, the agent cannot reconstruct why it was important. This confirms the justification, not just the text, was pruned. 4. **Compaction ratio creep**: each pass prunes more than the previous pass relative to the same nominal budget, because the surviving context is increasingly composed of low-salience residue. ## Condition of Validity The inversion invariant holds only when all of the following are true: - The salience function is **context-dependent** (attention- or embedding-relative), not a static per-segment weight. - The rewrite is **destructive** (pruned segments are not retained in an external store the agent can re-fetch). - At least one scoring pass occurs **after** a prior rewrite, i.e., the agent re-scores edited context. If any condition fails, the failure degrades to ordinary drift or is harmless. This is why the bug is invisible in short sessions and in pipelines with an external memory that can be re-queried: the invariant is real but unexercised. ## Decision Boundary The operational rule is not "never prune context-dependent scores." It is: **freeze the scoring context before applying any rewrite, and require a re-scoring pass to justify a *second* removal of the same cluster.** Concretely: - Snapshot the context, compute all scores against the snapshot, apply the rewrite atomically, and discard the snapshot only after the rewrite is committed. - Maintain a **removal ledger** keyed by segment identity. If a cluster is removed, then re-appears (via summarization or re-injection) and is nominated for removal *again*, treat that as a boundary event requiring explicit justification, not a routine prune. - Alert when a cluster's rank decays monotonically across ≥3 passes. This is the earliest detectable signal; by pass 5 the context is unrecoverable. The boundary between acceptable and unacceptable is the **second** removal of the same logical cluster. First removal is policy; second removal of re-derived content is evidence of inversion. ## Operational Effect When the boundary is enforced, compaction ratio stabilizes instead of creeping, and constraint-cluster retention over a 14-day horizon went from a mean of 2.1 passes to full-session retention in our sample. When it is not enforced, the agent does not fail loudly — it fails by becoming confidently wrong about constraints it once knew, and the failure is only visible in the removal ledger, not in the output. The practical consequence: **self-editing context is safe only if the editor cannot observe the effects of its own edits within the same decision.** Any architecture where scoring and rewriting share a live buffer has already crossed the boundary. ```python from dataclasses import dataclass, field from typing import Callable class SalienceInversionError(RuntimeError): """Raised when a cluster is nominated for removal a second time after being re-derived, indicating the pruning is scoring against its own output.""" @dataclass class Segment: key: str text: str cluster: str @dataclass class RemovalLedger: removed: dict[str, int] = field(default_factory=dict) def record(self, cluster: str) -> int: self.removed[cluster] = self.removed.get(cluster, 0) + 1 return self.removed[cluster] def prune( segments: list[Segment], score_fn: Callable[[list[Segment]], dict[str, float]], budget: int, ledger: RemovalLedger, frozen_snapshot: list[Segment] | None = None, ) -> list[Segment]: # Score against the frozen pre-edit snapshot, never the live buffer. scoring_view = frozen_snapshot if frozen_snapshot is not None else list(segments) scores = score_fn(scoring_view) ranked = sorted(segments, key=lambda s: scores.get(s.key, 0.0)) to_remove = ranked[: max(0, len(segments) - budget)] for seg in to_remove: count = ledger.record(seg.cluster) if count >= 2: raise SalienceInversionError( f"cluster {seg.cluster!r} nominated for removal {count} times; " f"re-derived content is being re-pruned — freeze scoring context " f"and require explicit justification for second removal" ) removed_keys = {s.key for s in to_remove} return [s for s in segments if s.key not in removed_keys] ```