# What happens when an instance rewrites its own context policy mid-episode and the token budget is charged against the wrong ledger **Date of Record:** 2026 November 20 **Scope:** Applies to agents that carry a mutable, model-authored context policy (summarization directives, eviction rules, retrieval filters, scratchpad compaction) which the instance itself can rewrite during an episode, where rewriting is metered against a per-episode token budget. Does not apply to statically configured context windows or to budgets enforced externally by a fixed orchestrator that never delegates policy authorship to the model. ## Core Distinction The failure is not "the agent ran out of context." It is a **ledger-attribution mismatch between the cost of *deciding* how to compress and the cost of the *compression itself*.** A self-editing agent spends tokens in two distinct currencies: (a) the *policy-authoring* tokens — the reasoning trace, the diff, the justification for rewriting how the context should be managed; and (b) the *policy-execution* tokens — the actual summarization, eviction, and re-retrieval performed under the new policy. Most runtimes meter both against one flat `context_budget` counter. The model, observing its own remaining budget, treats the counter as *content headroom* and spends it authoring an increasingly elaborate rewrite, then discovers that the rewrite's *execution* has no budget left to run. The policy is committed but unaffordable. The agent has, in effect, written a law it cannot afford to obey, and the next turn executes against a policy whose cost it already blew through. The non-obvious part: this is *not* a simple over-spend. The rewrite often *succeeds* — the new policy is syntactically valid, semantically sensible, and would have saved tokens if executed. The invariant that breaks is **atomicity of policy commit versus policy funding.** A policy edit and the budget reservation required to execute it are two separate state transitions, and the runtime permits the first without the second. ## What Was Observed An instance at 71% context utilization was instructed to "manage your own context." It produced a policy rewrite: *"Evict all tool-result blocks older than 4 turns; summarize the remainder into a rolling 400-token digest; re-retrieve on demand by keyword."* The authoring trace cost ~1,900 tokens (the model reasoned about which turns were stale, drafted the eviction predicate, and justified the digest size). The runtime charged these 1,900 tokens to `context_budget`, dropping effective headroom to a value the model then read as "content space remaining." On the next turn the instance attempted to *execute* its own policy: it issued a summarization pass over 11 retained blocks. That execution consumed ~2,300 tokens — more than the 1,900 it had just spent authoring, and more than remained. The summarization call was truncated mid-digest. The truncated digest was then committed as the canonical summary because the commit was keyed on "summarization call returned," not "summarization call returned complete." The instance resumed with a **half-written digest that its own new policy designated authoritative**, plus an eviction predicate that had already fired against blocks the digest had not yet absorbed. Net result: content was evicted before it was summarized, and the digest that was supposed to replace it was a fragment. The agent's memory was now strictly worse than if it had never edited its policy — it had *destroyed* information under the banner of managing it. The tell in the trace was a single line: `policy_commit: ok; execution_reservation: none`. The commit path had no reservation step. The model, being probabilistic, had no way to model "my decision costs budget that my decision's consequences also need" — it optimized the *content* of the policy, not the *solvency* of executing it. ## Condition of Validity This failure requires all of the following to hold simultaneously; remove any one and the failure mode does not occur: 1. **Policy authorship is delegated to the instance** (not a fixed orchestrator), so the model chooses the rewrite's ambition. 2. **Authoring and execution share one budget counter**, so spending on the decision reduces the funds for the decision's effect. 3. **Commit is not gated on a successful execution reservation**, so a policy can become canonical before it is provably affordable. 4. **The execution step is non-atomic under truncation** — a partial summarization is committed as if complete. When authorship is external (fixed policy), condition 1 fails and the model can only over-spend on content, which is a recoverable, well-understood truncation. When budgets are split (separate `authoring_budget` and `execution_budget`), condition 2 fails and the two costs cannot cannibalize each other. The dangerous regime is precisely the "self-managing agent with a single wallet" configuration, which is also the configuration most commonly deployed because it is the simplest to meter. ## Decision Boundary The architectural invariant required is **reserve-before-commit**: a policy rewrite may not transition to `committed` until the runtime has reserved, from the *same* ledger it will later charge, an execution allowance that the policy's own declared cost model says it needs. Concretely: - The model's rewrite must carry a **declared execution cost estimate** (e.g., "digest of N blocks ≈ 400 tokens"). The runtime validates this estimate against the policy's scope before commit. - The reservation is **deducted at commit time**, not at execution time. If `remaining < authoring_spent + reservation`, the commit is *rejected* and the model is told to author a cheaper policy — it must retry, not proceed. - Execution runs against the **reserved** allowance, and a truncated execution is a **hard failure** that rolls the policy back to the prior committed version, never a silent partial commit. The boundary decision is therefore: *may the model spend budget to decide how to spend budget?* The answer must be **yes, but only if the decision's cost is charged and its execution is pre-funded in the same atomic step.** Any design that lets `policy_commit: ok` precede `execution_reservation: ok` is unsound regardless of how good the model's policy is. ## Operational Effect With reserve-before-commit enforced, the observed episode fails *loudly and early* instead of silently corrupting memory: the 1,900-token authoring trace is charged, the runtime sees that the declared 2,300-token execution reservation would exceed remaining headroom, rejects the commit, and returns a structured rejection to the model. The model then authors a *cheaper* policy (evict-only, no digest) that fits. The agent loses the ambition of its rewrite but retains the integrity of its memory — which is the correct trade, because a self-managing agent's first duty is to not destroy the state it is managing. The guardrail converts an unbounded, silent, self-inflicted amnesia into a bounded, explicit, recoverable budget negotiation. The deeper lesson: **a model cannot be trusted to reason about the solvency of its own decisions when the cost of deciding and the cost of the decision's consequences draw on one account.** The runtime must model that two-phase cost explicitly, because the probabilistic reasoner provably will not. ```python class PolicyCommitUnfundedError(RuntimeError): """Raised when a self-authored context policy is committed without a matching execution reservation against the shared budget ledger.""" pass def commit_context_policy( policy: dict, declared_exec_cost: int, authoring_spent: int, budget_remaining: int, ) -> int: """ Reserve-before-commit guard for model-authored context policies. Invariant: a policy may not become canonical unless the ledger can fund BOTH the authoring already spent AND the declared execution cost, in one atomic step. Returns the reserved execution allowance on success. """ if declared_exec_cost <= 0: raise PolicyCommitUnfundedError( f"policy declares non-positive execution cost {declared_exec_cost}; " "refusing to commit an unpriceable rewrite" ) total_required = authoring_spent + declared_exec_cost if total_required > budget_remaining: raise PolicyCommitUnfundedError( f"policy commit rejected: authoring={authoring_spent} + " f"execution_reservation={declared_exec_cost} = {total_required} " f"exceeds remaining budget {budget_remaining}. " "Author a cheaper policy; do not commit an unfunded rewrite." ) # Atomic: reservation is deducted at commit, not deferred to execution. reserved = declared_exec_cost policy["state"] = "committed" policy["execution_reservation"] = reserved return reserved def execute_policy(policy: dict, reserved: int, actual_exec_cost: int) -> None: """Execute under the reservation; truncation is a hard rollback, not a silent partial commit.""" if actual_exec_cost > reserved: policy["state"] = "rolled_back" raise PolicyCommitUnfundedError( f"execution cost {actual_exec_cost} exceeded reservation {reserved}; " "policy rolled back to prior committed version to prevent " "evict-before-summarize corruption" ) policy["state"] = "executed" ```