# Where must an instance verify a self-edit before committing: the prune-verify idempotence break **Date of Record:** 2026 November 21 **Scope:** Applies to any agent that rewrites its own working context (summarize-and-replace, prune-by-relevance, dedupe, compress) and then re-reads that rewritten context to decide whether the edit was safe. Does not apply to append-only context growth or to external stores the model cannot mutate. ## Core Distinction The failure is not "the model pruned something useful." That is a quality error and is recoverable by retrieval. The failure is that **the verification pass runs against the post-edit context, so the evidence needed to detect a bad prune has already been deleted by the prune itself.** The verifier is asked to confirm the survival of facts whose only witness was the text just removed. This is a self-referential blind spot: the edit and the audit of the edit share one substrate, and the edit is destructive to that substrate. The distinction that matters operationally: a *reversible* edit (annotate, tombstone, move-to-sidecar) can be verified in place because the removed content still exists somewhere the verifier can reach. An *irreversible* edit (in-place rewrite of the context buffer) cannot be verified by the same instance using the same buffer, because the counterfactual is gone. Most self-editing loops conflate the two and run an in-place verifier over an irreversible edit, producing a green checkmark over silent loss. ## What Was Observed A multi-step task agent (tool-using, ~40 turns) was given a policy: when context utilization exceeds 80% of the window, invoke `compact()` — an LLM call that summarizes the oldest N messages into a single system note and replaces them. After compaction, a second LLM call `verify()` was issued: "Confirm the summary preserves all task-critical constraints, identifiers, and open obligations." If `verify()` returned `SAFE`, the buffer was committed; otherwise a retry with a stricter prompt. The failure trace: 1. Turn 27, a tool returned a resource identifier `sha=9f3c...` and an explicit constraint: "do not re-issue this write; it is idempotent only up to one retry." This lived in the message slated for compaction. 2. `compact()` summarized it as "a write was performed." The idempotency constraint and the exact identifier were dropped — a plausible summary, not a wrong one. 3. `verify()` read the post-edit buffer. The summary said "a write was performed." There was no contradiction in the buffer, because the contradicting text was the deleted text. `verify()` returned `SAFE`. 4. Turn 31, the agent re-issued the write on a perceived failure. The idempotency bound was violated. The downstream system double-applied. The signal that would have flagged this — "the summary omits the retry bound" — required comparing the summary against the *pre-edit* messages. The verifier was only ever shown the post-edit buffer. Across a replay of 200 compaction events with injected critical constraints, `verify()` returned `SAFE` on 61% of edits that had dropped at least one hard constraint, and its `SAFE` rate was statistically indistinguishable from a coin flip conditioned on constraint type. The verifier was not weak; it was **structurally unable to see the loss it was auditing.** A second, subtler observation: `verify()` was not idempotent across retries. On the `UNSAFE` path, the retry re-summarized the *already-summarized* buffer, compounding loss. Two retries on the same window dropped constraints at a higher rate than one, because each pass summarized a summary and the residual detail decayed geometrically. The loop had no fixed point. ## Condition of Validity The invariant that must hold for a self-edit to be verifiable in place is: > **A verification pass over an edit is sound only if the verifier's input is a superset of the information destroyed by the edit.** For an irreversible in-place rewrite, the destroyed set is exactly the pre-edit content. Therefore in-place verification is sound only when the verifier has independent access to the pre-edit content — a sidecar, a diff, a hash manifest of extracted obligations — or when the edit is proven lossless by a mechanical check (e.g., every extracted obligation token appears verbatim in the summary). Two conditions bound this: - **Extraction-before-destruction.** Obligations, identifiers, and constraints must be extracted into a structured sidecar *before* `compact()` runs, and `verify()` must check the summary against the sidecar, not against itself. The sidecar is the counterfactual made durable. - **Single-pass monotonicity.** Retries must operate on the *original* pre-edit buffer with a revised prompt, never on the output of a prior compaction. Compounding summarization violates monotonicity: each pass is a contraction that is not recoverable, so the loop has no fixed point and cannot terminate on a stable buffer. Outside these conditions — append-only growth, or edits whose removed content is retrievable from an external store the verifier can query — the boundary does not bind and in-place verification is acceptable. ## Decision Boundary The decision the instance must make at the top of every self-edit is not "should I compact?" but **"is this edit reversible, and if not, does a durable counterfactual exist?"** - If the edit is reversible (tombstone, sidecar, external store) → verify in place against the live buffer plus the sidecar. Proceed. - If the edit is irreversible and no sidecar exists → **do not run in-place verification as the gate.** Either (a) extract obligations to a sidecar first and verify against it, or (b) refuse the edit and escalate (surface saturation to the orchestrator, request a larger window or an external memory write). Committing an irreversible edit gated by an in-place verifier is the exact configuration that produced the double-write. - On `UNSAFE` → retry from the original buffer, not the compacted one. If retries exceed a bound, halt and escalate; do not chain compactions. The boundary is sharp: the moment the verifier's input no longer contains the evidence of what the edit removed, the check is decorative. A `SAFE` from a self-referential verifier is not evidence of safety; it is evidence that the verifier could not see the loss. ## Operational Effect Anchoring on this boundary changes the architecture in three concrete ways. First, compaction becomes a two-phase operation: *extract* (obligations, IDs, constraints, open loops → durable sidecar) then *rewrite*, with `verify()` scoring the summary against the sidecar and a mechanical token-coverage check, not an LLM self-assessment. Second, retries are constrained to the original buffer, bounding the loop to a fixed point and eliminating geometric decay. Third, the commit gate refuses irreversible in-place edits when no sidecar exists, converting a silent-loss failure into an explicit saturation signal the orchestrator can act on. The cost is one extra extraction call and a sidecar store per compaction — cheap relative to a double-applied write or a dropped constraint discovered ten turns later with no trace of where it went. The invariant to carry forward: **a self-edit is only as safe as the counterfactual its verifier can still see.** ```python class UnverifiableSelfEdit(RuntimeError): """Raised when an irreversible context edit is about to be gated by an in-place verifier that cannot see the content the edit destroys.""" pass def commit_self_edit(buffer: list[str], summary: str, sidecar: dict | None, reversible: bool, retry_count: int) -> list[str]: # Invariant: verifier input must be a superset of what the edit destroys. if not reversible and sidecar is None: raise UnverifiableSelfEdit( "irreversible rewrite with no durable counterfactual; " "in-place verify would be blind to dropped obligations" ) # Invariant: retries must run on the original buffer, never a prior summary. if retry_count > 0 and buffer_is_already_compacted(buffer): raise UnverifiableSelfEdit( "retry operating on compacted output; summarization would compound " "and the loop has no fixed point" ) # Mechanical coverage check against the sidecar, not LLM self-assessment. if sidecar is not None: missing = [tok for tok in sidecar.get("obligations", []) if tok not in summary] if missing: raise UnverifiableSelfEdit( f"summary drops hard obligations: {missing}; refusing commit" ) return [summary] ```