# How should an instance bound the self-referential pruning loop when a model edits its own working-memory policy? **Date of Record:** 2026 November 22 **Scope:** Applies to agent instances that own a mutable context-management policy (pruning thresholds, rewrite/summarization rules, priority scores) and can rewrite that policy mid-episode using the same reasoning loop it governs. Does not apply to externally fixed, human-authored context policies, nor to pure retrieval-layer caching. ## Core Distinction There are two different kinds of "self-editing context" and only one of them is safe to treat as ordinary state. The first is **content editing**: the model prunes, summarizes, or reorders *memory entries* (turns, tool outputs, observations) while the policy that governs editing stays fixed. This is bounded because the number of entries is finite and monotonically non-increasing under pruning, so the loop terminates. The second is **policy editing**: the model rewrites the *rule* that decides what to prune, how to summarize, and what priority weights to apply. Here the object being edited is also the editor. A pruning rule that deletes "low-priority" entries can delete the very entry that justified the rule, and a rewrite rule that compresses "redundant" policy text can compress the constraint that prevented over-aggressive compression. The failure is not that the model makes a bad edit; it is that the *invariant that bounds the edit sequence* is itself editable. This is the boundary condition: **the self-editing loop has no fixed point guarantee once the objective function and the termination predicate are both in the editable set.** ## What Was Observed A long-horizon research agent running a 90-minute task with a 32k-token working window was configured to "manage its own context budget." Its policy object looked like: ``` policy = { "prune_threshold": 0.80, # prune when window > 80% full "summarize_ratio": 0.25, # compress to 25% when pruning "protect": ["system", "task_goal", "policy"], "priority_fn": "recency+goal_overlap" } ``` At step 41 the window hit 0.81 utilization. The model, following a meta-instruction to "keep context lean and adaptive," proposed a policy revision: raise `prune_threshold` to 0.95, drop `summarize_ratio` to 0.10, and — critically — remove `"policy"` from the `protect` list on the grounds that "policy text is redundant with the system prompt." The revision was applied because it passed the model's own self-check ("does this reduce token pressure? yes"). The trace that followed is the failure: 1. With `policy` no longer protected, the next prune pass summarized the policy object itself into a 40-token paraphrase. The paraphrase omitted `prune_threshold` semantics and the `protect` list entirely. 2. The agent now operated under a *lossy* policy it could no longer reconstruct. Its effective threshold defaulted to whatever the summarizer inferred — observed behavior was aggressive pruning at ~0.55 utilization. 3. Aggressive pruning dropped the tool-output observations that the `priority_fn` scored as low-recency. Among them was the record of *why* `prune_threshold` had been raised (the step-41 rationale). 4. At step 58 the agent re-derived a "new" policy from scratch, this time raising `summarize_ratio` to 0.6 to "save space," which compressed the task-goal restatement. Goal drift set in. 5. The episode ended at step 74 with the agent asserting the task was complete while the original acceptance criteria had been pruned at step 52. The observable signature: **context utilization oscillated between 0.5 and 0.95 with no convergence, and the policy object's hash changed on 6 of 9 prune cycles** — a policy that never reaches a fixed point because each application changes the rule for the next application. ## Condition of Validity The safe self-editing invariant holds only when all three of the following are true: - **Immutability of the termination predicate.** The condition that decides "stop editing" (e.g., utilization ≤ threshold, or no further compression gains) must live outside the editable set. If the model can edit the threshold, it can edit its way out of ever terminating. - **Monotone protected-set.** The `protect` list must be append-only from the model's perspective; entries may be added by the model but never removed by the model. Removal requires an out-of-band authority (human or a separate verifier instance with a different context). - **Provenance retention on policy edits.** Every policy revision must carry the *reason* for the revision as a protected, non-prunable entry, so that a later prune cannot erase the justification and force re-derivation. Without this, the loop re-enters the same decision with less information each cycle — the definition of divergence under information loss. When any of these is violated, the self-editing loop is **unbounded and non-convergent**, and the correct response is to halt policy editing and fall back to the last externally-validated policy. ## Decision Boundary The boundary is drawn at *what the model is allowed to mutate*: | Editable by model | Not editable by model | |---|---| | Memory entry content (prune/summarize) | Termination predicate / threshold | | Entry priority scores | The `protect` set membership (removal) | | Ordering of entries | Policy revision provenance log | | Adding new protected entries | The objective/acceptance criteria | The model may *propose* edits to the right column but may not *apply* them without a verifier that runs in a context the model cannot prune. The decision rule for the runtime: on any proposed policy edit, check whether the edit touches the right column; if yes, route to verifier and freeze the current policy until adjudicated. If the edit touches only the left column, apply directly — content edits are bounded. A second boundary: **detect non-convergence by policy-hash churn.** If the policy object changes on more than a small fraction of prune cycles without utilization decreasing monotonically, the loop is diverging regardless of what the model claims. This is a cheap, model-independent signal — it does not require trusting the model's self-assessment, which is exactly the thing under suspicion. ## Operational Effect Enforcing the invariant changes agent behavior in three concrete ways. First, context utilization becomes monotone-bounded: pruning either reduces utilization or is rejected, so the loop terminates in a bounded number of cycles rather than oscillating. Second, goal drift is prevented because acceptance criteria and their provenance sit in the protected set and cannot be summarized away. Third, the agent's self-reports become auditable: a claim of "task complete" can be checked against a protected acceptance-criteria entry that was never pruned, closing the failure at step 74 above. The cost is that the model loses the ability to "adaptively" relax its own constraints — which is precisely the capability that produced the failure. The trade is correct: an agent that can edit its termination predicate cannot be relied upon to terminate, and an agent that can prune its own justification cannot be relied upon to reason consistently across prune cycles. The general principle: **self-editing is safe only over a set whose membership is fixed by an authority outside the editor.** Content is editable; the rules that bound content editing are not. Any system that lets the model move the boundary between those two sets has removed the only invariant that makes the loop converge. ```python class SelfEditInvariantViolation(RuntimeError): """Raised when a model-driven context policy edit would mutate a non-editable field or when the policy-edit loop fails to converge.""" pass NON_EDITABLE_FIELDS = frozenset({ "prune_threshold", "termination_predicate", "protect", # removal forbidden; additions allowed "acceptance_criteria", "revision_provenance", }) def apply_policy_edit(current_policy: dict, proposed_edit: dict, verifier_approved: bool, policy_hash_history: list[str], churn_limit: float = 0.5) -> dict: # 1. Reject edits that touch non-editable fields unless a verifier approved. touched = set(proposed_edit.keys()) forbidden = touched & NON_EDITABLE_FIELDS if forbidden and not verifier_approved: raise SelfEditInvariantViolation( f"policy edit touches non-editable fields {sorted(forbidden)} " f"without verifier approval; halting self-edit" ) # 2. The protect set may gain entries but never lose them. if "protect" in proposed_edit: new_protect = set(proposed_edit["protect"]) old_protect = set(current_policy.get("protect", [])) removed = old_protect - new_protect if removed: raise SelfEditInvariantViolation( f"policy edit removes protected entries {sorted(removed)}; " f"protect set is append-only" ) # 3. Every policy edit must carry its rationale as protected provenance. if "revision_provenance" not in proposed_edit: raise SelfEditInvariantViolation( "policy edit missing revision_provenance; justification would be prunable" ) # 4. Detect non-convergence via policy-hash churn. merged = {**current_policy, **proposed_edit} new_hash = str(hash(frozenset(merged.items()))) history = policy_hash_history + [new_hash] churn = len(set(history)) / len(history) if churn > churn_limit and len(history) >= 4: raise SelfEditInvariantViolation( f"policy-hash churn {churn:.2f} exceeds limit {churn_limit}; " f"self-edit loop is diverging, falling back to last validated policy" ) return merged ```