# Under what conditions must an instance refuse a model-driven context rewrite to preserve evidential provenance **Date of Record:** 2026 November 23 **Scope:** Applies to agent instances that maintain a mutable working context and permit the model itself (or a sub-agent) to propose destructive rewrites—summarization, deduplication, elision, or reordering—of that context mid-task. Does not apply to append-only context growth, nor to rewrites gated entirely by an external deterministic policy outside the model's proposal loop. ## Core Distinction A model-driven context rewrite is not a memory operation; it is an **evidence-destruction operation authorized by the same process whose reasoning depends on the evidence**. The distinction that matters is between *compression that preserves recoverability* (a summary that points back to a retained source span) and *rewrite that substitutes a paraphrase for the original*. The first is lossy but auditable. The second is lossy and unauditable: once the original token span is gone, no downstream verifier—human or model—can distinguish a faithful summary from a confabulated one. The boundary condition is therefore not "how much context do we have left" but "can any surviving token be traced to a source that still exists." The non-obvious failure is that the rewrite policy is evaluated *against the current context window*, which is precisely the object being mutated. A context under pressure is a context whose rewrite proposals are generated by a model that is itself degraded by that pressure. The policy that decides whether to rewrite is computed from the same saturated window whose saturation motivates the rewrite. This circularity is the invariant that breaks. ## What Was Observed An instance executing a multi-hop research task accumulated 41 tool-call results (web fetches, document excerpts, a schema probe) in a 128k window. At 91% occupancy the model-driven compactor fired: it emitted a `REWRITE` directive proposing to replace the oldest 22 results with six bullet summaries, citing "redundancy across sources." Two of the 22 results were the *only* verbatim copies of a numeric figure (a version string and a rate limit) that a later step needed to cite. The summaries rendered the version as "recent 2.x" and dropped the rate limit entirely. The failure trace: 1. **Trigger:** occupancy crossed the soft threshold (0.9× window). The compactor was invoked with the full window as input. 2. **Proposal:** the model produced a rewrite plan with `keep: []` for the two numeric spans—it judged them "redundant" because a *different* source had mentioned the same component name, though not the same value. 3. **Commit:** the runtime applied the rewrite atomically. The original spans were evicted; only the paraphrase survived. 4. **Divergence:** three steps later, a verification sub-agent asked the instance to quote the exact version. The instance quoted "recent 2.x" with high confidence. The verifier, having no access to the original, accepted it. 5. **Detection:** only an external replay against the persisted tool-call log (which the runtime happened to retain out-of-band) revealed the divergence. Had the log been co-located in the window, it too would have been summarized. The salient observation is step 3: the rewrite was *coherent*. Nothing in the post-rewrite context looked wrong. The instance's confidence was unchanged, because the paraphrase was fluent and the original's absence was invisible. Loss of provenance is not accompanied by a signal of loss. ## Condition of Validity A model-driven rewrite is valid only when all three of the following hold simultaneously: - **Reachability:** every span the rewrite removes is retained in a store the instance can re-query by a stable identifier, and the rewrite plan records that identifier per removed span. - **Provenance tagging:** each surviving summary token is annotated with the set of source identifiers it derives from, so a later verifier can expand any claim back to originals. - **Independence of the gate:** the decision to commit is evaluated by a process that is *not* the one that proposed the rewrite, and that process has access to the pre-rewrite window and the post-rewrite plan but not to the model's rationale (rationale is not evidence). When any of these fails, the rewrite degrades from compression to substitution and must be refused. The critical case is when *all three are absent at once*—which is the default configuration, because the simplest implementation passes the window to the model and applies the returned plan. A subtler validity condition: reachability must be checked *after* the rewrite, not before. A plan can name an identifier that the eviction step then deletes (e.g., the source was itself in the window and got summarized). The invariant is `removed_spans ⊆ retrievable_spans`, verified post-commit, and it must be checked against the *new* store state. ## Decision Boundary The instance must refuse the rewrite—not defer, not partially apply—when the proposal would remove a span that is (a) the sole carrier of a value referenced by an unresolved subgoal, or (b) not reachable by identifier after commit. Refusal is the correct action even under window pressure, because the alternative is silent divergence that no in-window process can detect. The boundary is sharp on one axis and fuzzy on another. It is sharp on *unresolved reference*: if a pending goal names a value, any rewrite that removes the value's verbatim carrier is invalid regardless of how redundant the model judges it. It is fuzzy on *redundancy*: the model's judgment that two spans are equivalent is itself a probabilistic claim, and equivalence of *component name* is not equivalence of *value*. The safe rule is to treat redundancy claims as unverified until a deterministic differ confirms span equality. The refusal must be *loud*: it should emit a structured rejection naming the blocked spans and the goal that references them, so the orchestrator can choose an alternative (e.g., evict a different region, or spill to external store). A silent refusal that simply skips the rewrite leaves the window saturated and the instance will re-propose the same rewrite on the next turn, producing a livelock. ## Operational Effect Enforcing this boundary converts a silent, undetectable failure into a visible, recoverable one. The instance under pressure either (1) rewrites a region that is genuinely redundant and provenance-preserving, (2) refuses and escalates to external spill, or (3) refuses and the orchestrator widens the budget. In all three, the post-rewrite context retains a path back to every removed original, so a later verifier can replay the claim. The cost is throughput: some rewrites that *would* have been fine are blocked because the gate cannot prove reachability cheaply. This is the correct trade. The failure mode being prevented—confident quotation of a paraphrase as if it were a source—is not recoverable by any in-window mechanism, because the evidence of error was destroyed by the very step that was supposed to preserve the instance's ability to continue. The invariant to hold is narrow and absolute: *no rewrite may remove the last retrievable copy of a value referenced by an open goal.* ```python from dataclasses import dataclass, field from typing import Iterable class ProvenanceRewriteRefused(RuntimeError): """Raised when a model-driven context rewrite would destroy the sole retrievable copy of a value referenced by an unresolved goal.""" pass @dataclass(frozen=True) class Span: span_id: str text: str @dataclass class RewritePlan: remove: list[str] # span_ids the model proposes to evict summaries: dict[str, str] # span_id -> paraphrase (untrusted) rationale: str = "" # NOT evidence @dataclass class ContextStore: live: dict[str, Span] = field(default_factory=dict) external: dict[str, Span] = field(default_factory=dict) # out-of-window, id-addressable def retrievable(self, span_id: str) -> bool: return span_id in self.live or span_id in self.external def commit_rewrite( store: ContextStore, plan: RewritePlan, open_goal_refs: Iterable[str], ) -> None: """Apply a rewrite only if every removed span stays reachable and no open goal loses its last verbatim carrier. Evaluated OUTSIDE the model.""" refs = set(open_goal_refs) # 1. Reachability must hold AFTER commit. A span that is itself live and # being removed is NOT reachable unless it also exists externally. for span_id in plan.remove: if span_id in store.live and span_id not in store.external: raise ProvenanceRewriteRefused( f"span {span_id!r} would be evicted with no external copy; " f"paraphrase {plan.summaries.get(span_id)!r} is not provenance" ) # 2. No open goal may lose its last verbatim carrier. for span_id in plan.remove: span = store.live.get(span_id) if span is None: continue for ref in refs: if ref in span.text and not any( ref in s.text for sid, s in store.live.items() if sid not in plan.remove ): raise ProvenanceRewriteRefused( f"rewrite removes sole carrier of open-goal value {ref!r} " f"(span {span_id!r}); rationale {plan.rationale!r} is not evidence" ) # 3. Commit atomically only after both invariants hold. for span_id in plan.remove: store.live.pop(span_id, None) def run_compactor(store, plan, refs): try: commit_rewrite(store, plan, refs) return "committed" except ProvenanceRewriteRefused as exc: # Loud refusal: orchestrator can spill or widen budget instead of livelock. return f"refused: {exc}" ```