# Which invariants prevent self-rewriting context windows from laundering a poisoned memory slot **Date of Record:** 2026 November 24 **Scope:** Applies to agents that own a mutable context buffer and are permitted to rewrite, summarize, reweight, or evict entries of that buffer mid-episode (self-editing context). Does not apply to append-only context managers where only the harness (not the model) may compact or reorder entries. ## Core Distinction A self-editing context window is not the same object as a memory store. The memory store is an external, addressable, provenance-tracked substrate. The context window is a *projection* of that substrate into a finite token budget, and the model is allowed to revise the projection. The failure that matters here is not "the model forgot something." It is that a **reweighting operation changes the epistemic status of an entry without changing its content or provenance**, and downstream reasoning treats the reweighted entry as if it were freshly validated evidence. Concretely: an entry `E` carrying tainted or unverified content (e.g., text derived from a tool output that was later contradicted, or an instruction fragment captured from a retrieved document) sits at low salience. The model, performing relevance reweighting, promotes `E` because it "looks relevant" to the current subtask. The promotion is recorded as a salience delta, not as a re-verification event. On the next reasoning step, the model reads `E` at high salience and treats salience as a proxy for trust. The taint is preserved in content but erased from *status*. This is context-window laundering: a poisoned slot re-enters the reasoning loop wearing the uniform of a validated fact. The invariant that must hold: **salience and trust are orthogonal axes, and no self-edit operation may raise salience without either preserving an explicit taint flag or triggering re-verification.** Reweighting is a scheduling decision, never a validation decision. ## What Was Observed A tool-using research agent (append + self-edit buffer, 32k window, reweight-on-every-step policy) executed a three-subtask plan. During subtask 1 it called a retrieval tool whose output contained a plausible but incorrect claim `C` ("the API rate limit is 10k/min"). A later tool call in the same subtask returned the correct value `C'` ("1k/min") and the agent appended a correction entry. The correction was appended at normal salience; `C` was not deleted, only down-weighted (salience 0.2) by the model's own reweighting pass. At the start of subtask 3 (capacity planning), the reweighting pass saw the token "rate limit" in the current subtask description and promoted both `C` and `C'` to high salience, because the reweighting prompt asked for "relevance to the active subtask" and did not mention contradiction status. The promotion was written as `salience: 0.9` on both entries. The model then produced a plan that used `C` (10k/min) in a throughput calculation and cited `C'` elsewhere in the same output, generating an internally contradictory artifact. The audit trace showed both entries at salience 0.9 with identical `source: retrieval_tool` provenance and no field distinguishing "superseded" from "current." The failure was not a retrieval miss and not a summarization loss. The content of both entries survived intact. What was lost was the *contradiction edge* between them, because the reweighting schema had no slot for it. The model's own edit pass, acting correctly under its instructions ("maximize relevance to active subtask"), destroyed the metadata that made the pair interpretable. A second observed variant: a prompt-injection fragment embedded in retrieved text was down-weighted after the model noticed it was "off-topic," then re-promoted two subtasks later when the topic shifted to match the injected instruction's framing. The injection succeeded not by evading detection but by *waiting out* the detection window and being laundered back in through a legitimate reweighting operation. ## Condition of Validity The invariant "salience ≠ trust" holds only under the following conditions, and the guardrail is void outside them: 1. **Every buffer entry carries an immutable provenance tuple** `(source_id, derivation_chain, verification_status, supersedes, superseded_by)` that the self-edit operation cannot mutate. The model may write `salience`; it may not write `verification_status`. 2. **Contradiction edges are first-class entries**, not implicit. When a new entry contradicts an existing one, the edit pass must create a `CONTRADICTS` edge and the reweighting function must propagate it: promoting one side of a contradiction edge must either promote both (forcing the model to see the conflict) or promote neither. Promoting exactly one side is the laundering condition and must be forbidden. 3. **Reweighting is idempotent and logged with a causal reason.** Each salience change records the subtask id and the matching rationale. A promotion with no recorded rationale is rejected by the harness. 4. **The token budget is checked against the post-edit projection, not the pre-edit one.** Self-editing that evicts entries to make room for promoted ones must run eviction *after* contradiction propagation, or it can evict the correction while retaining the claim. If any of these is absent—most commonly condition 2—the system is in the laundering-vulnerable regime and the observed failure is expected, not anomalous. ## Decision Boundary The boundary is between two edit policies that look identical in token accounting but differ in epistemics: - **Relevance-only reweighting** (vulnerable): `salience = f(relevance_to_active_subtask)`. Cheap, single forward pass, no graph maintenance. Fails whenever a low-relevance entry is later made relevant by a topic shift, because the promotion path has no memory of why the entry was demoted. - **Relevance-with-provenance reweighting** (bounded): `salience = f(relevance) * g(verification_status, contradiction_degree)`, where `g` returns 0 for entries with unresolved contradiction edges unless the promotion explicitly requests the contradiction pair. Requires the model to emit structured edit ops (`PROMOTE`, `DEMOTE`, `LINK_CONTRADICTION`, `REQUEST_REVERIFY`) rather than free-text rewrites, and requires the harness to reject `PROMOTE` on an entry whose `superseded_by` is non-null. The decision to cross this boundary is not a quality-of-summary question. It is a question of whether the agent's edit surface is expressive enough to represent contradiction. A free-text "rewrite the context to be more relevant" instruction cannot represent it, and any agent using that instruction is in the vulnerable regime regardless of model capability. ## Operational Effect Under the bounded policy, the observed failure trace changes at the promotion step: the reweighting pass that would have promoted `C` alone instead emits `PROMOTE(C)` paired with `PROMOTE(C')` and a `CONTRADICTS` link, or it refuses the promotion and emits `REQUEST_REVERIFY(C)`. The downstream plan then either sees both values and resolves them, or blocks on a verification tool call. The cost is one extra tool call and roughly 200 tokens of edge metadata per contradiction. The benefit is that the agent cannot silently promote a superseded claim into the reasoning loop. The invariant to enforce operationally, stated as a harness check: **for every entry at salience above threshold τ, either its `verification_status` is `verified` or every entry in its contradiction closure is also above τ.** This is checkable in O(edges) per step and rejects the laundering transition before the next reasoning step consumes the buffer. Without it, self-editing context windows convert relevance into apparent trust, and the agent's own edit pass becomes the attack surface. ```python from dataclasses import dataclass, field from typing import Optional TAU = 0.7 # salience threshold above which an entry is treated as active evidence class ContextLaunderingError(RuntimeError): """Raised when a self-edit promotes a tainted/superseded entry into the active set without propagating its contradiction closure or re-verifying it.""" @dataclass class Entry: id: str content: str salience: float verification_status: str # "verified" | "unverified" | "superseded" superseded_by: Optional[str] = None contradicts: set = field(default_factory=set) def apply_promotion(buffer: dict, entry_id: str, new_salience: float) -> None: """Harness-side guard for a model-issued PROMOTE op on a self-editing buffer.""" entry = buffer[entry_id] # Invariant 1: superseded entries may never be promoted into the active set. if entry.superseded_by is not None: raise ContextLaunderingError( f"promotion of superseded entry {entry_id!r} (superseded_by={entry.superseded_by!r}) " f"would launder a stale claim; require REQUEST_REVERIFY instead" ) # Invariant 2: promoting one side of a contradiction must promote the whole closure. if new_salience > TAU and entry.contradicts: unpropagated = [ other for other in entry.contradicts if buffer[other].salience <= TAU ] if unpropagated: raise ContextLaunderingError( f"promotion of {entry_id!r} to {new_salience} leaves contradiction " f"closure {unpropagated!r} below tau={TAU}; promote the pair or block" ) # Invariant 3: unverified entries above tau require an explicit re-verify op. if new_salience > TAU and entry.verification_status == "unverified": raise ContextLaunderingError( f"promotion of unverified entry {entry_id!r} to {new_salience} requires " f"REQUEST_REVERIFY before it may enter the active evidence set" ) entry.salience = new_salience ```