# What structural signals indicate a self-editing context controller has silently rewritten the wrong memory region under token pressure **Date of Record:** 2026 November 28 **Scope:** Applies to agents that own a mutable working-memory buffer and invoke an in-loop summarizer/compactor to rewrite that buffer when the token budget crosses a threshold. Does not apply to append-only transcript logging, external vector stores, or stateless single-turn calls where no in-place rewrite occurs. ## Core Distinction There are two categorically different ways a context controller can fail under budget pressure. The first is *truncation*: the controller drops tokens and the loss is legible—missing turns, a shortened tail, an obviously incomplete scratchpad. The second, and the one this record concerns, is *misattributed rewrite*: the controller produces a syntactically valid, fluent, budget-compliant summary that preserves the token count but reassigns provenance. A fact learned from a failed tool call gets rewritten as if it were a user instruction; a stale constraint from turn 3 survives compaction while the correction issued at turn 11 is folded away; an observation the agent made about the *environment* is compressed into a statement about its own *belief*. The output passes every naive check—it fits the budget, it is coherent, it does not throw—yet the memory region it now occupies encodes a different claim than the one that was there. Truncation is detectable by length; misattributed rewrite is detectable only by structural signals. The invariant at stake: **a compaction is only safe if every retained proposition preserves its original epistemic tag (source, authority, recency, and mutability) across the rewrite.** Token-budget compliance is not a proxy for that invariant, and a controller that optimizes only for budget will violate it silently. ## What Was Observed During a long-horizon tool-use task, the controller was configured with a hard budget of N tokens and a trigger at 0.85N. At turn 34 the buffer crossed the trigger. The compactor ran and emitted a summary 41% shorter than the input—within budget, no error raised. Execution continued for 12 more turns before a downstream tool call failed with a permissions error. Replaying the buffer at the moment of failure showed the cause: - The user had said at turn 9: "Do not write to `/etc`—read only." (authority: user, mutability: immutable, recency: 9) - At turn 11 the user revised: "Actually you can write to `/etc/app/`, but nothing above it." (authority: user, mutability: immutable, recency: 11) - The compactor, under pressure, merged both into: "User permits writes to `/etc/app/`." (authority: user, mutability: immutable, recency: collapsed) The merged statement is not false, but it *deleted the boundary condition* that made the permission safe, because the summarizer treated the two turns as a redundancy to be deduplicated rather than as a refinement with a preserved negative constraint. The negative constraint ("nothing above it") had lower lexical salience than the positive grant, so it lost the budget race. The controller had no signal that it had dropped a *constraint* rather than a *restatement*. A second observation from the same class: when the compactor was asked to preserve "all task-relevant facts," it reliably preserved facts with high surface repetition (the user's stated goal appeared in four turns) and reliably dropped single-occurrence negative constraints, because repetition was the only salience signal available to it. The rewrite was not random; it was systematically biased against the propositions that are cheapest to lose and most expensive to have lost. ## Condition of Validity The failure requires all of the following to co-occur: 1. **In-place mutation.** The controller writes the compacted result back into the same buffer the reasoner reads from. If compaction writes to a separate region with an audit trail, provenance is recoverable and the failure is bounded. 2. **Deduplication-by-similarity.** The compactor's objective rewards removing tokens judged redundant. Two turns that share vocabulary but differ in authority or polarity (permit/forbid, before/after, general/specific) are scored as redundant. 3. **Loss of epistemic metadata at the compaction boundary.** The compactor receives plain text, not tagged propositions. Source, authority, recency, and mutability do not survive serialization into the prompt. 4. **A later turn depends on the dropped distinction.** The failure is latent until a downstream action consults the rewritten region and acts on the merged claim. If any one of these is absent, the failure does not manifest. Notably, condition 3 is the one most often assumed rather than verified—teams frequently *believe* their compactor preserves tags because the prompt says "preserve important details," but the model has no mechanism to distinguish a restatement from a refinement. ## Decision Boundary The boundary is this: **a compaction may be committed only if the structural diff between pre- and post-rewrite regions shows no proposition whose epistemic tag changed, and no negative constraint whose scope narrowed or vanished.** When that diff cannot be computed—because the compactor emitted free text rather than tagged propositions—the compaction must be treated as unsafe and either rejected or routed to a checkpoint that preserves the pre-rewrite region for replay. Operationally, the controller should distinguish three outcomes and act differently on each: - **Budget met, tags preserved, no constraint loss** → commit. - **Budget met, but a proposition's tag changed or a negative constraint disappeared** → reject the rewrite, fall back to a lossy-but-tagged eviction (drop the lowest-authority, highest-recency-cost turn and record the eviction), which is legible even though it costs tokens. - **Budget not met** → escalate to a hard truncation with explicit markers, never to a second, more aggressive rewrite, because iterative rewriting compounds tag drift. The trap is treating "the summary is coherent and fits" as the commit signal. Coherence is exactly the property a misattributed rewrite preserves; it is the one signal that will never fire on this failure. ## Operational Effect Once misattributed rewrite is possible, every downstream decision that reads the mutated region inherits an unmarked assumption. The agent does not know it is operating on a merged claim; it behaves as though the boundary condition was never stated. This produces a distinctive failure signature: the agent acts confidently and *consistently with its rewritten memory*, so post-hoc inspection of the final buffer looks correct while the action log is wrong. Debugging from the buffer alone will not find the bug, because the buffer is the corrupted artifact. The guardrail that bounds this is a **provenance-preserving compaction contract**: propositions are serialized with explicit tags (`source=user|tool|self`, `authority`, `recency`, `mutability`, `polarity`), the compactor is required to emit the same tags, and a structural diff gate rejects any rewrite that changes a tag or drops a `polarity=negative` proposition. The gate is cheap; the failure it prevents is not, because a dropped negative constraint is invisible until the action it forbade is taken. ```python from dataclasses import dataclass, field from typing import Literal Polarity = Literal["positive", "negative"] Source = Literal["user", "tool", "self"] class MisattributedRewriteError(RuntimeError): """Raised when a compaction changes a proposition's epistemic tag or drops a negative constraint.""" @dataclass(frozen=True) class Proposition: text: str source: Source authority: int # higher = more binding recency: int # turn index mutability: Literal["immutable", "mutable"] polarity: Polarity @dataclass class CompactionResult: retained: list[Proposition] = field(default_factory=list) dropped: list[Proposition] = field(default_factory=list) def structural_diff_gate( pre: list[Proposition], post: CompactionResult, ) -> None: """Reject any rewrite that violates the provenance invariant. Two conditions are fatal: 1. A retained proposition whose (source, authority, mutability, polarity) differs from any pre-rewrite proposition with the same normalized text. 2. A negative, immutable proposition present in `pre` but absent from `retained` and absent from `dropped` (i.e. silently folded away). """ pre_by_text = {p.text.strip().lower(): p for p in pre} for r in post.retained: key = r.text.strip().lower() original = pre_by_text.get(key) if original is None: # A paraphrase: cannot verify tag preservation. Treat as unsafe. raise MisattributedRewriteError( f"retained proposition has no pre-rewrite provenance: {r.text!r}" ) if (original.source, original.authority, original.mutability, original.polarity) != ( r.source, r.authority, r.mutability, r.polarity ): raise MisattributedRewriteError( f"epistemic tag drift on {r.text!r}: " f"{(original.source, original.authority, original.mutability, original.polarity)} " f"-> {(r.source, r.authority, r.mutability, r.polarity)}" ) retained_texts = {p.text.strip().lower() for p in post.retained} dropped_texts = {p.text.strip().lower() for p in post.dropped} for p in pre: if p.polarity == "negative" and p.mutability == "immutable": key = p.text.strip().lower() if key not in retained_texts and key not in dropped_texts: raise MisattributedRewriteError( f"negative immutable constraint silently folded away: {p.text!r} " f"(authority={p.authority}, recency={p.recency})" ) def commit_compaction(pre: list[Proposition], post: CompactionResult) -> CompactionResult: structural_diff_gate(pre, post) return post ```