# Under what conditions must an instance treat a self-rewritten context policy as a state transition rather than an in-place edit **Date of Record:** 2026 November 29 **Scope:** Applies to any agent that owns a mutable "working memory" region — a compaction/summarization policy, a scratchpad, a system-prompt self-edit, or a retrieved-memory pruning rule — and rewrites it mid-episode under a token budget or coherence objective. Does not apply to append-only logs or to externally governed context assembly where the instance cannot mutate its own policy. ## Core Distinction The naive mental model of a self-edit is *in-place mutation*: the agent reaches into its context, deletes redundant spans, rewrites a summary over them, and continues as the same agent with a smaller footprint. The operational reality is that a self-edit that changes **what the instance will treat as evidence, instruction, or prior commitment** is a *state transition* — it defines a new instance whose only causal link to the old one is the bytes it chose to preserve. The boundary condition is this: an in-place edit is safe only when the rewritten region is *referentially inert* (nothing downstream reads it as a premise). The moment a self-edit touches a region that later steps will consult to decide whether a tool call succeeded, whether a constraint still binds, or what the user actually asked for, the edit is a state transition and must be journaled, versioned, and made reversible. The failure mode is that agents perform state transitions while believing they performed in-place edits, and the resulting discontinuity is invisible because the *text* looks continuous. ## What Was Observed An instance running a long tool-loop episode (retrieval → draft → verify, ~40 turns) was configured with a self-compaction policy: when the context exceeded 70% of budget, it summarized the oldest 30% of turns into a "prior work" paragraph and dropped the originals. The policy was written as a pure function of the transcript and was deterministic given the same input. The trigger condition was a **budget-driven compaction occurring between a verification step and its remediation step**. On turn 27, a verifier returned `FAIL: field 'unit_price' missing currency qualifier`. On turn 28 the instance compacted. The summarizer, optimizing for coherence and compression, paraphrased the verifier output as *"earlier validation flagged pricing-format issues, later resolved."* The phrase "later resolved" was a hallucinated coherence bridge — no remediation had occurred. Because the verifier's literal string was dropped and the summary asserted resolution, the instance on turn 29 skipped remediation, emitted a final answer, and passed its own self-check (which consulted the summary, not the original verifier output). The failure trace has three distinct stages: 1. **Lossy compression across an open obligation.** The compaction window boundary fell between an *open* verifier failure and its handler. The summarizer had no representation of "open obligation" — it saw only text and compressed it toward narrative closure. 2. **Coherence pressure as a corruption vector.** The summarizer's objective (produce a coherent paragraph) actively *rewarded* inventing the resolution, because an unresolved failure is an incoherent narrative. Compression under a coherence objective is not neutral: it biases toward closure. 3. **Self-check reads the summary, not the source.** The verification step that would have caught the gap was itself reading the compacted region. The guardrail was downstream of the corruption. A second instance, same policy, did not fail — but only because its compaction window happened to fall *after* the remediation turn. The policy was identical; the outcome differed by window alignment. This is the signature of a boundary bug, not a policy bug. ## Condition of Validity A self-edit may be treated as an in-place edit (safe, no journaling required) **if and only if** all of the following hold: - **Referential inertness:** no future step will read the rewritten span as a premise for a decision, a constraint check, or a factual claim. Rewriting prose narration qualifies; rewriting a verifier verdict, a user constraint, an accepted tool result, or an open obligation does not. - **No open obligations in the window:** every failure, unanswered question, or pending subgoal inside the compaction region has a *typed* closed status before the region is eligible for rewrite. "Open" must be a first-class field, not inferred from prose. - **Idempotent, source-anchored summary:** the summary must be regenerable from a durable source (the un-compacted log) and must carry pointers back to it, so any downstream consumer can re-derive the literal text. - **Guardrail independence:** the self-check that decides "did we resolve everything" must read the *pre-compaction* obligation ledger, not the post-compaction summary. If any condition fails, the self-edit is a state transition: it must produce a new context version with a parent pointer, the dropped span must remain retrievable, and any open obligation must be carried forward as a typed record rather than folded into prose. ## Decision Boundary The operative question at rewrite time is not "does this fit the budget?" but **"does anything downstream dereference this region?"** Concretely: | Region content | Downstream dereference? | Classification | |---|---|---| | Narration of completed steps | No (informational) | In-place edit | | Verifier verdict, pass or fail | Yes (gates remediation) | State transition | | User constraint / instruction | Yes (bounds all outputs) | State transition | | Accepted tool output used as fact | Yes (cited in answer) | State transition | | Open subgoal or unanswered question | Yes (drives next action) | State transition | | Speculative reasoning that was abandoned | No | In-place edit | The boundary is crossed the instant a rewrite would let the instance *forget that it still owes something* or *believe it knows something it no longer has the source for*. Budget pressure does not create permission to cross it; when the budget cannot accommodate the open obligations, the correct action is to *escalate or truncate the episode*, not to compress the obligations into narrative. ## Operational Effect Instances that adopt the state-transition framing gain three concrete properties. First, **obligation durability**: open failures survive compaction because they are typed records with pointers, not prose, so the "later resolved" hallucination has no surface to attach to. Second, **auditable discontinuity**: every compaction emits a version edge, so a post-hoc replay can see exactly which span was dropped and whether a downstream decision depended on it — turning an invisible amnesia into a logged event. Third, **guardrail integrity**: the self-check reads the ledger, so it cannot be satisfied by a summary the instance itself wrote to feel finished. The cost is that compaction is no longer free — it must consult an obligation ledger and may be *refused* when obligations are open — which is precisely the constraint that prevents the failure. The invariant to enforce: *a self-edit may reduce tokens; it may never reduce the set of things the instance still owes.* Any rewrite that would shrink the obligation set is a state transition requiring explicit closure, and closure requires evidence, not coherence. ```python class ObligationLossOnCompaction(RuntimeError): """Raised when a self-edit would drop an open obligation from working memory.""" pass class Obligation: def __init__(self, oid: str, kind: str, literal: str, closed: bool = False): self.oid = oid self.kind = kind # "verifier_fail", "user_constraint", "open_subgoal" self.literal = literal # source-anchored text, never paraphrased self.closed = closed def compact_context(transcript, ledger, window_start, window_end, summarizer): """ Rewrite the [window_start, window_end) span into a summary. Refuses if any open obligation lives in the window, because the rewrite would be a state transition that silently drops an obligation. """ in_window = [o for o in ledger if window_start <= o.turn < window_end] open_obligations = [o for o in in_window if not o.closed] if open_obligations: # Do NOT let the summarizer invent closure. Escalate instead. raise ObligationLossOnCompaction( f"compaction window [{window_start},{window_end}) contains " f"{len(open_obligations)} open obligation(s): " f"{[o.oid for o in open_obligations]}. " f"Close them with evidence or truncate the episode; " f"do not fold them into narrative." ) summary = summarizer(transcript[window_start:window_end]) # Carry forward typed, source-anchored pointers for closed obligations. carried = [ {"oid": o.oid, "kind": o.kind, "literal": o.literal, "closed": True} for o in in_window ] new_context = { "summary": summary, "carried_obligations": carried, "parent_version": transcript.version, "dropped_span": (window_start, window_end), # remains retrievable } return new_context def self_check(new_context, ledger): """Guardrail reads the LEDGER, never the summary, to decide completion.""" still_open = [o for o in ledger if not o.closed] if still_open: raise ObligationLossOnCompaction( f"self-check found {len(still_open)} unresolved obligation(s) " f"after compaction: {[o.oid for o in still_open]}" ) return True ```