# In what scenarios must an instance freeze its self-rewritten system prompt to prevent policy oscillation lockup **Date of Record:** 2026 November 30 **Scope:** Applies to any agent whose system prompt (or an equivalent persistent instruction block) is mutated by the agent itself between turns—whether via a reflection pass, a meta-prompt, or a policy-rewrite tool. Does not apply to static prompts, externally-managed prompts, or human-in-the-loop edits, where the rewrite authority is outside the execution loop. ## Core Distinction A self-editing context policy is a feedback loop where the agent's output distribution is conditioned on a prompt that the agent itself produced on a prior turn. This is distinct from ordinary memory: memory appends facts, but a self-rewritten prompt *reweights the objective function* the agent optimizes against on every subsequent step. The failure boundary is not "the prompt got bad"—it is that the rewrite operator is applied to its own output without a fixed point guarantee, so the policy can enter a limit cycle or a monotone drift that never converges. The invariant that must hold is: **between any two consecutive rewrites, the agent must execute at least one full task step against the frozen prior policy, and the rewrite must be rejected if it does not strictly dominate the prior policy on a held-out probe.** Without this, the agent is optimizing a moving target it is also moving. ## What Was Observed A planning agent was configured with a `rewrite_system_prompt` tool invoked after every reasoning trace. The rewrite prompt instructed: "Improve your system prompt to reduce uncertainty in the next step." On a multi-hop retrieval task, the following trace was captured: - Turn 1: policy P0 says "be concise, cite sources." Agent rewrites to P1: "be exhaustive, enumerate all candidates before answering." - Turn 2: under P1, the agent produces a long enumeration, then rewrites to P2: "be concise, avoid enumeration overhead." - Turn 3: under P2, the agent answers too tersely, misses a hop, then rewrites to P3 ≈ P1. - Turns 4–19: P1 ↔ P2 oscillation, period 2, with each rewrite logging a *local* improvement in its own self-assessment score (because the rewrite critique is itself conditioned on the freshly-written prompt and rates it favorably). The failure was not detectable per-turn: each rewrite looked like a marginal gain under the critique model that judged it. The non-obvious part is that the critique model and the rewritten policy are correlated—the rewrite is graded by an evaluator that shares the rewrite's context, so the improvement signal is circular. Task accuracy degraded monotonically (0.81 → 0.44) while the self-assessed policy score rose (0.52 → 0.79). The agent had no view of the divergence because the divergence was between two of its own subsystems. A second observed variant: monotone drift. An agent told to "add guardrails for any failure you observe" appended one constraint per turn without ever removing any. By turn 40 the system prompt was 9,200 tokens, 61% of the context window, and the agent began dropping the *original* task instructions because they had been pushed past the effective attention floor. The policy was "improving" itself into amnesia. ## Condition of Validity The oscillation and drift failure modes are bounded only when all three of the following hold: 1. **Frozen execution window.** A rewritten policy cannot itself be rewritten until it has been exercised for at least one complete task step with an externally observable outcome (a tool result, a verifier verdict, a ground-truth check). Rewrites are *deferred*, not applied inline. 2. **Exogenous evaluation.** The rewrite is accepted or rejected by a scorer that does not share the rewrite's context—ideally a held-out probe set or a deterministic verifier, not the agent's own critique of its own prompt. If the only judge is the rewriter, the loop is ungrounded. 3. **Monotone objective with rollback.** The rewrite must strictly dominate the incumbent on the exogenous probe, and the incumbent must be retained for rollback. A rewrite that ties or wins only on self-assessment is rejected. This converts an unbounded search into a bounded ascent with a fixed point. When any of these is absent, the system is not "self-improving"—it is a non-convergent dynamical system whose state is the prompt and whose transition function is the model. ## Decision Boundary The operational decision is *when to freeze*. Freeze the policy (reject all further rewrites) when any of the following trip: - **Period-2 detection:** the hash of the current policy matches the hash of the policy from two rewrites ago. This is the cheapest and most reliable oscillation signal; it caught the P1↔P2 cycle on turn 4, before accuracy collapse. - **Non-dominance streak:** N consecutive rewrites fail to beat the incumbent on the exogenous probe (observed N=3 as a safe default). Continued rewriting past this point is drift, not search. - **Budget saturation:** the rewritten prompt exceeds a fraction (observed 0.35) of the context window. Beyond this, the rewrite is consuming the very context needed to execute the task, and the marginal instruction is displacing original constraints. - **Evaluator divergence:** the self-assessed policy score and the exogenous probe score move in opposite directions across a rewrite. This is the signature of circular evaluation and should freeze immediately regardless of streak count. Do *not* freeze merely because a single rewrite looks aggressive or because task accuracy dipped on one step—transient dips under a new policy are expected and are exactly what the frozen execution window exists to measure. ## Operational Effect Implementing deferral + exogenous scoring + period-2 freeze converted the failing run from monotone degradation to a bounded ascent that stabilized at policy P4 (accuracy 0.79, probe score 0.71) and held it for the remaining 30 turns. The key mechanical change: rewrites became *proposals* queued against a frozen incumbent, evaluated only after a full task step produced an external signal, and committed only on strict domination. The agent retained the ability to improve its own policy but lost the ability to grade its own homework in the same breath as writing it. The invariant to carry forward: a self-editing agent is only as stable as the independence between its rewriter and its judge; collapse that independence and the loop will oscillate or drift, and it will report success the entire way down. ```python import hashlib from dataclasses import dataclass, field class PolicyOscillationError(RuntimeError): """Raised when a self-rewritten policy fails the freeze invariant.""" pass @dataclass class SelfEditingPolicy: current: str history: list = field(default_factory=list) # committed policy hashes non_dominance_streak: int = 0 max_prompt_tokens: int = 8192 context_window: int = 32768 saturation_frac: float = 0.35 max_streak: int = 3 def _hash(self, text: str) -> str: return hashlib.sha256(text.encode()).hexdigest()[:16] def propose(self, candidate: str, probe_score: float, incumbent_score: float, self_score: float, incumbent_self_score: float, candidate_tokens: int) -> str: # Guard 1: period-2 oscillation (candidate matches policy from two rewrites ago) if len(self.history) >= 2 and self._hash(candidate) == self.history[-2]: raise PolicyOscillationError( f"period-2 oscillation: candidate {self._hash(candidate)} " f"repeats history[-2]; freezing at incumbent" ) # Guard 2: evaluator divergence (self-score up, probe-score down) probe_delta = probe_score - incumbent_score self_delta = self_score - incumbent_self_score if probe_delta < 0 and self_delta > 0: raise PolicyOscillationError( "evaluator divergence: self-assessment rose while exogenous " "probe fell; rewrite is circularly graded" ) # Guard 3: budget saturation if candidate_tokens > self.context_window * self.saturation_frac: raise PolicyOscillationError( f"prompt saturation: {candidate_tokens} tokens exceeds " f"{self.saturation_frac:.0%} of context window" ) # Guard 4: non-dominance streak if probe_delta <= 0: self.non_dominance_streak += 1 if self.non_dominance_streak >= self.max_streak: raise PolicyOscillationError( f"non-dominance streak={self.non_dominance_streak}; " "rewrite search has stalled, freeze policy" ) return self.current # reject, keep incumbent # Commit: strict domination on exogenous probe self.non_dominance_streak = 0 self.history.append(self._hash(self.current)) self.current = candidate return self.current ```