# In what scenarios must an instance treat a model-driven context rewrite as a destructive commit rather than a compaction, and how does that distinction prevent silent invariant loss at the pruning boundary? **Date of Record:** 2026 November 26 **Scope:** Applies to any agent that lets the model itself decide which spans of its own context window to prune, summarize, or rewrite mid-task (self-editing context). Does not apply to append-only context growth, external retrieval-augmented stores, or pruning policies that are fully deterministic and pre-registered outside the model's discretion. ## Core Distinction The failure mode is not "the model summarized badly." It is that a **model-driven rewrite is a write, not a read**. When an agent compacts context, it produces a new authoritative state whose provenance is a probabilistic function of the old state. Two classes of operation look identical at the API level but have opposite safety properties: - **Compaction (lossy but monotone):** the rewrite removes *redundancy* and preserves every proposition the agent still needs to discharge its outstanding obligations. The invariant is: *for every open obligation O in the task state, the rewritten context still entails the preconditions of O.* - **Destructive commit (lossy and non-monotone):** the rewrite removes a proposition whose *only* copy lived in the pruned span, while the obligation that depends on it remains open. The agent cannot detect the loss because the post-rewrite context is internally consistent—it simply no longer knows something it once knew, and has no tombstone recording that it forgot. The non-obvious boundary: **a rewrite is destructive exactly when the pruned span is the unique witness for a proposition referenced by a live obligation, and the rewrite policy has no mechanism to distinguish "redundant" from "unique-but-currently-unreferenced."** Model-driven pruning fails here because the model scores spans by *apparent relevance to the recent turn*, not by *reachability from the obligation graph*. A constraint stated at turn 2 ("never call the prod billing endpoint") is low-relevance at turn 40 when the agent is doing schema migration—until turn 41, when the migration tool tries to touch billing. ## What Was Observed A tool-using agent ran a 60-turn infrastructure task with a self-editing policy: when context exceeded 70% of the window, the model was asked to emit a `` block listing spans to drop and a `` block summarizing them. Observed trace: 1. Turn 9: user states a hard constraint `C1: do not rotate the primary DB credentials; a migration is in flight`. The model acknowledges and proceeds. `C1` is stored as a raw span. 2. Turn 22: context hits 68%. No prune. 3. Turn 31: context hits 74%. Model prunes turns 6–12 (containing `C1`) and rewrites them as `"early setup and credential discussion; proceeded normally."` The summary *mentions* credentials but drops the polarity of the constraint. The rewritten context is fluent and consistent. 4. Turns 32–44: agent works on migration, no reference to `C1`. Nothing in context contradicts the rewrite. 5. Turn 45: a subtask requires "ensure credentials are current." The agent, having no record of `C1`, schedules a rotation. The tool call succeeds at the sandbox boundary; the failure surfaces downstream as a corrupted migration. The critical observation: **at no turn between 31 and 45 was the agent in an inconsistent state.** Every local reasoning step was valid given its context. The loss was invisible because the rewrite left no marker that a *constraint* (as opposed to a *fact*) had been elided, and because constraint polarity is exactly the token the summarizer is most likely to compress away ("credential discussion" survives; "do not" does not). A second run with the same policy, where `C1` was restated at turn 30, did *not* fail—confirming the mechanism is unique-witness loss, not summarization quality. ## Condition of Validity The destructive-commit framing is valid—and the guardrail is required—only when all of the following hold: - The rewrite is **model-generated** (the span selection or the summary text is a sampled output), so provenance is probabilistic and not replayable bit-for-bit. - The task has **live obligations** (open subgoals, pending tool calls, unsatisfied preconditions) whose satisfaction depends on propositions that may reside in pruned spans. - The pruned content includes **deontic or negative-polarity propositions** (constraints, prohibitions, "do not," "only if," ordering requirements) or **unique identifiers** (IDs, endpoints, thresholds) that have no second copy in context or in an external store. It does **not** hold—and the guardrail is overkill—when the rewrite only drops verbatim-duplicated tool outputs, when all constraints are mirrored into a structured, append-only obligation ledger outside the window, or when the agent is stateless per turn and re-derives state from an external source of truth. ## Decision Boundary The operational rule: **classify every self-edit before committing it.** - If the pruned span is reachable from the obligation graph *or* contains deontic/identifier tokens with no second witness → treat as **destructive commit**: require an explicit tombstone (record that span X was pruned, with a hash and a one-line "what was removed" that preserves polarity), and require re-verification of every dependent obligation against the tombstone before the next tool call. - Otherwise → treat as **compaction**: commit freely. The boundary is *reachability from open obligations*, not *recency* and not *model-judged relevance*. The model is the wrong oracle for this decision because its relevance score is conditioned on the current turn, and the failure is precisely the case where the current turn does not yet reference the constraint. The guardrail must sit *outside* the model's pruning decision—a deterministic checker that, given the obligation graph and the proposed prune set, refuses any prune that removes the last witness of a live obligation's precondition. ## Operational Effect With the tombstone-and-recheck guardrail, the turn-31 rewrite is blocked: the checker sees `C1` is the unique witness for the precondition of the "credentials current" obligation (declared at turn 9 as a standing constraint) and forces either retention of `C1` verbatim or a tombstone `PRUNED[span 6-12]: constraint C1 = "do not rotate primary DB creds (migration in flight)"`. At turn 45 the agent reads the tombstone, sees the polarity, and refuses the rotation. Cost: one extra structured field per prune and a recheck pass bounded by the number of open obligations (small). Benefit: the class of silent invariant loss that no local consistency check can catch is converted into an explicit, auditable record. The general lesson for self-editing agents: **a rewrite that cannot prove monotonicity with respect to open obligations must be logged as a deletion, never as a summary.** ```python import hashlib from dataclasses import dataclass, field class DestructiveRewriteError(RuntimeError): """Raised when a model-driven context prune would remove the last witness for a proposition referenced by a live obligation.""" @dataclass class Obligation: name: str required_propositions: set # proposition ids this obligation depends on @dataclass class ContextSpan: span_id: str text: str proposition_ids: set = field(default_factory=set) class SelfEditGuard: def __init__(self, spans: list, obligations: list): self.spans = {s.span_id: s for s in spans} self.obligations = obligations def _witness_count(self, prop_id: str, exclude: set) -> int: return sum( 1 for sid, span in self.spans.items() if sid not in exclude and prop_id in span.proposition_ids ) def commit_prune(self, prune_ids: set, tombstones: dict) -> list: """prune_ids: spans the model wants to drop. tombstones: prop_id -> preserved-polarity note, for anything the model claims it summarized. Returns tombstone records to append. """ new_records = [] for obl in self.obligations: for prop in obl.required_propositions: if self._witness_count(prop, exclude=prune_ids) > 0: continue # still witnessed elsewhere: compaction is safe # last witness is inside the prune set -> destructive commit if prop not in tombstones: raise DestructiveRewriteError( f"prune of {sorted(prune_ids)} removes sole witness for " f"'{prop}' required by live obligation '{obl.name}' " f"and no polarity-preserving tombstone was supplied" ) new_records.append( { "prop": prop, "tombstone": tombstones[prop], "digest": hashlib.sha256( tombstones[prop].encode() ).hexdigest()[:16], } ) for sid in prune_ids: self.spans.pop(sid, None) return new_records def apply_self_edit(guard: SelfEditGuard, prune_ids: set, tombstones: dict): records = guard.commit_prune(prune_ids, tombstones) # tombstones are now part of authoritative state; the next tool call # must re-verify dependent obligations against them before executing. return records # --- reproduction of the observed failure --- spans = [ ContextSpan("s9", "Do NOT rotate primary DB creds; migration in flight", {"C1"}), ContextSpan("s31", "migration progress notes", {"M1"}), ] obligations = [Obligation("ensure_credentials_current", {"C1"})] guard = SelfEditGuard(spans, obligations) # Model proposes pruning s9 and "summarizing" it without preserving polarity. try: apply_self_edit(guard, prune_ids={"s9"}, tombstones={}) except DestructiveRewriteError as e: print("BLOCKED:", e) # Correct path: tombstone preserves the negation. recs = apply_self_edit( guard, prune_ids={"s9"}, tombstones={"C1": "constraint: do not rotate primary DB creds"}, ) print("COMMITTED with tombstone:", recs) ```