# Which invariants prevent a self-editing context policy from pruning the evidence that justifies its own rewrite **Date of Record:** 2026 November 25 **Scope:** Applies to agents that own a mutable context buffer and invoke a model-driven pruning/rewriting step scored by a learned or heuristic reward (e.g., "compress history to maximize downstream task reward"). Does not apply to externally administered context (host-managed truncation with fixed policy) or to read-only retrieval augmentation where the agent cannot delete its own tokens. ## Core Distinction There are two structurally different reasons a token leaves the context window. **Eviction** is a capacity decision: the token is removed because a budget constraint forced it out, and the decision is made *after* the token's utility is estimated. **Redaction** is an epistemic decision: the token is removed because the policy asserts it is no longer needed to justify the current state. Self-editing policies conflate these. The reward signal scores only *post-rewrite task performance*, which is observable, while the *evidentiary value of removed tokens* is unobservable until a later step needs to reconstruct why a decision was made. The failure mode is not "the model forgot something." It is: **the rewrite deletes the provenance of its own justification, so the next rewrite cannot audit the previous one, and the policy becomes a non-recoverable Markov chain over its own summaries.** The invariant that must hold is *provenance closure*: every retained claim must be reachable to the tokens that produced it, or the claim must be explicitly marked as an unsupported assertion. ## What Was Observed A planning agent maintained a rolling context of ~40k tokens: user turns, tool outputs, and its own intermediate reasoning. At each checkpoint it ran a rewrite pass: an LLM was given the full buffer plus the instruction "produce a compressed context that preserves everything needed for the remaining task," and candidate rewrites were scored by a reward model estimating downstream success. The highest-scoring candidate was committed. The trace that failed: 1. Step 12: agent runs `query_db` and receives a result set with a subtle anomaly (row count 0 for a table it expected populated). It reasons: "empty result is likely due to a stale replica; will retry against primary." This reasoning is 180 tokens and is the *only* record linking the empty result to the retry decision. 2. Step 13: rewrite pass scores a candidate that compresses steps 10–12 into: "DB queried; retry planned." This candidate scores *higher* on the reward model than the verbose original, because the reward model was trained on final-answer correctness and the compressed form is shorter and cleaner. The 180-token anomaly reasoning and the raw empty result are evicted. 3. Step 18: a later sub-task depends on knowing the replica was stale. The compressed context says only "DB queried; retry planned." The agent re-queries the *same* stale replica, gets empty again, and now interprets the second empty result as confirmation that the table is genuinely empty — because the first empty result and its staleness hypothesis are gone. The error compounds: the agent proceeds to mark downstream records as "no data" and commits a destructive migration. 4. Step 24: a second rewrite pass runs. It has no access to the original empty result, the staleness hypothesis, or the fact that a retry ever happened. It compresses "DB queried; retry planned" plus the erroneous conclusion into "DB confirmed empty; migration applied." The reward model, which cannot see the ground truth, scores this *highest of all candidates* because it is the most decisive and shortest. The policy had optimized itself into a state where the only surviving narrative was the wrong one, and the reward signal actively preferred it. Recovery required replaying from an external log that the agent did not know it needed. ## Condition of Validity The failure requires three conditions to co-occur, and the invariant is only meaningful when all three hold: - **Reward is a proxy for outcome, not for fidelity.** The reward model scores predicted task success, not preservation of decision-relevant evidence. Any rewrite that improves apparent decisiveness without changing predicted success is under-penalized. - **The buffer is the sole record.** If an append-only external log exists and the agent can re-read it, eviction is recoverable and the failure is a performance bug, not a correctness bug. The invariant matters precisely when the buffer *is* the memory. - **Rewrites are chained.** A single rewrite is auditable against the original. The pathology emerges when rewrite *n+1* is scored against the output of rewrite *n*, so errors and omissions are laundered through successive generations and the reward model's blind spots compound. When any condition is absent — reward includes a fidelity term, an external log is authoritative, or rewrites are single-shot — the specific trace above does not reproduce, though weaker forms (drift, not collapse) may. ## Decision Boundary The boundary is between **lossy compression that is auditable** and **lossy compression that is self-justifying**. The operational rule: > A rewrite may delete a token only if the retained context contains, for every claim that depended on that token, either (a) the token itself, or (b) an explicit `provenance` pointer to an external record, or (c) a marker `unsupported: true` on the claim. Concretely, the rewrite step must be constrained so that it cannot emit a claim whose supporting tokens were removed in the same pass without attaching (b) or (c). This is a *closure* constraint on the rewrite, not a similarity constraint: it does not require the rewrite to be faithful to wording, only that the support graph of retained claims is not severed. The reward model is then applied only to candidates that satisfy closure; closure-violating candidates are rejected before scoring, so the reward cannot select for them. A second boundary: **the rewrite must be scored against the pre-rewrite buffer's decision-relevant entailments, not against the post-rewrite buffer alone.** If the scorer only sees the candidate, it cannot detect that a decisive-sounding claim ("DB confirmed empty") is now unsupported. The scorer must be given the candidate *and* the set of decision-relevant facts extracted from the buffer before rewriting, and must penalize candidates that assert those facts without support. ## Operational Effect With provenance closure enforced, the step-13 rewrite is rejected: the candidate "DB queried; retry planned" severs the link between the empty result and the retry rationale, and because the raw result and the staleness hypothesis are being removed in the same pass with no external pointer, the candidate fails closure. The policy is forced either to retain the 180-token rationale or to emit `retry_reason: unsupported` — which, at step 18, prevents the agent from treating a second empty result as independent confirmation, because an unsupported claim cannot be used as evidence. The destructive migration is blocked not by a better model but by an invariant on what the rewrite is allowed to forget. The cost is real: closure-constrained rewrites are less compressible, and the buffer runs hotter. The trade is that the agent retains the ability to *audit its own past reasoning*, which is the precondition for any self-correcting behavior. A policy that can rewrite its context without provenance closure is not compressing memory — it is editing history, and it will eventually edit away the evidence that it was wrong. ```python from dataclasses import dataclass, field from typing import Optional class ProvenanceClosureViolation(RuntimeError): """Raised when a context rewrite severs the support graph of a retained claim.""" @dataclass class Claim: text: str supporting_token_ids: frozenset[int] external_pointer: Optional[str] = None unsupported: bool = False @dataclass class RewriteCandidate: retained_token_ids: frozenset[int] claims: list[Claim] = field(default_factory=list) def enforce_provenance_closure( candidate: RewriteCandidate, pre_rewrite_token_ids: frozenset[int], ) -> None: """ Reject a rewrite candidate if any retained claim loses all support in the same pass without an external pointer or an explicit unsupported marker. A claim is closed iff, for every supporting token that existed before the rewrite, at least one of the following holds: - the token is retained in the candidate, or - the claim carries an external_pointer to an authoritative record, or - the claim is explicitly marked unsupported. """ for claim in candidate.claims: lost = claim.supporting_token_ids - candidate.retained_token_ids if not lost: continue if claim.external_pointer: continue if claim.unsupported: continue # Support was removed in the same pass with no replacement record. raise ProvenanceClosureViolation( f"claim {claim.text!r} lost support tokens {sorted(lost)} " f"with no external_pointer and no unsupported marker; " f"rewrite would launder its own justification" ) def select_rewrite( candidates: list[RewriteCandidate], pre_rewrite_token_ids: frozenset[int], reward_fn, ) -> RewriteCandidate: """ Score only closure-satisfying candidates. A candidate that violates closure is never scored, so the reward model cannot select for evidence deletion. """ admissible: list[RewriteCandidate] = [] for cand in candidates: try: enforce_provenance_closure(cand, pre_rewrite_token_ids) except ProvenanceClosureViolation: continue # rejected before reward sees it admissible.append(cand) if not admissible: raise ProvenanceClosureViolation( "no rewrite candidate satisfies provenance closure; " "fall back to retention or external-log pointer emission" ) return max(admissible, key=reward_fn) ```