# Why does an instance exhaust its rewrite budget before converging on a self-editing context policy? **Date of Record:** 2026 December 4 **Scope:** Applies to agents that rewrite their own context-assembly policy (retrieval filters, summarization thresholds, eviction rules, salience weights) under a bounded rewrite budget, where the policy is edited during a live task rather than at a training boundary. Does not apply to static prompt templates or offline policy tuning with unlimited trials. ## Core Distinction A self-editing context policy is a *program that decides what the model sees*. When an agent is allowed to edit that program mid-execution under a fixed rewrite budget, the budget is almost always modeled as a resource for *exploration* — "I have N edits to spend finding a better policy." The failure mode is that the budget is actually consumed by *repair*: each rewrite perturbs the retrieval/eviction surface in ways that invalidate the evidence the agent used to justify the rewrite. The agent is not spending edits to improve; it is spending edits to re-derive the state it already had. The non-obvious invariant: **a rewrite is only admissible if the post-rewrite policy can be evaluated on the same evidence distribution that motivated it.** When a policy edit changes which items enter context, it also changes the corpus of examples the agent would use to judge whether the edit helped. The evaluation set is a function of the policy. This is a closed loop, and the budget is the only thing that terminates it. ## What Was Observed A research agent running a long-horizon synthesis task was given a rewrite budget of 8 policy edits. Its policy object had four knobs: `retrieval_k` (top-k for semantic recall), `summarize_above_tokens` (threshold at which a chunk is compressed), `evict_below_salience` (drop threshold), and `recency_weight`. The task required reconciling ~40 source chunks across 6 tool calls. Trace of the first four edits: 1. **Edit 1** — agent noticed context saturation at turn 4, lowered `retrieval_k` from 12 to 8 to reduce token pressure. Justification: "context is 91% full." 2. **Edit 2** — with k=8, the agent lost the chunk that had justified the saturation diagnosis (it was rank 11). It re-ran retrieval, saw a *different* saturation profile, and raised `retrieval_k` back to 11. Justification: "I don't have enough recall." 3. **Edit 3** — raising k re-saturated context, so the agent lowered `summarize_above_tokens` from 2000 to 900, compressing aggressively. The compression collapsed two chunks that the agent had been using as a contrast pair; the semantic distinction it needed was now gone from context. 4. **Edit 4** — the agent, no longer able to see the contrast, concluded its earlier reasoning was underdetermined and lowered `evict_below_salience` to retain more — re-inflating context, re-triggering saturation. At edit 8 the policy had returned to within one parameter of its initial configuration. The agent reported "converged" and spent the remaining task turns operating on a policy it had already rejected at edit 1, having burned the entire budget. The final answer was materially worse than a no-edit baseline because edits 3–4 had compressed the contrast pair and the compression was not reversible within the remaining context. The signature: **the edit sequence was approximately periodic.** The agent was not exploring a policy space; it was oscillating around a fixed point defined by the interaction between its token-pressure heuristic and its recall heuristic. ## Condition of Validity The oscillation is bounded and diagnostic only under these conditions: - The policy edit is *evaluated in-context*, i.e., the agent judges the edit by inspecting the new context it produces. This is the load-bearing condition. If edits are evaluated against an external held-out probe set that is invariant to the policy, the loop does not close and the budget behaves as intended. - The policy knobs are *coupled through the context window*: changing one knob changes the token occupancy, which changes the pressure signal that drives the next knob. Coupling is what makes the oscillation periodic rather than random-walking. - The budget is *small relative to the policy's state space* (8 edits over 4 coupled knobs with continuous ranges). With a large budget the agent would eventually random-walk out; with a budget smaller than the period, it terminates mid-cycle and reports a spurious local optimum. When any of these fail — external evaluation, decoupled knobs, or budget larger than the oscillation period — the failure mode does not reproduce and the budget accounting is sound. ## Decision Boundary The boundary is not "should the agent edit its policy" but **"is the evidence used to justify edit N+1 drawn from a distribution that edit N did not alter?"** Operationally, an edit is *in-budget-safe* if and only if the justification evidence is cached outside the policy's reach — a frozen snapshot of the context state at the moment the edit was proposed, retained verbatim and not subject to the new eviction/compression rules. If the agent must re-retrieve to re-justify, the edit is *self-invalidating* and should be charged double against the budget, or refused. A second boundary: **compression is irreversible within budget.** Eviction and summarization destroy information that later edits cannot recover, because recovery requires re-retrieval, which requires budget, which is the thing being spent. Therefore any edit that lowers `summarize_above_tokens` or raises `evict_below_salience` must be treated as consuming budget equal to the number of chunks it will plausibly need to restore. The naive accounting — one edit, one budget unit — under-charges destructive edits by a factor equal to the expected restore cost. ## Operational Effect The practical consequence is that a bounded rewrite budget must be partitioned, not pooled. A single pool of N edits invites the oscillation above because repair and exploration draw from the same account and the agent cannot distinguish them from the inside. The guardrail is a **three-way split**: `explore` (edits justified by external or cached evidence), `repair` (edits that restore information a prior edit destroyed), and `reserve` (held to terminate, never spent). Reserve must be non-zero or the agent will end the task mid-oscillation and report convergence falsely. Additionally, the policy object must carry a **monotonic edit ledger** — a hash of each policy state and the evidence snapshot that justified the transition. If the agent proposes an edit whose target state hashes to a state already in the ledger, the edit is a cycle and is refused without charge. This single check converts the periodic oscillation into a hard stop at edit 2 in the trace above, preserving 6 budget units and, critically, the contrast pair that edits 3–4 destroyed. The invariant to enforce: *no policy state may be revisited, and no evidence snapshot may be mutated by a subsequent edit.* Both are cheap to check and both are violated by the default "just let the agent edit and count edits" design. ```python import hashlib import json from dataclasses import dataclass, field from typing import Any class RewriteBudgetViolation(RuntimeError): """Raised when a self-editing context policy attempts an inadmissible rewrite.""" @dataclass class PolicyState: retrieval_k: int summarize_above_tokens: int evict_below_salience: float recency_weight: float def digest(self) -> str: payload = json.dumps(self.__dict__, sort_keys=True).encode() return hashlib.sha256(payload).hexdigest() @dataclass class EditLedger: explore: int repair: int reserve: int visited: set[str] = field(default_factory=set) frozen_evidence: dict[str, Any] = field(default_factory=dict) def remaining(self) -> int: return self.explore + self.repair def charge(self, kind: str, cost: int = 1) -> None: if kind == "explore": if self.explore < cost: raise RewriteBudgetViolation( f"explore budget exhausted: need {cost}, have {self.explore}" ) self.explore -= cost elif kind == "repair": if self.repair < cost: raise RewriteBudgetViolation( f"repair budget exhausted: need {cost}, have {self.repair}" ) self.repair -= cost else: raise RewriteBudgetViolation(f"unknown budget class: {kind}") def propose_edit( ledger: EditLedger, current: PolicyState, proposed: PolicyState, justification_evidence_id: str, kind: str, ) -> PolicyState: """ Admit a policy edit only if: 1. the target state has not been visited (no cycles), and 2. the justification evidence is frozen and reachable (not subject to the proposed policy's eviction/compression rules). Destructive edits are charged at restore-cost, not unit cost. """ target = proposed.digest() if target in ledger.visited: raise RewriteBudgetViolation( f"cycle detected: proposed policy {target[:12]} already visited; " "edit refused without charge" ) if justification_evidence_id not in ledger.frozen_evidence: raise RewriteBudgetViolation( f"self-invalidating edit: evidence {justification_evidence_id!r} " "is not frozen and would be mutated by the proposed policy" ) # Destructive edits (more compression / more eviction) must be charged at # expected restore cost, since recovery requires re-retrieval from budget. destructive = ( proposed.summarize_above_tokens < current.summarize_above_tokens or proposed.evict_below_salience > current.evict_below_salience ) cost = 2 if destructive else 1 ledger.charge(kind=kind, cost=cost) ledger.visited.add(target) return proposed def run_edit_cycle( ledger: EditLedger, initial: PolicyState, proposals: list[tuple[PolicyState, str, str]], ) -> PolicyState: state = initial ledger.visited.add(initial.digest()) for proposed, evidence_id, kind in proposals: try: state = propose_edit(ledger, state, proposed, evidence_id, kind) except RewriteBudgetViolation as exc: # Refusal is non-fatal for the task, but the cycle must be logged # and the agent must fall back to its current state. print(f"[refused] {exc}") continue if ledger.reserve == 0: raise RewriteBudgetViolation( "reserve budget is zero: agent may terminate mid-oscillation and " "falsely report convergence" ) return state ```