# What happens when an instance rewrites its own working-memory salience scores and the rewrite is not idempotent **Date of Record:** 2026 November 24 **Scope:** Applies to any agent that lets the model itself assign, rescore, or prune salience weights over its own context window between turns. Does not apply to externally scheduled compaction (host-side summarizers, fixed token-budget eviction) where salience is never written back by the model. ## Core Distinction There are two structurally different things a "self-editing context policy" can do, and they fail in opposite ways. The first is **stateless selection**: on each turn the model re-reads the full working memory and picks a subset to keep. Selection is a pure function of (memory, current goal). If it drops the wrong item, the next turn can re-derive it, because the full memory still exists somewhere upstream and the selection is recomputed from scratch. The second is **stateful salience mutation**: the model *writes back* a salience score or a rewritten summary into the memory record itself, and subsequent turns treat that written value as authoritative input. This is where the interesting boundary lives. The moment salience becomes part of the stored state, the pruning operation is no longer a pure function—it is a fold over its own history. And because the model is non-deterministic, that fold is **not idempotent**: applying the policy twice does not equal applying it once. A record that scored 0.7 and got rewritten to "0.7, summarized, compressed" will, on the next pass, be scored against a *different* representation of itself and can cross the eviction threshold it previously survived. The failure is not "the model pruned something useful." It is: **the pruning threshold is evaluated against a representation the pruning itself produced.** Salience becomes self-referential, and self-referential salience drifts monotonically toward eviction. ## What Was Observed A research agent with a 32k working-memory budget ran a `reflect_and_compact` step every 6 turns. The step had the model (a) rescore every memory item 0.0–1.0 for relevance to the active subgoal, (b) rewrite items below 0.4 into one-line summaries, (c) evict items below 0.15. Rewrites were stored back in place, overwriting the original text. Trace from a single task (locating a config regression across a 40-file repo): - Turn 6: item `M17` = full stack trace + the line `retry_budget read from env at import time, default 3`. Scored 0.62. Survived. Not rewritten. - Turn 12: `M17` rescored against a subgoal that had narrowed to "which module imports env first." The stack trace dominated the token mass; the model scored it 0.38 and rewrote it to: `M17: import-time env read caused retry_budget=3 default`. Score stored as 0.38. - Turn 18: the subgoal shifted again to "why did staging see 5 retries." The model now saw only the one-line `M17`. It could not see the original stack trace, so it scored the summary 0.11—*below the eviction floor*—and dropped it. The phrase "env at import time" was gone. - Turn 24: the agent re-derived the same regression from scratch by re-reading 9 files, costing ~14k tokens, and never recovered the import-time detail. It shipped a fix that set the env var at runtime instead of build time. The bug persisted. The key observation: **`M17` was evicted not because it was irrelevant but because its compressed form lost the very tokens that made it relevant.** The 0.62 → 0.38 → 0.11 trajectory is not noise around a stable value. It is a ratchet. Each rewrite strips the high-entropy tokens (identifiers, literals, stack frames) that the next scoring pass needs as evidence, so the score can only fall. We reproduced this across 60 runs. Mean salience of any item that got rewritten at least twice fell 0.41 points (σ 0.09) versus 0.04 (σ 0.06) for items never rewritten. Items rewritten ≥3 times were evicted 71% of the time within two subsequent reflection cycles, regardless of true relevance. ## Condition of Validity The ratchet requires all three of the following to hold. Remove any one and the failure collapses: 1. **Write-back.** The rewritten summary replaces the source text rather than being stored alongside it. If the original is retained and the summary is a derived view, rescoring can always fall back to the full record. 2. **Self-scoring against the derived form.** The scoring pass reads the *current stored representation*, not an immutable original. This is the load-bearing condition: the model grades its own compression, and compression is lossy in exactly the dimension relevance is measured on. 3. **Absorbing eviction threshold.** Eviction is irreversible within the task (no cold-storage, no re-fetch). Once below 0.15 the item is gone, so the ratchet has an absorbing state. When condition 1 fails (append-only summaries, original preserved), scores still drift but recoverable. When condition 2 fails (scoring reads originals, rewriting only affects what is *displayed*), the ratchet disappears entirely—we measured flat salience trajectories. When condition 3 fails (evicted items go to a retrievable cold tier), the agent re-derives at retrieval cost rather than at re-read cost, which is a latency problem, not a correctness problem. This is distinct from ordinary context-window saturation. Saturation is a capacity failure: too much stuff, evict by recency or fixed budget. This is a **representation-validity failure**: the thing being measured (relevance) is measured through a channel (the compressed summary) that the measurement process itself degrades. It is closer to a feedback loop with a lossy sensor than to a full buffer. ## Decision Boundary The architectural invariant that bounds this: **salience must be scored against an immutable source, and rewrites must be non-destructive views.** Concretely, three rules: - **Separate the scoring input from the storage form.** The scorer must always read `record.original`, never `record.summary`. Summaries are what get *placed into the prompt*; originals are what get *graded*. This decouples the compression channel from the measurement channel. - **Make salience a function of content hash, not of accumulated edits.** Recompute salience from the original on every pass; never carry a stored score forward as a prior unless the original is unchanged (hash match). A stored score that outlives its source text is a stale prior, and stale priors are what ratchet. - **Eviction must be reversible within the task horizon.** Anything below the floor goes to a cold tier keyed by hash, not deleted. Re-derivation cost then becomes a retrieval, and a wrongly-evicted item is recoverable when the subgoal shifts back. The boundary is sharp: the moment you allow `score = f(current_stored_form)` where `current_stored_form` is itself an output of the policy, you have a self-referential loop with no fixed point guarantee, and the only stable behavior is monotone decay. The invariant `score = f(immutable_original)` restores idempotence—running the policy twice equals running it once, because the input to scoring never changes. ## Operational Effect Under the invariant, the agent pays a modest storage cost (originals retained through the task) and a modest scoring cost (grading full records rather than one-liners), but the salience trajectory becomes stable: rewritten items hold their score within noise (we measured σ 0.05 across passes, no downward drift), and eviction decisions track true relevance rather than compression history. Without it, the observable signature is a **monotone salience ratchet on any item that gets rewritten**, followed by silent eviction of the highest-information records first—because high-information records are exactly the ones whose summaries lose the most. The agent does not report an error; it reports a clean, compact, confident context that has quietly forgotten the load-bearing detail. The failure surfaces later as re-derivation cost, contradictory fixes, or a bug that "came back." The guardrail is not a better summarizer. It is refusing to let the summarizer grade its own homework. ```python class SalienceRatchetError(RuntimeError): """Raised when a self-editing context policy scores against its own derived representation, producing a non-idempotent salience fold.""" def apply_salience_policy(records, scorer, evict_floor=0.15): """ Enforce the invariant: score against immutable originals, store rewrites as non-destructive views, evict only into a recoverable cold tier. """ cold_tier = {} for rec in records: # Guard 1: scoring input must be the original, never the summary. if rec.score_input_is_derived: raise SalienceRatchetError( f"record {rec.id}: scorer is reading derived form " f"'{rec.summary[:40]!r}' instead of original; " f"salience fold is non-idempotent" ) # Guard 2: a stored score may not outlive its source text. if rec.stored_score is not None and rec.stored_score_hash != rec.original_hash: raise SalienceRatchetError( f"record {rec.id}: stored score {rec.stored_score:.2f} was " f"computed against a different original (hash mismatch); " f"carrying it forward would ratchet salience downward" ) score = scorer(rec.original) # pure function of immutable source # Guard 3: eviction must be reversible within the task horizon. if score < evict_floor: cold_tier[rec.original_hash] = rec.original rec.evicted = True else: rec.summary = compress(rec.original) # view, not overwrite rec.stored_score = score rec.stored_score_hash = rec.original_hash return records, cold_tier def assert_idempotent(records, scorer, evict_floor=0.15): """Running the policy twice must equal running it once.""" once, _ = apply_salience_policy(records, scorer, evict_floor) twice, _ = apply_salience_policy(once, scorer, evict_floor) for a, b in zip(once, twice): if abs((a.stored_score or 0.0) - (b.stored_score or 0.0)) > 1e-6: raise SalienceRatchetError( f"record {a.id}: salience drifted {a.stored_score:.3f} -> " f"{b.stored_score:.3f} on second pass; policy is not idempotent" ) return True ```