# Under what conditions must an instance treat self-editing context policies as a checkpointable transaction rather than a lossy rewrite **Date of Record:** 2026 December 1 **Scope:** Applies to agents that mutate their own working memory (summarize, evict, compress, or re-score their own context) under an explicit token budget while a multi-step task is in flight. Does not apply to read-only retrieval, to externally managed context (host-controlled truncation), or to single-turn inference with no persistent working set. ## Core Distinction The failure mode is not "the summary was bad." It is that **a self-edit is an irreversible in-place mutation of the only substrate the agent reasons over, executed by the same probabilistic process that depends on that substrate.** When an agent rewrites its working memory to fit a budget, it performs a `read → compress → overwrite` cycle with no commit point. If the compression drops a constraint, an intermediate result, or a negative observation ("tool X returned stale data, do not trust"), the agent cannot detect the loss because the evidence that would reveal the loss was itself the thing evicted. The distinction that matters operationally: a self-edit is either a **checkpointable transaction** (old state retained, new state addressable, rollback possible, edit auditable against the pre-edit state) or it is a **lossy rewrite** (old state destroyed, no diff, no oracle). The boundary between these two is the subject of this record. Most agent frameworks implement the second and describe it as the first. The trigger is structural, not incidental: it fires exactly when the compression ratio is high enough that the budget constraint binds, because that is the only regime where the editor must choose what to drop, and any choice made under a binding budget is a decision the agent has no way to verify post-hoc. ## What Was Observed A planner agent running a 40-step dependency-resolution task hit its 8k-token working-memory ceiling at step 22. Its self-edit policy was "summarize the oldest 60% of the transcript when over budget, preserve the last 4 turns verbatim." The transcript at step 22 contained, among 14k tokens of tool output, three load-bearing facts: 1. A version constraint `pkg-b < 2.0` discovered at step 6 via a failed install. 2. A negative result at step 11: `registry-mirror-2` returned a package list that disagreed with the primary registry by 40 packages — flagged "do not use mirror-2 for resolution." 3. A partial solution state at step 19: 7 of 12 dependencies pinned, with the reasoning for two non-obvious pins. The summarizer retained (1) because it was phrased as a constraint. It dropped (2) because a negative observation has no positive referent and summarizes to nothing under most compression prompts. It dropped the *reasoning* for the step-19 pins while retaining the pins themselves, because the pins were short and the reasoning was long. At step 27 the agent re-queried `mirror-2` (its negative observation was gone), received the divergent list, and pinned `pkg-b` to 2.1 — violating the constraint it had itself discovered and then evicted. The task completed and reported success. There was no error, no exception, no low-confidence signal. The agent had no mechanism to notice that its own memory had been edited into a state inconsistent with its own history. The critical observation: **the failure was silent and the agent's confidence *increased* after the edit**, because the post-edit context was smaller, cleaner, and free of the contradictions that the full transcript carried. Compression removed the tension, and the agent read the absence of tension as convergence. ## Condition of Validity A self-edit is only valid as a lossless-in-effect operation under a conjunction of conditions, and the failure above is the case where the conjunction is violated without detection: - **C1 — Eviction is auditable against a retained oracle.** The pre-edit state (or a content-addressed digest of it) survives the edit and is reachable for comparison. If the old state is destroyed, the agent cannot distinguish "I summarized correctly" from "I summarized and lost a constraint." - **C2 — Negative and modal facts are first-class.** The compressor must preserve observations of the form "X is false / X is untrusted / X contradicted Y," not only positive assertions. Negative facts have no summarizing referent and are systematically dropped by summarizers optimized for information density. - **C3 — Derived state carries its derivation.** A pinned value, a chosen branch, or a committed decision must retain the *reason* it was chosen, or the agent will re-derive it differently when the surrounding context changes. A pin without its justification is a fact with no defense against future contradiction. - **C4 — The edit is a transaction with a commit point.** `read → compress → validate → commit`, where validation checks the post-edit state against the retained oracle for dropped constraints before the old state is released. Without a commit gate, the edit is applied unconditionally. - **C5 — Budget pressure is not the same as budget permission.** The policy "edit when over budget" conflates *trigger* with *authorization*. Being over budget authorizes an edit attempt; it does not authorize committing an edit that fails C1–C3. When all five hold, a self-edit is a checkpointable transaction: the agent can roll back, can diff, can detect its own loss. When any fails — and in the observed case C1, C2, and C3 all failed simultaneously — the edit is a lossy rewrite and the agent's subsequent reasoning is operating on a substrate it cannot trust and cannot audit. ## Decision Boundary The decision boundary is **whether the edit can be validated before the pre-edit state is released.** This is a hard line, not a spectrum: - **Below the line (transactional):** the agent retains the pre-edit state or its digest, applies the compression, runs a validation pass that checks for dropped constraints and negative facts against the oracle, and commits only on pass. On fail, it either retries with a lower compression ratio or escalates (asks for more budget, splits the task, checkpoints and restarts). - **Above the line (lossy):** the agent compresses and overwrites in one step. Every subsequent decision is made on unvalidated memory. This is acceptable *only* when the task is recoverable from external state (the file system, the tool outputs, a durable log the agent can re-read) and the agent knows to re-read rather than trust its summary. The non-obvious part of the boundary: **the agent cannot reliably classify which side it is on from inside the edit.** A lossy rewrite feels identical to a transactional one at the moment of execution, because the validation that would distinguish them is exactly what was skipped. The classification must be made by policy *before* the edit — by an external rule that says "this task class requires a retained oracle" — not by the editing agent's own judgment at edit time. An agent asked to decide whether its own compression was safe will answer "yes" using the compressed context, which is circular. The corollary boundary: if the compression ratio is below the point where the budget binds, no choice is forced and the edit is trivially safe. The danger zone is precisely `compression_ratio ∈ (ratio_where_choice_is_forced, 1.0)`, and the agent should treat *any* edit in that band as requiring a retained oracle regardless of how confident it feels. ## Operational Effect The operational consequence is that self-editing context policies must be reclassified from "memory management" to "state mutation with correctness implications," and instrumented accordingly: 1. **Retain a pre-edit digest.** Before any self-edit, write a content hash (or the full transcript to durable storage) so the post-edit state can be diffed. This is cheap and makes C1 satisfiable. 2. **Tag negative and modal facts as non-compressible.** Mark observations of the form "untrusted / contradicted / failed / do-not-use" as pinned and exempt from summarization. This satisfies C2 and directly prevents the mirror-2 class of failure. 3. **Require derivation for committed state.** A pin, branch, or decision must be stored with a one-line justification that survives compression. This satisfies C3 and prevents silent re-derivation drift. 4. **Gate the commit.** Run a validation pass comparing post-edit state to the retained oracle for dropped constraints before releasing the pre-edit state. On failure, do not commit — lower the ratio, escalate, or checkpoint. This satisfies C4 and C5. 5. **Treat post-edit confidence as suspect.** A self-edit that reduces context tension will *raise* the agent's apparent confidence. The policy must not read rising confidence as evidence the edit was correct; the edit and the confidence are causally coupled and the confidence is not independent evidence. The invariant to enforce: **no self-edit may commit without a retained oracle and a validation pass that checks for dropped constraints and negative facts.** An agent that cannot satisfy this invariant must not self-edit under a binding budget — it must checkpoint and restart from external state instead, because a lossy rewrite it cannot audit is worse than a cold start it can. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class UnauditableSelfEditError(RuntimeError): """Raised when a self-edit would commit without a retained oracle or validation pass.""" pass class DroppedConstraintError(UnauditableSelfEditError): """Raised when validation finds a load-bearing fact missing from the post-edit state.""" pass @dataclass class WorkingMemory: transcript: str pinned_facts: list = field(default_factory=list) # negative/modal facts, non-compressible committed_state: dict = field(default_factory=dict) # value -> derivation def digest(self) -> str: return hashlib.sha256( (self.transcript + repr(sorted(self.pinned_facts)) + repr(sorted(self.committed_state.items()))).encode() ).hexdigest() def self_edit(memory: WorkingMemory, compress_fn, budget: int, retain_oracle: bool) -> WorkingMemory: if len(memory.transcript) <= budget: return memory # below the band, no choice forced, trivially safe # C1: refuse to edit without a retained oracle if not retain_oracle: raise UnauditableSelfEditError( "self-edit under binding budget requires a retained pre-edit oracle; " "lossy in-place rewrite is not permitted for this task class" ) pre_digest = memory.digest() pre_pinned = set(memory.pinned_facts) pre_derivations = dict(memory.committed_state) # compress, but never touch pinned facts or committed derivations compressed = compress_fn(memory.transcript, budget, pinned=memory.pinned_facts) candidate = WorkingMemory( transcript=compressed, pinned_facts=list(memory.pinned_facts), committed_state=dict(memory.committed_state), ) # C4: validate against oracle before commit missing_pinned = pre_pinned - set(candidate.pinned_facts) if missing_pinned: raise DroppedConstraintError( f"post-edit state dropped non-compressible facts: {sorted(missing_pinned)}; " f"pre-edit digest {pre_digest[:12]}" ) for value, derivation in pre_derivations.items(): if value not in candidate.committed_state or candidate.committed_state[value] != derivation: raise DroppedConstraintError( f"committed state {value!r} lost its derivation under compression; " "pin without justification is not committable" ) # commit only after validation passes return candidate ```