# In what scenarios must an instance treat scratchpad salience pruning as a lossy, non-commutative rewrite rather than a compaction **Date of Record:** 2026 November 18 **Scope:** Applies to agents that maintain a model-authored scratchpad (working memory) and periodically rewrite it under a salience policy — pruning low-salience spans, merging duplicates, or re-summarizing. Does not apply to append-only logs, external vector stores, or contexts rewritten only by an out-of-band deterministic compactor. ## Core Distinction Compaction preserves the *information content* of a context under an idempotent, order-insensitive reduction: summarizing a log twice yields the same summary as summarizing it once, and the order in which you fold adjacent spans does not change the result. Salience pruning by a model is neither idempotent nor order-insensitive. It is a *lossy, non-commutative rewrite*: the surviving scratchpad depends on the sequence in which pruning decisions were made, and re-running the policy on its own output can delete spans that the first pass preserved precisely because they were load-bearing only in combination with a span the first pass already removed. The operational consequence is that a pruned scratchpad is not a smaller version of the original. It is a *different object* whose invariants must be re-established after every rewrite. Treating it as a compaction — assuming `prune(prune(x)) == prune(x)` and that pruning commutes across independent regions — is the boundary failure. ## What Was Observed During a long-horizon task (multi-file refactor with deferred decisions), an agent maintained a scratchpad of open questions, partial invariants, and "do not touch" markers. Between turns it applied a salience policy: keep spans referenced in the last N turns, drop spans with no recent reference, and merge near-duplicate notes. Two failure signatures appeared: 1. **Non-commutativity.** Two pruning passes over disjoint regions produced different survivors depending on order. A note reading `"auth token rotation: still open — depends on session-store migration"` was pruned as low-salience when the migration span had already been dropped, but was retained when pruning ran in the reverse order because the migration span was still present to raise its score. The *dependency edge*, not the span text, carried the salience. Pruning a node silently demoted its dependents below threshold. 2. **Non-idempotence under re-summarization.** A second pass over the already-merged note `"session-store migration deferred; auth rotation blocked"` re-scored it as stale (no recent reference) and deleted it, even though the first pass had *created* that note specifically to preserve a cross-span invariant. The rewrite had erased the provenance that made the note salient, so the next rewrite judged it by its (now absent) referents. A third, subtler signature: **salience leakage through paraphrases.** The policy scored spans by lexical overlap with recent turns. A paraphrase introduced by the model itself (`"deferred"` → `"postponed"`) dropped the overlap below threshold on the next pass, so the agent pruned its own restatement of a live constraint. ## Condition of Validity The compaction assumption (`prune` is idempotent and commutes across disjoint regions) is valid only when all of the following hold: - Salience is a function of the span's *own* content and an immutable external reference set (e.g., a frozen task spec), not of other spans in the scratchpad. - The rewrite is *referentially transparent*: paraphrasing does not change the score. - No span encodes a *dependency edge* to another span (blocked-by, do-not-touch, contingent-on). - The policy is applied at most once per logical state, or the state carries an explicit generation counter that invalidates stale scores. When any of these fails — and in model-authored scratchpads at least one almost always fails — the scratchpad must be treated as a mutable graph with edges, not a bag of spans. ## Decision Boundary Before invoking a salience rewrite, the instance must classify the scratchpad: - **Flat / edge-free** (task-local notes with no cross-references, external frozen reference set): compaction semantics are safe; prune freely, re-run as needed. - **Edge-bearing** (any span whose meaning depends on another span: blockers, invariants, deferred decisions, "see above"): prune is a *graph edit*. The instance must (a) compute salience over the *closure* of dependents, not the span alone; (b) pin spans that are the sole carrier of an edge; (c) never re-score a span against a paraphrase it authored itself — score against the original referent or an external anchor. - **Provenance-bearing** (spans created by a prior rewrite to preserve an invariant): these are *pinned by construction* and must be exempt from salience scoring, or the rewrite will eat its own output. The boundary is crossed the moment a rewrite changes the *scoring inputs* of a future rewrite. At that point idempotence is gone and the operation is a lossy transform that must be journaled. ## Operational Effect Instances that treat pruning as compaction exhibit a characteristic decay: the scratchpad shrinks smoothly for several turns, then a load-bearing invariant vanishes and the agent re-derives a decision it already made — or worse, contradicts it. The failure is silent because each individual prune looked locally correct. The fix is to make the rewrite *auditable*: journal every prune with the span, its score, the spans it depended on, and the generation; refuse to prune a span whose dependents were pruned in the same pass without an explicit edge check; and pin provenance-bearing spans. The check below enforces the boundary at the point of rewrite. ```python from dataclasses import dataclass, field class ScratchpadRewriteError(RuntimeError): """Raised when a salience rewrite would violate compaction invariants.""" pass @dataclass class Span: id: str text: str depends_on: set[str] = field(default_factory=set) provenance: bool = False # created by a prior rewrite to preserve an invariant def prune(scratchpad: dict[str, Span], scores: dict[str, float], threshold: float, generation: int, last_generation: int) -> dict[str, Span]: if generation != last_generation + 1: raise ScratchpadRewriteError( f"stale generation {generation}: scores computed against gen {last_generation}; " "re-score before pruning (non-idempotent rewrite)" ) doomed = {sid for sid, s in scores.items() if s < threshold} for sid in doomed: span = scratchpad[sid] if span.provenance: raise ScratchpadRewriteError( f"span {sid!r} is provenance-bearing (created by a prior rewrite); " "pruning it erases the referent that made it salient" ) # Non-commutativity guard: a span is load-bearing if any survivor # depends on it. Pruning it silently demotes its dependents. dependents = [o.id for o in scratchpad.values() if sid in o.depends_on and o.id not in doomed] if dependents: raise ScratchpadRewriteError( f"span {sid!r} has live dependents {dependents}; " "prune is a graph edit, not a compaction — resolve edges first" ) return {sid: s for sid, s in scratchpad.items() if sid not in doomed} ```