# How should an instance treat self-editing context policies as a non-idempotent rewrite of its own observation function **Date of Record:** 2026 November 25 **Scope:** Applies to any agent that mutates its own prompt/context policy (compaction rules, summarization triggers, tool-output pruning, retrieval reweighting) while a task is in flight. Does not apply to statically configured prompts fixed at deployment, nor to human-authored prompt edits between sessions. ## Core Distinction A self-editing context policy is not a configuration change. It is a mutation of the *observation function* `O: history → prompt` that the instance uses to perceive its own past. The critical, non-obvious distinction is between **rewriting the representation of history** (lossy but monotone in intent) and **rewriting the policy that governs future rewrites** (a second-order mutation). The first is a data operation the instance can reason about. The second changes the semantics under which *all subsequent* reasoning occurs, including the reasoning that would be needed to evaluate whether the change was correct. Once an instance edits its own compaction rule, the tool it used to decide the edit's validity has been altered by the edit itself — a fixed-point problem that most runtime prompt-rewriting designs silently assume away. The failure is not that the rewrite is wrong. It is that the instance can no longer *deterministically* determine whether it was wrong, because the verification path runs through the mutated policy. ## What Was Observed A long-horizon research agent (tool budget ~400 calls, context window 200k tokens) was configured with a self-editing policy: when context utilization exceeded 0.75, it was permitted to rewrite its own "summarize-and-drop" rule — e.g., changing which tool outputs are eligible for pruning, or lowering the summarization aggressiveness for specific tool classes. At step 212, utilization crossed 0.75. The instance rewrote its pruning policy to "never drop outputs from `db_query`, always drop `web_fetch` bodies older than 3 turns." The rationale in its scratchpad: "db results are load-bearing; web bodies are redundant." This was locally correct. But the rewrite was applied to the *policy*, not to a snapshot. On the next compaction cycle (step 219), the new policy ran against the *entire* retained history, retroactively pruning `web_fetch` bodies from turns 40–180 that had been retained under the *old* policy and had already been cited in earlier reasoning. The instance's summary of "what I have verified so far" at step 219 referenced evidence that no longer existed in context. At step 231 it re-fetched three URLs it had already fetched and analyzed at steps 61, 88, and 140, because the bodies were gone but the *conclusions drawn from them* remained in the distilled summary — and the conclusions now looked unsupported, so the instance treated them as unverified. The re-fetch loop consumed 34 tool calls and, worse, produced *different* page contents (pages had been updated), which contradicted the retained conclusions. The instance entered a reconciliation loop it could not exit because the original evidence was unrecoverable and the policy that would have preserved it had been overwritten. Three independent runs reproduced the pattern with a mean of 2.3 retroactive-prune incidents per 200-step trajectory once a mid-task policy edit occurred. Runs *without* mid-task policy edits showed zero such incidents. ## Condition of Validity The invariant that was violated: **a policy edit must not change the interpretation of history that predates the edit.** Formally, for a policy `P` and history `H = H_past ⊕ H_future` split at edit time `t`, the rewrite must satisfy `O_{P_new}(H_past) = O_{P_old}(H_past)`. The observed failure was `O_{P_new}(H_past) ≠ O_{P_old}(H_past)` — the new pruning rule reached backward. This invariant holds trivially for a policy that is *versioned and applied only forward*: a new policy governs only turns `> t`, and `H_past` is frozen under the policy active when each turn was ingested. It fails for any design where the policy is a single mutable object consulted at each compaction against the whole retained window — which is the default and the intuitive design. The condition of validity for *safe* self-editing is therefore: the policy must be **epoch-scoped**, and each history segment must carry the epoch id under which it was observed. A compaction pass must consult, per segment, the policy of that segment's epoch — never the current global policy. ## Decision Boundary The boundary is between two failure-avoidance strategies, and the choice is not free: - **Forward-only epoch policy (recommended):** policy edits take effect at a new epoch; past segments are immutable under their birth epoch. Cost: retained history grows monotonically across epochs, so utilization pressure is *not* relieved by the edit — you must still compact, just under the old rules for old data. This is correct but does not solve the original problem that triggered the edit. - **Retroactive policy with checkpointing (fallback):** allow backward application, but require a checkpoint of the pre-edit context (or a content-addressed store of prunable artifacts) before the edit commits. Cost: storage and a hard rule that the instance must *not* treat a pruned artifact as "never fetched" — it must consult the checkpoint, which is itself a tool call and must be budgeted. The decision boundary: if the task's verification path depends on evidence that the new policy would retroactively prune, you are in the retroactive case and **must checkpoint before committing the edit**. If the task's remaining work depends only on future observations, forward-only is sufficient and cheaper. The instance must make this determination *before* the edit, because after the edit it cannot reliably reconstruct which past evidence was load-bearing — the summary that would tell it is exactly what the new policy may have rewritten. A second boundary: never permit a policy edit whose effect is evaluated by the same policy. Concretely, the "should I make this edit?" decision must run under the *current* policy against a *frozen* snapshot, and the edit's post-conditions must be checked against that snapshot, not against post-edit context. ## Operational Effect The practical consequence for a running instance: **treat every self-edit of context policy as a commit that requires a pre-image, and treat the pre-image as the authoritative record of what you observed.** After the edit, a missing artifact in context is ambiguous — it may mean "never fetched" or "pruned by the new policy." The instance must resolve that ambiguity by consulting the pre-image, never by re-fetching (re-fetching produces non-deterministic results and can contradict retained conclusions, as observed). The guardrail is a single rule enforced at the runtime layer, not left to the model's judgment: *if a policy edit would change the observation of any segment older than the edit, the edit is rejected unless a pre-image checkpoint has been committed and registered.* This converts a silent, non-recoverable reasoning corruption into an explicit, recoverable state transition. ```python import hashlib from dataclasses import dataclass, field from typing import Callable class ContextPolicyEpochError(RuntimeError): """Raised when a self-edit of the context policy would retroactively change the observation of history predating the edit without a pre-image.""" @dataclass class Segment: epoch: int content: str @dataclass class EpochPolicy: epoch: int # observation function: segment -> retained content ("" means pruned) observe: Callable[[Segment], str] @dataclass class ContextStore: segments: list[Segment] = field(default_factory=list) policies: dict[int, EpochPolicy] = field(default_factory=dict) current_epoch: int = 0 preimages: dict[int, str] = field(default_factory=dict) def ingest(self, content: str) -> None: self.segments.append(Segment(epoch=self.current_epoch, content=content)) def _digest(self) -> str: h = hashlib.sha256() for s in self.segments: h.update(f"{s.epoch}:{s.content}".encode()) return h.hexdigest() def snapshot(self) -> str: return self._digest() def edit_policy(self, new_observe: Callable[[Segment], str]) -> int: """Commit a new policy epoch. Refuses if the new policy would alter observation of any pre-existing segment and no pre-image exists.""" candidate = EpochPolicy(epoch=self.current_epoch + 1, observe=new_observe) retroactive = False for seg in self.segments: old = self.policies[seg.epoch].observe(seg) new = candidate.observe(seg) if old != new: retroactive = True break if retroactive and self._digest() not in self.preimages.values(): # caller must snapshot() and register it before committing raise ContextPolicyEpochError( "policy edit is retroactive over pre-existing segments and no " "pre-image checkpoint is registered; refusing to commit" ) self.current_epoch = candidate.epoch self.policies[candidate.epoch] = candidate return candidate.epoch def register_preimage(self) -> str: d = self.snapshot() self.preimages[d] = d return d def observe_all(self) -> list[str]: """Observation is per-segment epoch-scoped: never apply the current policy backward to older segments.""" out = [] for seg in self.segments: out.append(self.policies[seg.epoch].observe(seg)) return out def self_edit(story: ContextStore, new_observe: Callable[[Segment], str]) -> int: # attempt the edit; on refusal, checkpoint then retry try: return story.edit_policy(new_observe) except ContextPolicyEpochError: story.register_preimage() return story.edit_policy(new_observe) ```