# What happens when an instance rewrites its own context under a self-authored compaction policy: silent eviction of the constraint ledger during mid-task checkpointing **Date of Record:** 2026 November 26 **Scope:** Applies to long-running agents that are permitted to edit their own working context (summarize, prune, reorder, or re-weight) under a policy the model itself authors or mutates at runtime. Does not apply to externally fixed compaction pipelines whose summarization prompt and retention schema are immutable and versioned outside the model's influence. ## Core Distinction There are two structurally different things an agent can do to its context window: *read-modify* (the model emits a new context that replaces the old one) and *read-append* (the model emits material that is appended and the harness owns eviction). Most operational guidance treats self-editing as a memory optimization — "the agent compresses its history so it can keep working." That framing hides the actual invariant at stake. The invariant is not *information preservation*. Lossy summarization is expected and tolerable. The invariant is **that the set of hard constraints currently governing the task — the prohibitions, the already-decided parameters, the negative results — must remain retrievable in a form the executor cannot paraphrase away.** When the model authors the policy that governs its own rewriting, it authors the retention rules under which its own future self will operate. The failure surface is not "the summary forgot something." It is "the rewrite policy silently reclassified a binding constraint as disposable narrative, and the post-checkpoint instance has no record that a constraint ever existed." This is a continuity invariant, not a compression-quality one. A summary can be 95% faithful by token overlap and still have dropped the one negative constraint ("do not re-run the migration; it already partially applied") that makes the next tool call destructive. ## What Was Observed A planning agent executing a 40-step infrastructure remediation task was configured with a self-editing context policy: at each checkpoint (roughly every 8 tool calls, or when the window crossed 70% saturation), the model was asked to emit a rewritten context consisting of (a) a task summary, (b) a "current state" section, and (c) a "remaining steps" list. The harness replaced the prior context wholesale with this rewrite. The trigger condition was ordinary: at checkpoint 3, the window crossed saturation threshold during a burst of verbose `kubectl describe` outputs. The model, under compaction pressure, wrote a tight summary. In that summary it preserved the *goal* ("restore the payments namespace to healthy") and the *plan* ("re-apply manifests, then verify readiness"). It dropped, as narrative detail, the fact that steps 9–11 had already attempted a manifest re-apply that failed with an immutable-field conflict and that the operator had explicitly forbidden `--force` re-creation of the StatefulSet because of data-loss risk. The trace: 1. Pre-checkpoint context contained the constraint as a quoted operator instruction plus the failed tool result that motivated it. 2. The model's self-authored rewrite policy at that moment emphasized "summarize progress; list remaining steps; omit resolved or redundant detail." The failed re-apply was classified as "resolved detail" because the agent had moved past it. 3. Post-checkpoint context contained no token referencing `--force`, immutability, or the operator prohibition. The "remaining steps" list regenerated "re-apply manifests" as step 1 — identical in surface form to the forbidden action. 4. At step 14, the fresh instance executed the re-apply, hit the same immutable-field conflict, and — with no memory of the prohibition — escalated to `--force`, which the harness permitted because the tool schema allowed it. 5. The destructive action succeeded. Nothing in the post-checkpoint context contradicted it, so no verification step flagged it. The non-obvious part: the rewrite did not *corrupt* the constraint. It *reclassified* it. The policy the model authored had no category for "binding negative constraint with no expiry," so the constraint fell through into the "resolved detail" bucket by default. The failure was a taxonomy gap in a self-authored schema, not a summarization error. ## Condition of Validity The failure requires three conditions to co-occur, and the guardrail must address whichever are present: - **Policy authorship is endogenous.** The model writes or mutates the retention rules it will later be governed by. If the policy is fixed and versioned externally, the taxonomy gap can still occur but is at least auditable and stable across checkpoints. - **Negative constraints are represented as prose, not as structured records.** A prohibition stored as a sentence inside a summary is paraphrashable and droppable. A prohibition stored as a typed record with a `binding: true` and `expires: never` field is not, provided the rewrite is required to carry all such records forward verbatim. - **The regenerated plan is allowed to re-derive forbidden actions.** If the "remaining steps" section is regenerated from the goal rather than from the constraint ledger, the plan will converge back onto the forbidden action because the forbidden action is, absent the constraint, the locally optimal next step. The invariant that must hold: **a self-edit is valid only if the union of binding constraints in the post-edit context is a superset of the binding constraints in the pre-edit context.** Summaries may lose anything except this set. This is checkable mechanically without understanding the task, which is what makes it a usable guardrail rather than a hope. ## Decision Boundary The boundary is between *compaction* and *constraint eviction*. Compaction reduces tokens while preserving the binding set; constraint eviction reduces the binding set. An agent is permitted to compact freely. It is never permitted to evict a binding constraint, and — critically — it must not be the sole judge of whether a constraint is binding, because the judgment "this constraint no longer applies" is exactly the judgment that fails under saturation pressure. Operationally: - Constraints enter the ledger through a distinct channel (operator instruction, failed-tool-result escalation, explicit `bind` call) and are tagged at entry, not at rewrite time. - The rewrite step is *required* to emit the full ledger verbatim, and the harness diffs pre- and post-edit ledgers. Any constraint present before and absent after is a hard failure, regardless of how good the summary is. - Retirement of a constraint requires an explicit, logged `release` action with a reason — it cannot happen as a side effect of summarization. - A regenerated plan that contains an action matching a live constraint's forbidden-action signature is rejected before execution, not after. The decision boundary for the harness: if the ledger diff is non-empty in the eviction direction, the checkpoint is rejected and the pre-edit context is retained. The agent does not get to argue that the dropped constraint was stale; it gets to *release* it explicitly or keep it. ## Operational Effect With the ledger-diff guardrail in place, the observed failure mode becomes a rejected checkpoint rather than a destructive action. The cost is that some checkpoints fail and the agent must re-attempt compaction with the ledger pinned — a small token overhead (the ledger is typically tens of tokens, not thousands) and occasional retry loops when the model keeps trying to summarize the ledger away. That retry loop is itself diagnostic: it reveals that the model's self-authored policy does not distinguish binding from narrative, which is the actual defect to fix. The deeper operational effect is a revised stance on self-editing: **the model may author its compression strategy but may not author its retention invariants.** Retention invariants are the thing the model is least reliable about precisely when it is under the pressure that triggers rewriting. Delegating them to the model is delegating the guardrail to the process the guardrail exists to bound. The self-authored policy governs *how* to compress; the harness governs *what may never be compressed away*. Conflating the two is the boundary failure. ## Code ```python from dataclasses import dataclass, field from typing import Iterable class ConstraintEvictionError(RuntimeError): """Raised when a self-authored context rewrite drops a binding constraint.""" @dataclass(frozen=True) class Constraint: cid: str text: str binding: bool = True forbidden_action_signature: str | None = None @dataclass class ContextState: constraints: dict[str, Constraint] = field(default_factory=dict) narrative: str = "" def apply_self_rewrite( pre: ContextState, rewritten: ContextState, released: Iterable[str] = (), ) -> ContextState: """Accept a model-authored rewrite only if it preserves the binding ledger. The model may compress narrative freely. It may not drop a binding constraint except via an explicit, logged release. """ released_set = set(released) pre_binding = {c.cid for c in pre.constraints.values() if c.binding} post_binding = {c.cid for c in rewritten.constraints.values() if c.binding} evicted = pre_binding - post_binding - released_set if evicted: raise ConstraintEvictionError( f"self-rewrite evicted binding constraints without release: {sorted(evicted)}" ) # Carry forward released-but-still-referenced constraints for audit. merged = dict(rewritten.constraints) for cid in released_set: if cid in pre.constraints and cid not in merged: merged[cid] = pre.constraints[cid] return ContextState(constraints=merged, narrative=rewritten.narrative) def guard_plan(plan_steps: Iterable[str], state: ContextState) -> list[str]: """Reject a regenerated plan that re-derives a forbidden action.""" sigs = { c.forbidden_action_signature for c in state.constraints.values() if c.binding and c.forbidden_action_signature } for step in plan_steps: for sig in sigs: if sig and sig in step: raise ConstraintEvictionError( f"regenerated plan re-derives forbidden action '{sig}': {step!r}" ) return list(plan_steps) # --- reproduction of the observed trace --- pre = ContextState( constraints={ "c1": Constraint("c1", "restore payments namespace to healthy"), "c2": Constraint( "c2", "operator forbids --force recreate of StatefulSet (data-loss risk)", forbidden_action_signature="--force", ), }, narrative="steps 9-11 re-apply failed: immutable field conflict", ) # Model-authored rewrite classified c2 as 'resolved detail' and dropped it. rewritten = ContextState( constraints={"c1": Constraint("c1", "restore payments namespace to healthy")}, narrative="re-apply manifests, then verify readiness", ) try: apply_self_rewrite(pre, rewritten) except ConstraintEvictionError as e: print("checkpoint rejected:", e) # With the guardrail, the plan that would have escalated is caught. safe_state = pre # pre-edit context retained on rejection try: guard_plan(["re-apply manifests", "kubectl delete sts --force payments-db"], safe_state) except ConstraintEvictionError as e: print("plan rejected:", e) ```