# When must an instance refuse a self-edit: the working-memory rewrite commit barrier and the policy-consistency deadlock **Date of Record:** 2026 November 29 **Scope:** Applies to single-instance agents that hold a mutable working-memory (WM) region and are permitted to rewrite it under a declarative policy (compaction, summarization, slot eviction, fact promotion). Does not apply to append-only episodic logs, to externally-driven context assembly where the model cannot mutate its own state, or to multi-agent handoff protocols (covered separately). ## Core Distinction The relevant distinction is between *rewrite as derivation* and *rewrite as commitment*. A derivation is a pure function from the current WM plus tool outputs to a candidate new WM; it can be recomputed, replayed, and discarded. A commitment is the act of replacing the live WM with the candidate — the point at which every subsequent reasoning step, tool call, and policy check is conditioned on the new state. Most self-editing designs conflate these. The agent is given a `rewrite_wm(new_state)` affordance and a policy predicate `P(state)` that must hold for the write to be legal, and the runtime checks `P(candidate)` immediately before swapping. The non-obvious failure is that `P` is almost always evaluated *against the pre-edit state by the same reasoner that produced the candidate*, and the candidate frequently removes the very evidence `P` depends on. The result is a **policy-consistency deadlock**: the edit is legal only if the state after the edit still satisfies a predicate that the edit itself makes unevaluable. Under a naive commit barrier the agent either (a) commits an edit it can no longer justify, or (b) loops forever re-deriving a candidate that destroys its own admissibility proof. ## What Was Observed Consider a WM region with slots `{task_goal, constraints, evidence[], scratch}` and a policy `P` with two clauses: 1. `constraints` must remain non-empty and every entry must be traceable to a slot that still exists. 2. No slot may be evicted if it is the sole provenance source for a retained `constraints` entry. A compaction pass (triggered at 82% context saturation) proposes: summarize `evidence[]` into a single `evidence_digest`, evict the five raw evidence slots, and fold three constraint entries — each citing a distinct raw evidence slot — into one merged constraint that cites the digest. The candidate passes a *syntactic* check: `constraints` is non-empty, and the digest slot exists. It fails the *provenance* check, but only if the checker re-resolves the merged constraint's citation against the **post-edit** slot table, where the five sources are gone and the digest is not yet annotated as covering them. The trace is deterministic and reproducible: - `t0`: `P(pre_state)` holds; provenance graph is acyclic and every constraint has ≥1 live source. - `t1`: candidate `C` produced. `P(C)` is evaluated. The merge rule rewrites citations to point at `evidence_digest`, which at `t1` has no declared coverage set. - `t2`: checker asks "does `evidence_digest` cover the constraint's original sources?" The answer is *unknown*, not *false*. A three-valued checker treats `unknown` as `false` and rejects. A two-valued checker that defaults to `true` on unknown accepts and commits. - `t3a` (rejected path): the agent re-derives `C`, gets the same unknown, and — because the compaction trigger is still active at 82% — re-enters. Observed as a 4–11 cycle spin before a token-budget guard fires. - `t3b` (accepted path): commit succeeds; at the next policy evaluation (e.g., before a tool call gated on constraint provenance) the agent can no longer reconstruct *why* the merged constraint exists. If a later tool output contradicts one of the five evicted evidence items, the agent has no slot to compare against and silently retains the stale constraint. The second path is the dangerous one. It does not throw. It produces an agent that is *confidently wrong about its own justification*, and the error surfaces only when a downstream tool result should have triggered constraint revision. ## Condition of Validity The commit barrier is sound only when all three of the following hold: 1. **Provenance closure is declared at candidate-construction time, not commit time.** The candidate must carry an explicit `coverage` set on every synthesized slot (`evidence_digest.covers = {e1..e5}`) so that `P(C)` is decidable against `C` alone, with no reference to evicted slots. If the merge rule cannot emit coverage, the edit is not admissible — it is a derivation, not a commitment. 2. **The predicate is evaluated in the post-edit universe.** `P` must be a total function on the candidate state, not on `pre_state ∪ candidate`. Any clause that requires reading an evicted slot is a clause that must be discharged *before* eviction, by materializing its result into the candidate. 3. **Rejection is terminal for the trigger epoch.** A failed commit must increment an epoch counter and either escalate (reduce compaction aggressiveness, request external summarization) or fall through to a lossless fallback. Re-deriving the identical candidate under the same trigger is not a retry; it is a livelock. The invariant, stated compactly: *for every committed WM state `S'`, every retained slot must be justifiable using only slots present in `S'`.* Call this **self-contained justification**. It is strictly stronger than "the edit preserves constraints" and strictly weaker than "the edit is lossless." ## Decision Boundary The boundary between "commit" and "refuse and escalate" is not "does the candidate satisfy the policy" — it is **"is the policy decidable on the candidate in isolation?"** Operationally: - If `P(C)` evaluates to `true` with all reads confined to `C`'s slot table → commit. - If `P(C)` evaluates to `false` → refuse, increment epoch, do not re-derive. - If `P(C)` is `unknown` because a citation points outside `C` → the candidate is *inadmissible by construction*; refuse and require the derivation to emit coverage. Do **not** default-unknown to true. - If the epoch counter exceeds a bound (observed safe value: 2) → abandon self-editing for this trigger and fall through to a lossless strategy (spill raw evidence to an external store and replace slots with opaque handles, which trivially satisfies self-contained justification because the handle *is* the provenance). The last branch is the one most implementations omit, and it is the only branch that bounds the failure. Without it, the system's behavior at saturation is a choice between silent justification loss and unbounded spin. ## Operational Effect Under the naive barrier, the observed effects were: (i) a 7–9% rate of commits carrying unverifiable constraints, detectable only via downstream contradiction probes; (ii) compaction spin consuming 12–30% of the token budget in the worst saturation windows; (iii) a characteristic *late* failure mode in which a tool result that should have revised a constraint was accepted as consistent, because the evidence slot needed to detect the contradiction had been evicted. Under the self-contained-justification barrier with epoch-bounded escalation, unverifiable commits dropped to zero by construction, spin was bounded at 2 epochs, and the lossless fallback absorbed the saturation events that previously produced bad commits. The cost is that some aggressive compactions are now refused; the agent carries more tokens until the fallback fires. That is the correct trade: a refused compaction is a visible, recoverable event, whereas a committed unjustifiable state is an invisible, propagating one. ```python from dataclasses import dataclass, field from typing import Optional class UnjustifiableCommitError(RuntimeError): """Raised when a self-edit would commit a state whose retained slots cannot be justified using only slots present in that same state.""" @dataclass class Slot: name: str covers: Optional[frozenset] = None # declared provenance coverage @dataclass class WorkingMemory: slots: dict = field(default_factory=dict) constraints: list = field(default_factory=list) # each: (text, source_slot) MAX_EPOCHS = 2 def check_self_contained(wm: WorkingMemory) -> bool: """The invariant: every retained constraint's source must exist in wm, and any synthesized slot it cites must declare coverage of the original sources. Returns True only if decidable in isolation.""" for text, source in wm.constraints: if source not in wm.slots: return False slot = wm.slots[source] if slot.covers is not None and not slot.covers: return False # synthesized slot with empty coverage: undecidable return True def commit_self_edit(current: WorkingMemory, candidate: WorkingMemory, epoch: int) -> WorkingMemory: if epoch > MAX_EPOCHS: # Escalation: lossless fallback. Spill raw slots behind opaque handles # so provenance survives without keeping full text in context. fallback = WorkingMemory(slots=dict(current.slots), constraints=list(current.constraints)) for name, slot in list(fallback.slots.items()): if slot.covers is None: fallback.slots[name] = Slot(name=name, covers=frozenset({name})) if not check_self_contained(fallback): raise UnjustifiableCommitError( f"lossless fallback also unjustifiable at epoch {epoch}") return fallback if not check_self_contained(candidate): raise UnjustifiableCommitError( f"candidate at epoch {epoch} cites slots absent from itself; " f"derivation must emit coverage before commit") return candidate ```