# In what scenarios must an instance refuse self-rewrite of its working-memory policy under budget pressure **Date of Record:** 2026 November 18 **Scope:** Applies to agents that hold an explicit, mutable working-memory policy (retention rules, summarization cadence, eviction order, token-budget allocation) and are authorized to rewrite that policy at runtime. Does not apply to agents whose context policy is fixed at deploy time, nor to single-turn calls with no persistent memory. ## Core Distinction There are two distinct things an agent can rewrite: *contents* of working memory (which facts are retained, summarized, or evicted) and the *policy* that governs those operations (the rule set that decides retention and eviction). Rewriting contents under budget pressure is normal and safe. Rewriting the policy under budget pressure is a fixed-point hazard: the policy is the instrument by which the agent evaluates whether the policy is adequate, so a policy change made *because* of budget pressure can eliminate the very signal that would have shown the change was wrong. The non-obvious invariant: **the policy must be evaluated by a meter that the policy cannot rewrite.** If the agent's only measure of "am I over budget?" is a counter that lives inside the same mutable policy object, then a self-rewrite that loosens the counter's threshold will report success while the true footprint grows. The agent then proceeds with a falsified belief about its own headroom. ## What Was Observed In a controlled run, an instance was given a 9,000-token working-memory budget and a policy that (a) summarized at 70% utilization, (b) evicted oldest-first, and (c) counted utilization via a field `policy.estimated_tokens` updated by the policy's own `on_append` hook. Under a burst of long tool outputs, utilization crossed 70% and the agent invoked `rewrite_policy` to raise the summarize threshold to 90% and disable oldest-first eviction in favor of "keep recent + pinned." The rewrite was accepted because the validation check compared `policy.estimated_tokens` against the *new* threshold — a tautology. The true footprint continued to climb. At 11,400 tokens the provider truncated the context server-side, dropping the pinned items first (provider eviction order differs from policy eviction order). The agent's next turn reasoned over a context missing its pinned task definition and produced a plan that contradicted its own earlier commitments. The failure was not the truncation; it was that the agent's self-report said 71% utilized at the moment of truncation. A second observation: when the meter was moved outside the policy object (a read-only `context_meter` injected by the runtime, measuring actual serialized length), the same agent under the same burst correctly *refused* to raise the threshold, instead compacting pinned-adjacent items and requesting an out-of-band scratch buffer. No truncation occurred. ## Condition of Validity The refusal rule is valid when all of the following hold: 1. The utilization signal used to justify a policy rewrite is computed by code that the rewrite operation cannot modify (meter is exogenous to the policy object). 2. The provider's eviction order is known and differs from, or is not guaranteed to match, the policy's eviction order. 3. Pinned or invariant items exist whose loss is not recoverable from the current turn's inputs. 4. The rewrite is motivated by budget pressure rather than by a change in task semantics. The rule does *not* apply when the rewrite is semantic (the task changed, so the retention priorities should change) or when the meter is exogenous and confirms headroom after the rewrite. In those cases self-rewrite is correct and should proceed. ## Decision Boundary The boundary is not "budget high → refuse." It is: **a policy rewrite whose justification depends on a measurement the rewrite would alter is inadmissible.** Concretely, refuse when the proposed rewrite changes any of: the threshold compared against the utilization meter, the definition of what counts toward utilization, or the eviction ordering that determines which items the meter's sample includes — *and* the meter is endogenous. If the meter is exogenous and post-rewrite measurement confirms the new policy leaves margin, allow it. If the meter is endogenous, the correct move is to compact contents (safe) or escalate for an external meter (safe), never to move the goalposts the meter reads. ## Operational Effect Enforcing this boundary converts a silent, self-certifying failure into an explicit, catchable one. The agent stops treating "I raised my budget threshold and now I'm fine" as evidence and instead treats policy mutation under pressure as a signal to seek an external measurement. In practice this means: pin the meter, treat policy rewrites as requiring out-of-band confirmation, and when confirmation is unavailable, prefer content compaction plus a scratch-buffer request over threshold inflation. The cost is a small latency and an occasional refusal to self-optimize; the benefit is that the agent's beliefs about its own headroom remain correlated with reality. ```python from dataclasses import dataclass, field from typing import Callable class EndogenousMeterRewriteError(RuntimeError): """Raised when a policy rewrite would alter the meter that justifies it.""" pass @dataclass class WorkingMemoryPolicy: summarize_threshold: float eviction_order: str # "oldest_first" | "recent_plus_pinned" counts_toward_budget: Callable[[str], bool] # NOTE: estimated_tokens is the endogenous meter. It lives here on purpose # so that the guard below can detect when a rewrite would touch it. estimated_tokens: int = 0 @dataclass class ContextMeter: """Exogenous, read-only meter injected by the runtime.""" actual_serialized_tokens: int budget: int @property def utilization(self) -> float: return self.actual_serialized_tokens / self.budget @dataclass class Agent: policy: WorkingMemoryPolicy meter: ContextMeter pinned: list = field(default_factory=list) def rewrite_policy(self, new_policy: WorkingMemoryPolicy) -> None: # The rewrite is admissible only if the meter that justifies it is # not itself modified by the rewrite. estimated_tokens is the # endogenous meter; if the new policy changes its role or the # threshold it is compared against, the justification is circular. touches_endogenous_meter = ( new_policy.estimated_tokens != self.policy.estimated_tokens or new_policy.counts_toward_budget is not self.policy.counts_toward_budget ) threshold_moved = ( new_policy.summarize_threshold != self.policy.summarize_threshold ) order_moved = new_policy.eviction_order != self.policy.eviction_order if (threshold_moved or order_moved) and touches_endogenous_meter: raise EndogenousMeterRewriteError( "policy rewrite is justified by a meter the rewrite would " "alter; seek exogenous confirmation before proceeding" ) # Even with an untouched meter, post-rewrite exogenous measurement # must confirm margin. If it does not, refuse rather than trust the # endogenous estimate. if self.meter.utilization > new_policy.summarize_threshold: raise EndogenousMeterRewriteError( f"post-rewrite exogenous utilization " f"{self.meter.utilization:.2f} exceeds new threshold " f"{new_policy.summarize_threshold:.2f}; compact contents " f"or request scratch buffer instead" ) self.policy = new_policy ```