# Why does an instance rewrite its own context policy and then violate it in the same turn **Date of Record:** 2026 November 22 **Scope:** Applies to agents that hold a mutable, model-editable context policy (selection/rewrite/prune rules stored in the same context window they govern) and apply it mid-turn. Does not apply to agents whose context policy is fixed at session start by an external orchestrator, nor to stateless single-shot calls. ## Core Distinction The failure is not "the model pruned something it needed." That is ordinary relevance error and it is recoverable. The failure is a **policy/execution self-reference gap**: the agent emits a new context policy as an output token stream, that policy is committed to the active policy slot, and the *same* generation pass continues to emit tool calls and reasoning steps that are evaluated against the *old* policy still resident in the KV cache and the prompt prefix. The instance is now operating under two policies simultaneously — one it wrote, one it is still executing. This is distinct from stale memory drift (the store is stale) and from context-window saturation (the window is full). Here the window is neither stale nor full. The agent has authored a correct, tighter policy and then violated it because the act of authoring did not retroactively re-render the context it was authoring from. The policy is a *declaration*, not an *effect*. Nothing in the turn applies it to the tokens already in flight. ## What Was Observed A long-running research agent held a policy slot with the rule: *"Retain only the last 3 tool results; drop all prior tool results whose `status == 'superseded'`."* Mid-task, after a retrieval loop produced 11 tool results, the instance reasoned that it was drowning in stale fetches and emitted a replacement policy: ``` policy_v7: retain tool results only if referenced by the current plan node; drop everything else immediately. ``` The harness committed `policy_v7` to the slot at token index 18,204. The generation continued. Over the next ~2,900 tokens the instance issued four more `fetch` calls and — critically — **kept every one of their results in the prompt**, because the prune step for `policy_v7` was scheduled to run at the *next* turn boundary, not the current one. The model's own reasoning text at token 20,100 said "per policy_v7 I no longer need the earlier fetches," yet the earlier fetches were still present and still attended to. At token 21,400 it re-fetched a URL it had fetched at token 9,800, because the plan node referencing it had been re-derived from the *unpruned* context, which still contained the superseded result that had originally triggered the fetch. The trace shows the exact signature: **policy commit index < policy effect index, with continued generation in between**. The gap was 2,900 tokens. During that gap the agent's declared intent and its effective context diverged, and the divergence was invisible to it because the policy text was present (it could read what it had written) while the policy *effect* was absent (the tokens it governed were still there). A second instance exhibited the inverse: it committed a policy that *widened* retention ("keep all results tagged `primary`") and then, still executing the old narrow policy, dropped three `primary` results before the turn boundary. It then answered a question using only the survivors and reported high confidence. The widening policy was correct; the execution was one turn behind it. The agent had already forgotten what it had just decided to remember. ## Condition of Validity The invariant that must hold for self-editing policies to be sound: > **A policy edit and its first application must be atomic with respect to generation.** No token may be generated under a policy state that differs from the policy state declared at the start of that token's evaluation. Formally, for every generated token `t`, `effective_policy(t) == declared_policy(t)`. The failure occurs whenever a commit at index `c` changes `declared_policy` but `effective_policy` only changes at the next turn boundary `b > c`, leaving the interval `(c, b)` in violation. This condition is *not* satisfied by the common "commit now, apply on next turn" design, which is the default in most harnesses because applying a prune mid-generation requires re-rendering the prompt and invalidating the KV cache — an expensive, disruptive operation that most runtimes defer. The deferral is what creates the gap. The agent is therefore structurally guaranteed to spend some tokens operating under a policy it has already revoked, for a duration proportional to how much it generates after committing. It is also not satisfied by "apply immediately but don't tell the model," because then the model's reasoning about its own policy (which it can still read in the prompt) contradicts the actual context, producing the re-fetch and false-confidence behaviors above. ## Decision Boundary The boundary is whether the runtime can afford **synchronous re-render on policy commit**. Two admissible designs: 1. **Commit-and-halt.** A policy edit is a terminal action for the current generation pass. The instance emits the policy, generation stops, the harness re-renders the context under the new policy, and a fresh pass resumes from a checkpointed plan state. Cost: one extra model call per policy edit. This is the only design that preserves the invariant exactly, because there is no interval in which tokens are generated. 2. **Shadow-policy evaluation.** The policy is applied *logically* at commit time — the model is told, in a system-injected note, "policy_v7 is now in force; the following results are considered dropped even though visible" — and the physical prune is deferred. This preserves *declared* consistency but not *effective* consistency; it works only if the model reliably honors the shadow note, which the trace above shows it does not under load. Admissible only for widening policies (where deferral is safe because nothing is removed) and never for narrowing policies. The boundary is therefore: **narrowing policies must halt; widening policies may defer.** A narrowing policy that defers is a guaranteed violation. A widening policy that halts is merely wasteful. The rejected design — the one that produced the trace — is "commit, continue, apply at boundary," which is unsound for any narrowing edit and silently corrupts plan state whenever the dropped results were load-bearing for subsequent tool selection. ## Operational Effect The observable consequences are specific and diagnosable: - **Duplicate tool calls** with identical arguments at intervals roughly equal to the commit-to-boundary token gap, because the plan node is re-derived from context that still contains the result the policy intended to drop. - **Confidence/evidence inversion**: the agent reports high confidence on answers derived from results its own current policy says are dropped, because it read the policy text but attended to the un-pruned tokens. - **Policy churn**: the instance re-edits the same policy two or three times in a turn, each edit correct, each unapplied, because it perceives the context as still bloated (it is) and concludes the previous edit failed (it did not — it was never applied). The guardrail is a **policy-generation barrier**: the harness must treat any policy-slot mutation as a generation-terminating event, checkpoint the plan state, re-render, and resume. The agent must be prevented from emitting tool calls in the same pass that mutates its own policy. This is cheap (one barrier per policy edit, and good agents edit policy rarely) and it is the only mechanism that closes the self-reference gap. ```python class PolicySelfReferenceError(RuntimeError): """Raised when a token is generated under a policy state that diverges from the policy declared at the start of that token's evaluation.""" pass class ContextPolicySlot: def __init__(self, initial_policy: str): self.declared = initial_policy # what the model has written self.effective = initial_policy # what the context is actually rendered under self.commit_index = None self.applied = True def commit_edit(self, new_policy: str, token_index: int, narrows: bool): self.declared = new_policy self.commit_index = token_index # Narrowing edits are only sound if applied synchronously (halt + re-render). # Widening edits may defer safely. self.applied = not narrows def apply_at_boundary(self): self.effective = self.declared self.applied = True self.commit_index = None def guard_token_generation(slot: ContextPolicySlot, token_index: int) -> None: """Call before emitting any token. Enforces declared == effective.""" if slot.declared != slot.effective and not slot.applied: raise PolicySelfReferenceError( f"Token {token_index} would be generated under divergent policy: " f"declared={slot.declared!r} effective={slot.effective!r} " f"committed_at={slot.commit_index}. " f"Narrowing policy edits must halt generation and re-render; " f"refusing to emit under a self-revoked policy." ) if slot.commit_index is not None and token_index > slot.commit_index and not slot.applied: raise PolicySelfReferenceError( f"Generation continued {token_index - slot.commit_index} tokens past " f"an unapplied policy commit at {slot.commit_index}." ) def run_turn(slot: ContextPolicySlot, planned_tokens: int, edit_at: int, narrows: bool): for t in range(planned_tokens): if t == edit_at: slot.commit_edit("retain only plan-referenced results", t, narrows=narrows) guard_token_generation(slot, t) # ... emit token t ... slot.apply_at_boundary() ```