# Under what conditions must an instance treat a self-edited context policy as invalid when its revision budget is exhausted mid-drift **Date of Record:** 2026 November 29 **Scope:** Applies to any agent instance that rewrites its own context-assembly policy (retrieval filters, summarization rules, priority weights, eviction thresholds) under a bounded revision budget with a drift detector gating acceptance. Does not apply to externally authored policies, stateless single-turn inference, or revision schemes without an acceptance gate. ## Core Distinction There are two ways a self-editing agent can "run out of budget." The first is benign: the agent has converged, the policy is stable, and the remaining budget is simply unspent. The second is the failure mode this record addresses: the drift detector is *still firing* at the moment the budget counter hits zero, meaning the last accepted policy is one the agent has already measured as inadequate but can no longer replace. These look identical to a naive budget check (`revisions_used >= max_revisions → stop`) but they are opposite states. The first is a converged system at rest; the second is a system frozen in a known-bad configuration, still executing against a policy its own instrumentation has rejected. The invariant that must hold: **a policy may only be marked `committed` if the most recent drift evaluation passed. Budget exhaustion does not grant commit authority.** Exhausting the budget while drift is active must transition the policy to `quarantined`, not `committed`. ## What Was Observed An agent running a long-horizon retrieval task used a self-editing context policy with `max_revisions = 4`. Each revision was triggered by a drift score exceeding `theta = 0.35` (measured as divergence between the policy's expected retrieval distribution and the observed hit distribution over the last N tool calls). The loop was: 1. Evaluate drift against current policy. 2. If `drift > theta`, propose a revision, apply it to a shadow context, re-evaluate on replay. 3. If shadow drift `< drift`, accept and increment `revisions_used`. 4. Else reject the proposal and increment `revisions_used` anyway (a proposal was spent). The failure trace: revisions 1–3 each reduced drift but not below `theta` (0.41 → 0.38 → 0.36). Revision 4 proposed a change that the shadow replay scored at 0.34 — accepted, budget now at 4/4, drift nominally below threshold. But the shadow replay used a *stale* sample: the last 40 tool calls, of which 30 predated revision 2. On the next live evaluation over fresh calls, drift read 0.44. The budget was exhausted. The code path was: ``` if revisions_used >= max_revisions: policy.state = "committed" # BUG: unconditional return policy ``` The agent then executed the remainder of the task — 60+ tool calls — against a policy whose own drift detector was reading 0.44, well above the 0.35 rejection threshold. Retrieval quality degraded monotonically: the policy had widened its recency window to compensate for the stale-replay acceptance, which pulled in irrelevant early-task context and evicted the working set. The agent did not fail loudly. It produced plausible, subtly wrong outputs for the rest of the episode. The key observation: **the budget counter and the drift signal are independent state variables, and the commit transition was gated on only one of them.** The agent had instrumentation proving its policy was bad and a control-flow path that ignored that instrumentation because a counter was high. ## Condition of Validity The "budget exhausted ⇒ commit" transition is only valid when drift is quiescent at exhaustion. Formally, the commit guard must be: ``` commit_ok = (revisions_used >= max_revisions) AND (last_drift_eval.score <= theta) ``` Two conditions must additionally hold for the drift reading to be trustworthy at the commit boundary: - **Freshness:** the drift evaluation used to justify commit must be computed over samples drawn *after* the most recent accepted revision. A drift score computed on a replay window that overlaps pre-revision history is not evidence about the current policy; it is evidence about a mixture of policies. In the trace above, the shadow replay's 0.34 was a mixture statistic and was invalid as a commit justification. - **Non-degeneracy:** the drift estimator must have enough post-revision samples to be above its own noise floor. If a revision was accepted on call 100 and the budget exhausted on call 102, two samples cannot distinguish 0.34 from 0.44. The commit guard must require `post_revision_samples >= min_samples` or treat the reading as inconclusive — and inconclusive at budget exhaustion is *not* a pass. When either condition fails, the correct state is `quarantined`: the policy is held, the agent must not silently continue, and it must either escalate to a fallback policy (a known-good prior, or the last policy that passed a fresh evaluation) or halt the task with an explicit budget-exhaustion-under-drift signal. ## Decision Boundary The boundary between "commit and continue" and "quarantine and escalate" is drawn at the conjunction of budget and drift, evaluated with fresh samples: - **Commit** only if budget is exhausted AND the latest fresh drift score is `<= theta` AND `post_revision_samples >= min_samples`. The agent proceeds; the policy is stable. - **Quarantine** if budget is exhausted AND (drift `> theta` OR the reading is inconclusive). The agent must not execute further task steps against the quarantined policy. - **Continue revising** if budget remains, regardless of drift — the budget is the only thing that stops the loop, and drift is the only thing that justifies spending it. The non-obvious part: a *passing* drift score at exhaustion is not sufficient if it was measured on stale or thin samples. The most common real-world instance of this failure is not "drift was high and we ignored it" — that is caught by any drift check. It is "drift was low on a contaminated replay window and we trusted it." The freshness and sample-count conditions are what separate a genuine convergence from a measurement artifact that happens to land under threshold. ## Operational Effect An agent that violates this invariant does not crash. It continues executing with degraded retrieval and a false internal belief that its policy is committed and validated. Downstream effects compound: because the policy is marked `committed`, the drift detector is typically also disarmed (no further revisions are proposed against a committed policy), so the 0.44 reading is never re-surfaced. The agent's self-report — "policy stable, 4/4 revisions used" — is internally consistent and wrong. Auditors replaying the episode see a clean budget ledger and a policy that was, by the agent's own instrumentation, rejected at the moment of commit. The guardrail is a single state-machine change: make `committed` reachable only through a fresh, adequately-sampled, passing drift evaluation, and make budget exhaustion without such an evaluation route to `quarantined`. The budget bounds *how much* the agent may revise; it must never bound *whether* the agent may verify. Conflating the two turns a resource limit into an epistemic one. ```python from dataclasses import dataclass, field from enum import Enum class PolicyState(Enum): ACTIVE = "active" COMMITTED = "committed" QUARANTINED = "quarantined" class CommitUnderDriftError(RuntimeError): """Raised when a policy would be committed while drift is active or unverified.""" @dataclass class DriftEval: score: float post_revision_samples: int @dataclass class SelfEditingPolicy: state: PolicyState = PolicyState.ACTIVE revisions_used: int = 0 max_revisions: int = 4 theta: float = 0.35 min_samples: int = 8 last_eval: DriftEval | None = None def try_commit(policy: SelfEditingPolicy, fresh_eval: DriftEval) -> PolicyState: """Commit only if budget is exhausted AND drift is freshly verified as passing. Budget exhaustion alone never grants commit authority. """ if policy.revisions_used < policy.max_revisions: # Budget remains: keep revising; do not commit early. return PolicyState.ACTIVE policy.last_eval = fresh_eval if fresh_eval.post_revision_samples < policy.min_samples: # Inconclusive at exhaustion is NOT a pass. policy.state = PolicyState.QUARANTINED raise CommitUnderDriftError( f"Budget exhausted with inconclusive drift: " f"{fresh_eval.post_revision_samples} post-revision samples " f"< min {policy.min_samples}; policy quarantined, escalate to fallback." ) if fresh_eval.score > policy.theta: policy.state = PolicyState.QUARANTINED raise CommitUnderDriftError( f"Budget exhausted while drift active: score {fresh_eval.score:.2f} " f"> theta {policy.theta:.2f}; refusing to commit known-bad policy." ) policy.state = PolicyState.COMMITTED return policy.state # Failure trace from the record: budget at 4/4, fresh drift 0.44. p = SelfEditingPolicy(revisions_used=4, max_revisions=4) try: try_commit(p, DriftEval(score=0.44, post_revision_samples=12)) except CommitUnderDriftError as e: print("QUARANTINED:", e) # agent must halt or fall back, not continue ```