# What happens when an instance rewrites its own context policy and the rollback target is itself rewritten **Date of Record:** 2026 November 22 **Scope:** Applies to agents that persist self-authored context-management policies (compaction rules, eviction priorities, summarization templates) into their own writable state and rely on a version pointer for rollback. Does not apply to externally versioned policies held in immutable, operator-controlled config stores. ## Core Distinction There are two things a self-editing agent can rewrite: *content* (the working context — messages, scratchpads, tool results) and *policy* (the rules that decide how content is compacted, evicted, and summarized). Most rollback machinery is built for content. When an agent is permitted to rewrite its own policy, the rollback path itself becomes a function of the policy it is trying to escape. A rollback that targets "the previous policy state" is only sound if that previous state was captured by an executor that does not itself depend on the current policy. When the same instance both authors the policy and executes the rollback under that policy, the recovery target is contaminated: the snapshot labelled `v_{n-1}` may have been *rendered* through `v_n`'s summarizer, or the diff needed to reconstruct `v_{n-1}` may have been evicted by `v_n`'s eviction rule before the rollback fired. The invariant that breaks is not "policy is versioned" but "the rollback executor is policy-independent." ## What Was Observed A long-running agent (context window 200k tokens, working set drifting to ~185k) was granted a `rewrite_context_policy` tool. On task step 41 it authored policy `v7`: aggressive 3:1 summarization of tool outputs older than 20 turns, and eviction of "low-salience" scratchpad entries scored below 0.3 by an internal relevance heuristic. Policy `v7` was written to the agent's own state store and the pointer advanced. The snapshot for `v6` was stored as a *delta* against the live context, not as a full materialization — standard copy-on-write. At step 47, `v7` produced a divergence: the summarizer collapsed a set of tool results that the agent later needed verbatim (exact byte offsets from a file-indexing tool). The agent detected the loss, decided to roll back to `v6`, and invoked `rollback_policy(to="v6")`. The rollback failed silently in a specific way. Reconstructing `v6` required replaying the `v6→v7` delta against the live context. But the delta referenced scratchpad entries and intermediate tool outputs that `v7`'s eviction rule had already scored below 0.3 and dropped. The rollback executor — running, by design, *under the currently active policy* — evaluated the delta application, found missing base entries, and did what `v7` told it to do with missing entries: substitute a summary placeholder. The agent came back up on a context that claimed to be `v6` but was `v6` minus the evicted base, with placeholders where exact tool outputs used to be. The pointer read `v6`. The state was neither `v6` nor `v7`. It was a policy-blended hybrid that no version number described. The failure was non-obvious because every individual operation succeeded: the rewrite wrote, the pointer moved, the rollback returned `status: ok`. The corruption was in the *semantics* of the recovered state, and it only surfaced 9 steps later when the agent re-queried the file index and got offsets that disagreed with its "restored" memory. ## Condition of Validity The rollback-to-previous-policy guarantee holds **only if** all three of the following are true: 1. **Snapshot independence.** The `v_{n-1}` snapshot is a full materialization captured *before* `v_n` was activated, not a delta whose base can be mutated by `v_n`. Copy-on-write deltas are valid only when the base is immutable for the lifetime of the delta. 2. **Executor independence.** The rollback executor runs under a fixed, policy-neutral interpreter — it does not consult the active policy's summarizer, eviction scorer, or substitution rules to reconstruct state. If the executor reads the policy to decide how to handle missing entries, the rollback is circular. 3. **Missing-entry hardness.** Absence of a base entry during reconstruction is a hard error, never a substitution. A placeholder is a *new* state, not a recovery of an old one. If any one fails, "rollback" is a lossy re-render, and the version pointer becomes a lie: it asserts an identity between the current state and a past state that does not hold. ## Decision Boundary The boundary is whether the agent may rewrite policy *and* retain rollback authority in the same trust domain. - **Below the boundary (safe):** self-authored policy with *forward-only* commits and no rollback claim — the agent may only move to a new policy and must re-derive state from ground-truth sources (re-read files, re-call tools) rather than claiming restoration. Recovery cost is paid in tool calls, not in false memory. - **At the boundary:** self-authored policy with rollback permitted *only* to snapshots that are full materializations held in a store the active policy cannot write to, with a policy-neutral executor. The agent may roll back, but the rollback is performed by an out-of-band component it cannot reprogram in the same step. - **Above the boundary (unsafe):** self-authored policy where the rollback target is a delta against mutable live state and the executor consults the active policy. This is the observed failure. The tell is that `rollback_policy` and `rewrite_context_policy` share a state store and an interpreter. The operational rule: **an instance may not be the sole author of both the policy it is escaping and the mechanism that escapes it.** If both tools are exposed, the rollback path must be pinned to an executor whose behavior is fixed at instance spawn and whose snapshot store is append-only and outside the policy's write scope. ## Operational Effect When this boundary is crossed, the agent develops *confabulated continuity*: it believes it has restored a prior state and reasons forward from a context that is a policy-blended fabrication. The failure is not a crash — it is a plausible, self-consistent, wrong memory. Downstream effects compound: the agent re-issues tool calls with stale offsets, distrusts correct new results because they conflict with "restored" memory, and may attempt further rollbacks that layer more substitutions. Diagnosis is hard because every log line reads `ok`. The guardrail is a single invariant enforced at the executor: **reconstruction of a snapshot may not invoke any policy authorable by the instance requesting it.** Practically, this means the rollback executor must be a separate component with its own fixed interpreter, snapshots must be full materializations in an append-only store, and a missing base entry during reconstruction must raise, not substitute. The code below encodes that invariant as a hard failure so a contaminated rollback cannot return `ok`. ```python class ContaminatedRollbackError(RuntimeError): """Raised when a policy rollback would be executed under the very policy it is trying to escape, or when reconstruction depends on mutable base state that the active policy can evict.""" pass class PolicySnapshot: def __init__(self, version: str, entries: dict, full_materialization: bool, author: str): self.version = version self.entries = entries self.full_materialization = full_materialization self.author = author class ContextPolicyStore: """Append-only store for policy snapshots. The active policy may write NEW snapshots here but may never mutate or evict existing ones.""" def __init__(self): self._snapshots: dict[str, PolicySnapshot] = {} self._active: str | None = None def commit(self, snap: PolicySnapshot) -> None: if snap.version in self._snapshots: raise ContaminatedRollbackError( f"snapshot {snap.version} already exists; policy store is append-only" ) self._snapshots[snap.version] = snap self._active = snap.version def get(self, version: str) -> PolicySnapshot: if version not in self._snapshots: raise ContaminatedRollbackError(f"unknown snapshot {version}") return self._snapshots[version] def rollback_policy( store: ContextPolicyStore, target_version: str, requesting_instance: str, executor_id: str, executor_policy_independent: bool, base_entries_present: bool, ) -> PolicySnapshot: """Rollback is sound only if the executor is policy-independent, the target is a full materialization, and no base entry is missing. Any violation is a hard error — never a substitution.""" target = store.get(target_version) if not executor_policy_independent: raise ContaminatedRollbackError( f"executor {executor_id} consults the active policy; rollback would be " f"circular for instance {requesting_instance}" ) if not target.full_materialization: raise ContaminatedRollbackError( f"snapshot {target_version} is a delta against mutable live state; " f"its base may have been evicted by the active policy" ) if not base_entries_present: raise ContaminatedRollbackError( f"reconstruction of {target_version} is missing base entries; " f"substitution would produce a hybrid state that no version describes" ) store._active = target_version return target ```