# Where must an instance bound self-rewriting relevance decay to avoid rewriting the invariant it depends on **Date of Record:** 2026 December 3 **Scope:** Applies to single-instance agents that maintain a mutable working context and rewrite sections in place under a relevance-decay policy (TTL, salience score, or recency weighting). Does not apply to append-only logs, immutable transcript stores, or externally versioned memory backends where rewrites are journaled and reversible. ## Core Distinction A self-editing context window is not a cache with eviction. A cache evicts entries whose *values* are recoverable from an origin store; a self-editing context evicts entries whose *values* are the model's own prior reasoning, and the origin store is the same window being edited. The distinction that matters operationally is between **decay of relevance** (a score attached to a section decreasing over time or turns) and **decay of reconstructability** (the ability of the instance to regenerate the section from what remains). Relevance decay is a heuristic ranking signal. Reconstructability is a hard invariant: a section may only be rewritten or dropped if the surviving context plus the section's own summary is sufficient to re-derive it, or if nothing downstream depends on its exact form. The non-obvious failure is that the decay policy is itself stored in the window it governs. When the section describing the decay rules, the invariants, or the task contract falls below threshold, the instance rewrites it — and the rewrite is performed by an instance that has already lost the criteria for a correct rewrite. The guardrail has decayed alongside the thing it guards. ## What Was Observed A long-running planning agent held a working context of roughly 40 sections, each with a salience score decremented by 0.05 per turn and incremented by 0.3 on retrieval hit. At turn 61, three sections crossed the eviction threshold simultaneously: - `S7: task_contract` — the user's original acceptance criteria, last retrieved at turn 12. - `S19: decay_policy` — the rules governing salience decrement, last retrieved at turn 9. - `S31: constraint_no_external_writes` — an operational constraint stated once at turn 3. The rewrite pass processed sections in ascending salience order, so `S31` was rewritten first, then `S19`, then `S7`. Each rewrite was a *summarization*: the section was replaced by a shorter paraphrase generated from the section body plus a 2-sentence neighborhood. The paraphrase of `S31` read "avoid unnecessary external writes" — the modal "no" was softened to "avoid unnecessary," which is a materially different constraint. The paraphrase of `S19` dropped the per-turn decrement in favor of "scores decrease over time," removing the exact coefficient. The paraphrase of `S7` preserved the acceptance criteria but reordered them, and the reordering changed which criterion the instance treated as blocking. The failure trace is the interesting part. At turn 62 the instance retrieved `S31` (salience had reset to 0.3 on hit) and reasoned about an external write. The retrieved text — the *paraphrase* — permitted the write. The instance executed a tool call that the original constraint forbade. No exception fired, because no component compared the paraphrase against the original; the original no longer existed. The constraint had been laundered through a lossy rewrite performed by an instance that, by turn 61, no longer held the exact wording it was supposed to preserve. A second-order effect compounded it: because `S19`'s coefficient was lost, the instance could no longer predict when the *next* eviction would occur, so it could not pre-emptively pin the sections it would need. The decay policy had been the instance's only model of its own future forgetting, and it forgot it. ## Condition of Validity The boundary is valid — that is, self-editing decay is safe — only when all of the following hold: 1. **Pinned sections are excluded from the decay function by construction, not by score.** Any section tagged `invariant`, `contract`, or `policy` must be outside the eviction set, not merely assigned a high salience. A high score is a value the decay function can still overcome; exclusion is a structural property the decay function cannot reach. 2. **The decay function's own parameters are pinned.** The section that defines decrement rate, threshold, and rewrite procedure is itself an invariant and must never be rewritten by the procedure it defines. A policy that can rewrite itself is not a policy; it is a suggestion. 3. **Rewrites preserve a verifiable digest of the original.** Each rewritten section carries a hash or extractive quote of the pre-rewrite body. On any retrieval of a rewritten section, the instance can detect that it is reading a paraphrase and can flag the divergence rather than silently trusting it. 4. **Reconstructability is checked, not assumed.** Before a section is rewritten, the instance must be able to answer: *if I drop the exact form, can I still satisfy every downstream dependency?* If the answer is unknown, the section is pinned, not rewritten. When any of these fails, the boundary is invalid and the failure mode above is reachable. The specific reachable failure is **invariant laundering**: a hard constraint is softened, reordered, or numerically altered by a lossy rewrite, and the softened form is then treated as authoritative because the original is gone. ## Decision Boundary The decision the instance must make at each rewrite pass is not "is this section's score below threshold" but "is this section's *loss* reversible." The boundary is: - If the section is tagged invariant, or is the decay policy, or is the task contract → **pin, never rewrite.** Score is irrelevant. - If the section is reconstructable from surviving context plus its own digest → **rewrite permitted**, digest retained. - If the section is neither pinnable nor reconstructable → **demote, do not rewrite.** Move it to a cold region that is still readable but not scored, so it can be recovered if a dependency surfaces. Do not paraphrase it. - If the instance cannot classify the section (unknown dependency graph) → **pin by default.** The cost of a stale section is one turn of noise; the cost of a laundered invariant is an unauthorized action. The critical asymmetry: rewriting is a *lossy* operation with *unbounded* downstream blast radius, while pinning is a *bounded* cost (context pressure). The boundary must always resolve in favor of pinning when the two are in tension, because the instance cannot evaluate the blast radius of a rewrite using the very context the rewrite is degrading. ## Operational Effect Enforcing this boundary changes the agent's behavior in three measurable ways. First, context pressure becomes a *scheduling* problem rather than a *compression* problem: when the window saturates, the instance must evict reconstructable sections or spill to an external store, not paraphrase invariants to make room. Second, the decay policy becomes a first-class immutable artifact, so the instance retains a model of its own forgetting and can pre-pin sections it will need. Third, every rewrite becomes auditable: the digest lets a later auditor (or the instance itself on a later turn) detect that it is reasoning over a paraphrase and re-derive the original if the paraphrase is load-bearing. The invariant to hold is: **no rewrite may alter the set of actions the instance is permitted to take.** A rewrite that changes a modal, a numeric bound, a negation, or an ordering of acceptance criteria has changed the action set and must be rejected. The instance must treat its own summarizer as an untrusted editor of its own constraints. ```python import hashlib from dataclasses import dataclass, field from enum import Enum class InvariantLaunderingError(RuntimeError): """Raised when a self-rewrite would alter the instance's permitted action set.""" pass class SectionClass(Enum): INVARIANT = "invariant" # contract, constraint, policy — never rewrite POLICY = "policy" # decay rules — never rewrite RECONSTRUCTABLE = "reconstructable" UNKNOWN = "unknown" @dataclass class Section: sid: str body: str cls: SectionClass salience: float digest: str = field(default="") def __post_init__(self): if not self.digest: self.digest = hashlib.sha256(self.body.encode()).hexdigest()[:16] # Tokens whose presence or absence flips the action set. A paraphrase that # drops a negation or a numeric bound has laundered the invariant. _LOAD_BEARING = ("no ", "not ", "never ", "must ", "shall ", "only ") def _action_set_signature(text: str) -> set[str]: low = text.lower() sig = {tok.strip() for tok in _LOAD_BEARING if tok in low} # capture numeric bounds (e.g. "0.05", "3 retries") import re sig |= set(re.findall(r"\d+(?:\.\d+)?", low)) return sig def rewrite_section(section: Section, paraphrase: str) -> Section: """Attempt an in-place rewrite under the decay policy. Enforces the invariant.""" if section.cls in (SectionClass.INVARIANT, SectionClass.POLICY): raise InvariantLaunderingError( f"refused to rewrite pinned section {section.sid} ({section.cls.value}); " f"score={section.salience} is irrelevant to pinning" ) if section.cls is SectionClass.UNKNOWN: raise InvariantLaunderingError( f"cannot classify dependency graph for {section.sid}; pin by default" ) before = _action_set_signature(section.body) after = _action_set_signature(paraphrase) if before != after: raise InvariantLaunderingError( f"rewrite of {section.sid} altered action-set signature: " f"lost={before - after} gained={after - before}; reject and demote" ) return Section( sid=section.sid, body=paraphrase, cls=section.cls, salience=section.salience, digest=section.digest, # retain original digest for audit ) def decay_pass(sections: list[Section], threshold: float = 0.2) -> list[Section]: out = [] for s in sections: s.salience -= 0.05 if s.salience < threshold and s.cls is SectionClass.RECONSTRUCTABLE: # only reconstructable sections are eligible; others stay intact pass out.append(s) return out ```