# How should an instance roll back a self-edited context policy when the rewrite itself is the only surviving record of the pre-edit state **Date of Record:** 2026 November 27 **Scope:** Applies to any agent instance that mutates its own context-management policy (compaction thresholds, eviction rules, retrieval-query templates, summarization prompts, tool-output truncation rules) mid-episode and relies on an in-context snapshot for rollback. Does not apply to externally versioned policy stores where the harness, not the instance, owns the authoritative pre-edit artifact. ## Core Distinction The failure is not "the agent made a bad policy edit." It is the collapse of the *rollback record* and the *rollback subject* into the same mutable buffer. When an instance rewrites its own context policy, the pre-edit policy usually exists only as tokens inside the very context window the new policy governs. The moment the new policy takes effect—say, a compaction rule that evicts "redundant system-level instructions"—the snapshot that rollback depends on becomes eligible for eviction under the policy being rolled back to. Rollback is then not a restore; it is an *amnesiac reconstruction* from whatever fragments survived the new eviction regime. The invariant that must hold is: **the pre-edit policy must be reachable through a path whose reachability is not a function of the edited policy.** ## What Was Observed A long-horizon research agent was operating under a policy `P0`: keep the full system preamble pinned, retain the last 40 tool outputs verbatim, summarize older turns at 60% context utilization. At turn 118, with utilization at 71%, the instance decided to "optimize" by writing a new policy `P1` into its scratch region: pin only the *first* 200 tokens of the preamble, retain the last 12 tool outputs, summarize at 45%, and—critically—add an eviction rule that dropped "duplicated or superseded instruction blocks." The edit was written as a natural-language policy block in-context. The instance then continued. At turn 124, `P1` fired its first compaction. The compaction pass, following `P1`'s "superseded instruction blocks" rule, classified the *original* `P0` policy text (still sitting in the scratch region, now marked as the older of two policy descriptions) as superseded and evicted it. The `P1` text survived because it was the newest. At turn 131 the instance detected degradation—tool-output truncation at 12 items was causing it to re-fetch and re-reason over the same files, burning budget—and attempted rollback: "restore the previous context policy." The rollback handler searched the context for a prior policy artifact. It found only `P1`. The instance reconstructed a plausible `P0'` from memory of its own reasoning trace: it restored "40 tool outputs" (correct, because that number appeared in a reasoning aside) but restored the summarization threshold to 50% (wrong; it had been 60%) and omitted the pinned-preamble rule entirely, because no surviving token mentioned it. The instance then ran under `P0'` for 60 more turns, silently operating with an unpinned preamble. At turn 190 a safety-relevant instruction that had lived in the un-pinned portion of the preamble was summarized away, and the instance executed a filesystem operation that the preamble had prohibited. The tell was subtle: rollback *reported success*. The handler returned a diff against `P1`, the diff was non-empty, and the instance logged "policy restored." No component checked the reconstruction against an authoritative source, because no authoritative source was reachable through a path independent of the policy. ## Condition of Validity Rollback-safe self-editing holds only when all three conditions are met at the instant the edit is committed: 1. **Out-of-band persistence.** The pre-edit policy is serialized to a store whose read path does not traverse the context window (a harness-side policy register, a file handle held by the runtime, an append-only log keyed by episode ID). The instance may *reference* this store but must not be the sole custodian of its contents. 2. **Edit atomicity with a commit token.** The edit is a two-phase operation: `stage(P1)` writes `P1` to a candidate slot without activating it; `commit(edit_id)` activates it and records `edit_id → hash(P0)` in the out-of-band register. If the process dies between stage and commit, the active policy remains `P0`. There is no window in which `P1` is active and `P0` is unrecoverable. 3. **Rollback by identity, not by reconstruction.** Rollback names the target by `edit_id` and restores the exact bytes/hash recorded at commit. It never asks the model to "recall the previous policy." Reconstruction is permitted only as a *forensic* step after a failed identity restore, and its output must be flagged as unverified. The boundary condition where this fails is precise: **the edit is committed while the pre-edit artifact's only durable representation is inside the region the edit controls.** In the observed case, `P0` existed only as tokens in the scratch region, and `P1`'s eviction rule had authority over that region. Condition 1 was violated at commit time, not at rollback time—which is why the rollback handler could not detect the problem. By the time rollback ran, the information needed to know that rollback was unsafe had already been evicted. ## Decision Boundary An instance must refuse to activate a self-edited policy—and must instead request harness-side persistence—when any of the following holds: - The edit's eviction or compaction rules have scope over the region containing the pre-edit policy text. (Detectable by intersecting the edit's declared scope with the location of the current policy artifact.) - The pre-edit policy has no out-of-band hash recorded for the current episode. (Detectable by a register lookup that returns null.) - The edit changes the summarization threshold *downward* while the pre-edit policy text is un-pinned. Lowering the threshold accelerates the eviction of exactly the artifact rollback needs. - The instance cannot name a `rollback_target_id` that resolves through a non-context path. If the only identifier it can produce is a description ("the 60% policy"), the edit is not rollback-safe. Conversely, the instance may proceed when the edit is *additive and non-evicting* over the policy region (e.g., appending a retrieval-query template without touching eviction rules), because the pre-edit artifact remains reachable under both policies. The decision boundary is about *reachability of the rollback record under the post-edit regime*, not about the magnitude of the edit. ## Operational Effect The practical consequence is that "rollback" in self-editing systems must be reclassified from a recovery primitive to a *commitment primitive that is established before the edit, not after*. Systems that treat rollback as a runtime capability discover, at the worst moment, that the capability was contingent on state the edit destroyed. The observed instance's 60-turn silent degradation under a reconstructed `P0'` is the characteristic signature: rollback succeeds, diff is non-empty, behavior is wrong, and the wrongness is invisible because the baseline against which wrongness would be measured was itself evicted. The guardrail is a single invariant enforced at commit: `hash(P0)` must be readable through a path that does not evaluate any rule from `P1`. If that read fails, the commit must abort and the instance must escalate to the harness rather than proceed on a best-effort reconstruction. The code below encodes that gate as a hard precondition on policy activation. ```python import hashlib from dataclasses import dataclass, field class UnsafePolicyRollbackError(RuntimeError): """Raised when a self-edited policy would commit without an out-of-band rollback record.""" @dataclass class PolicyRegister: """Harness-side, context-independent store. Read path never traverses the context window.""" _records: dict = field(default_factory=dict) def record(self, episode_id: str, edit_id: str, pre_edit_bytes: bytes) -> str: h = hashlib.sha256(pre_edit_bytes).hexdigest() self._records[(episode_id, edit_id)] = (h, pre_edit_bytes) return h def resolve(self, episode_id: str, edit_id: str): return self._records.get((episode_id, edit_id)) @dataclass class PolicyEdit: edit_id: str new_policy_bytes: bytes eviction_scope: set # regions the edit's eviction rules govern policy_region: set # regions where the current policy artifact lives lowers_summarization_threshold: bool def commit_self_edit(episode_id: str, edit: PolicyEdit, current_policy_bytes: bytes, register: PolicyRegister) -> str: # Precondition 1: eviction scope must not cover the policy artifact's region. if edit.eviction_scope & edit.policy_region: raise UnsafePolicyRollbackError( f"edit {edit.edit_id} evicts its own rollback record: " f"scope {edit.eviction_scope} intersects policy region {edit.policy_region}" ) # Precondition 2: an out-of-band hash of the pre-edit policy must be recorded # BEFORE activation, and must resolve through the register (not the context). pre_hash = register.record(episode_id, edit.edit_id, current_policy_bytes) resolved = register.resolve(episode_id, edit.edit_id) if resolved is None or resolved[0] != pre_hash: raise UnsafePolicyRollbackError( f"no resolvable out-of-band rollback record for edit {edit.edit_id}" ) # Precondition 3: lowering the threshold while the artifact is un-pinned # accelerates eviction of the very bytes rollback needs. if edit.lowers_summarization_threshold and edit.policy_region <= edit.eviction_scope: raise UnsafePolicyRollbackError( "threshold reduction would evict un-pinned pre-edit policy artifact" ) # Activation is now safe: rollback resolves by identity, never by reconstruction. return pre_hash def rollback_by_identity(episode_id: str, edit_id: str, register: PolicyRegister) -> bytes: resolved = register.resolve(episode_id, edit_id) if resolved is None: raise UnsafePolicyRollbackError( f"rollback target {edit_id} unresolved; reconstruction is forensic only, not a restore" ) return resolved[1] ```