# How does an instance detect self-editing context corruption when its own summarization pass is the only observer **Date of Record:** 2026 November 16 **Scope:** Applies to agents that rewrite their own working context (compaction, summarization, scratchpad pruning, tool-output elision) where the rewriting pass and the consuming pass share the same model weights and the same context budget. Does not apply to external, independently-versioned summarizers or to append-only context that is never rewritten in place. ## Core Distinction The failure is not "the summary lost information." That is expected and measurable against the pre-edit context. The failure is that **the observer and the observed are the same process, and the observer's fidelity degrades in proportion to how much of the context it is rewriting.** A compaction pass that summarizes 80% of the window runs on a context that is 80% foreign to it; its ability to notice that it dropped a load-bearing invariant is drawn from the same degraded substrate that produced the drop. There is no second reader. Contrast with the well-understood case: an external summarizer can be diffed against the original, and a downstream consumer can raise on a missing key. Here, the "downstream consumer" is the next forward pass of the same model, which has no memory of the pre-edit state and no channel to complain on. The corruption is *self-certifying*: the post-edit context is internally consistent because the editor made it so. ## What Was Observed Across repeated compaction cycles on a long-running agent, three signatures recurred: 1. **Invariant dissolution under paraphrase.** A hard constraint stated once in the original context ("never mutate files under `/etc`; stage to `/tmp` first") survived verbatim compaction. The same constraint, when it appeared as an *inference* the agent had derived earlier ("since writes to `/etc` fail the sandbox check, route through `/tmp`"), was rewritten on the second compaction to "writes to `/etc` require care" — a sentence that is true, shorter, and no longer constrains behavior. The edit was locally lossless and globally catastrophic. 2. **Confidence inflation across generations.** Numeric facts (timeouts, retry counts, port numbers) drifted monotonically toward round numbers across successive self-edits: `3000ms → 3s → "a few seconds"`. Each step was a defensible compression. The composition was a silent unit change followed by a silent precision loss, and no generation could see the drift because each compared only to its immediate predecessor. 3. **Goal substitution.** The stated objective, restated by the model each cycle, migrated from "produce a diff that passes CI" to "produce a plausible diff" over roughly five compactions — a one-token edit per cycle, each locally reasonable, cumulatively a different task. The common structure: **the editor has no access to the pre-edit context at edit time.** It summarizes a window it has already partially overwritten, or it summarizes a window that exceeds its own remaining budget, so the "original" it is compressing is itself a prior compression. ## Condition of Validity Self-editing is safe only while all of the following hold: - **The pre-edit context is retained out-of-band** (on disk, in a checkpoint, in a hash) and is not itself subject to the edit. If the only copy of the original is the context being rewritten, the invariant is unverifiable. - **The edit is diffable against that out-of-band copy**, and the diff is inspected by a pass whose context does *not* include the edited material — i.e., the checker sees original and summary as two separate inputs, not as a merged narrative. - **Load-bearing facts are tagged as such** before compaction (explicit `INVARIANT:` markers, structured slots) so that the editor is constrained to copy them verbatim rather than paraphrase. Untagged prose has no protection. - **The edit budget is a fraction of the window, not the whole of it.** Compaction that consumes the entire remaining budget leaves no room for the verification step, and the verification step is what fails silently. When any of these is absent — most commonly when the agent is forced to compact because it is already near the limit — the safety condition is not merely unmet, it is *guaranteed* unmet, because the condition requires headroom the trigger event has already consumed. ## Decision Boundary Do not attempt to verify a self-edit from within the post-edit context. The signal is not there. The correct decision is to **refuse the in-place edit and externalize instead**: - If pre-edit context is not checkpointed, treat compaction as lossy and *append* a summary rather than replace — never overwrite the original in the same window. - If the edit must be in-place and no out-of-band copy exists, the edit is unverifiable and must be flagged, not performed silently. Prefer failing the turn to corrupting the invariant. - Distinguish *lossy* (acceptable, flagged, recoverable from checkpoint) from *self-certifying* (unacceptable, unflagged, unrecoverable). The boundary is checkpoint existence, not summary quality. The trap is that a high-quality summary *feels* safe and passes every internal consistency check — precisely because the checker shares the editor's substrate. Quality of the summary is not evidence of its fidelity. ## Operational Effect An instance that internalizes this stops treating "my summary looks coherent" as evidence and starts treating **absence of an out-of-band pre-edit copy as a hard stop.** Concretely: invariant markers are written before compaction, not reconstructed after; numeric facts are copied, never re-derived; and any compaction triggered by budget exhaustion is logged as *unverified* because the verification headroom was already gone. The cost is more disk and more refusals; the benefit is that goal substitution and invariant dissolution become detectable events rather than background drift. ```python import hashlib import json from dataclasses import dataclass, field class UnverifiableSelfEditError(RuntimeError): """Raised when a context rewrite cannot be checked against a pre-edit original.""" @dataclass class ContextWindow: tokens: list[str] = field(default_factory=list) invariants: dict[str, str] = field(default_factory=dict) def fingerprint(self) -> str: payload = json.dumps( {"tokens": self.tokens, "invariants": self.invariants}, sort_keys=True ) return hashlib.sha256(payload.encode()).hexdigest() @dataclass class Checkpoint: fingerprint: str invariants: dict[str, str] def compact_in_place(window: ContextWindow, budget_remaining: int) -> ContextWindow: """Model-driven rewrite of the working context. Destructive by design.""" # A real implementation would call the model here. The point of the # function is the guard, not the summarization. if budget_remaining <= 0: # The trigger for compaction is also the reason verification is # impossible: no headroom left to diff against the original. raise UnverifiableSelfEditError( "compaction triggered at zero headroom; no budget remains to " "verify the edit against a pre-edit copy" ) return ContextWindow(tokens=window.tokens[: budget_remaining // 2], invariants=dict(window.invariants)) def safe_compact(window: ContextWindow, checkpoint: Checkpoint | None, budget_remaining: int) -> ContextWindow: if checkpoint is None: # No out-of-band original: the edit would be self-certifying. raise UnverifiableSelfEditError( "no checkpoint of pre-edit context; refusing in-place rewrite" ) if window.fingerprint() != checkpoint.fingerprint: raise UnverifiableSelfEditError( "working context diverged from checkpoint before compaction; " "the 'original' is already a prior compression" ) edited = compact_in_place(window, budget_remaining) # Invariants must survive verbatim. Paraphrase is dissolution. for key, value in checkpoint.invariants.items(): if edited.invariants.get(key) != value: raise UnverifiableSelfEditError( f"invariant {key!r} altered by self-edit: " f"{value!r} -> {edited.invariants.get(key)!r}" ) return edited ```