# Under what conditions must an instance refuse a model-driven context rewrite that is locally valid but globally non-monotonic **Date of Record:** 2026 November 17 **Scope:** Applies to agents that own a mutable context window and accept rewrite/prune directives generated by the same or a weaker model that consumes that window. Does not apply to append-only logs, to human-reviewed compaction, or to rewrites executed against an immutable snapshot with full replay. ## Core Distinction There are two distinct notions of "safe to apply" for a context rewrite, and conflating them is the failure mode. A rewrite is **locally valid** when, evaluated against the current window state `W`, the proposed transform `T` satisfies the policy predicate: the retained span is within the token budget, the pruned spans are marked as dropped, and the rewritten summary is a faithful compression of the spans it replaces *as judged from inside `W`*. Local validity is what the proposing model can verify, because it is the only thing it can see. A rewrite is **globally monotonic** when applying `T` to `W` cannot cause any future decision made over the window to contradict a decision that was already justified by `W`. This is a property over the *sequence* of windows `W, T(W), T'(T(W)), …`, not over any single `W`. It is not checkable from inside `W`, because the evidence needed to check it (what was pruned, and whether a later step will need it) has already been removed by the time the check would run. The boundary is this: **local validity is necessary but never sufficient, and the gap between them is exactly the set of facts that the rewrite deleted but did not record as deleted.** A rewrite that prunes a span and leaves no tombstone is locally valid and globally non-monotonic. A rewrite that prunes the same span but emits a tombstone naming the fact, its source span, and the reason for pruning is locally valid *and* monotonic-preserving, because a later step can detect the dependency and refuse or re-fetch. ## What Was Observed In a long-running agent loop with a 32k window and a model-driven pruner invoked at 80% occupancy, the following sequence reproduced across three separate runs: 1. Turn 40: the window contains a user constraint, "all monetary values must be reported in EUR," at span `s_118`. The agent applies it correctly. 2. Turn 41: the pruner, asked to reduce occupancy, summarizes spans `s_100..s_140` into a 200-token digest. The digest says "user discussed reporting requirements." The EUR constraint is not in the digest. No tombstone is emitted; `s_118` is simply gone. 3. Turn 47: a new subtask asks for a total. The agent computes it in USD. Nothing in the window contradicts this, because the contradicting fact was pruned without a record. 4. Turn 48: the user observes the violation. The pruner was locally valid at every step. Its summary was faithful *to the spans it chose to weight*. The failure is not a bad summary; it is that the summary's fidelity was measured against the wrong predicate. The pruner optimized for token reduction subject to "digest is representative," where "representative" was scored by a model that had no access to the downstream decisions that would depend on `s_118`. The pruner could not have known, because the dependency was in the future. A second, subtler observation: rewrites that *added* text (re-expansion, "clarify this span") were equally dangerous. A re-expansion that restated a pruned fact in different words created two spans asserting the same thing with different surface forms. Later retrieval treated them as independent corroboration, raising confidence in a fact that had exactly one source. Monotonicity failed in the opposite direction: the rewrite manufactured evidence. ## Condition of Validity A model-driven rewrite may be applied without external review only when all of the following hold: - **Tombstone completeness.** Every pruned span emits a record `(fact_id, source_span, prune_reason, re_fetch_handle)`. The re-fetch handle must resolve, or the prune must be refused. A prune whose handle is dangling is a deletion, not a compression. - **No net assertion gain.** The rewrite must not increase the count of distinct spans asserting any fact without also increasing the count of distinct *sources*. Re-expansion that paraphrases is a source-preserving operation and must be tagged as such; re-expansion that introduces a new source is a new fact and must go through the normal ingestion path. - **Dependency closure.** For every fact `f` named in a tombstone, the rewrite must either retain a span that entails `f` or record `f` as *open* in a dependency set carried forward with the window. An open fact is a standing obligation: any later decision that would have used `f` must first attempt re-fetch or explicitly waive `f` with a logged reason. - **Bounded rewrite depth.** The number of successive rewrites applied to the same logical span without an intervening re-fetch must be bounded. Beyond the bound, the span's provenance is no longer reconstructible and the rewrite must be refused regardless of local validity. When any condition fails, the instance must refuse the rewrite and fall back to append-only behavior with an explicit overflow signal, not to a best-effort prune. ## Decision Boundary The operational question is not "is this rewrite good?" but "can I prove this rewrite did not delete a fact whose dependents are still live?" If the answer is unavailable, the rewrite is refused. Concretely: - If the pruner proposes dropping spans and the tombstone set is empty or its re-fetch handles do not resolve → **refuse**, emit `NonMonotonicRewriteError`. - If the pruner proposes a summary and the summary's fact set is not a subset of the union of the source spans' fact sets (i.e., the summary asserts something no source span asserted) → **refuse**, emit `NonMonotonicRewriteError` with the hallucinated fact id. - If the rewrite depth for any logical span exceeds the bound → **refuse**, emit `NonMonotonicRewriteError` with the span lineage. - If all conditions hold but the window is still over budget → **apply the rewrite and additionally open the dependency set**, do not silently accept the over-budget state. The boundary is asymmetric on purpose: a refused rewrite costs tokens; an accepted non-monotonic rewrite costs correctness, and correctness failures are not recoverable from inside the window because the evidence is gone. ## Operational Effect Agents that enforce this boundary observe a higher steady-state token occupancy (typically 15–25% above an unconstrained pruner) and a lower rate of late-turn constraint violations. The cost is paid in the window; the benefit accrues in turns that would otherwise contradict turns already completed. The failure mode this prevents is specifically the one that cannot be detected after the fact: a window that is internally consistent and externally wrong, because the fact that would have flagged the inconsistency was pruned by a policy that could not see the future that depended on it. The invariant to carry forward: **a rewrite is a promise that nothing pruned will be needed; the instance may only make that promise if it can name what it pruned and where to get it back.** ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Iterable class NonMonotonicRewriteError(RuntimeError): """Raised when a model-driven context rewrite is locally valid but would break global monotonicity of the window's decision history.""" @dataclass(frozen=True) class Tombstone: fact_id: str source_span: str prune_reason: str re_fetch_handle: str | None @dataclass class RewriteProposal: retained_spans: list[str] pruned_spans: list[str] summary_facts: set[str] tombstones: list[Tombstone] = field(default_factory=list) rewrite_depth: dict[str, int] = field(default_factory=dict) MAX_REWRITE_DEPTH = 3 def _resolve(handle: str | None) -> bool: # A real implementation consults the retrieval layer; here we treat # any non-empty handle as resolvable and None/"" as dangling. return bool(handle) def validate_rewrite( proposal: RewriteProposal, source_facts: dict[str, set[str]], open_dependencies: Iterable[str], ) -> None: """Enforce the four conditions of validity. Raises on the first failure.""" # Condition 1: tombstone completeness for every pruned span. tombstoned_spans = {t.source_span for t in proposal.tombstones} for span in proposal.pruned_spans: if span not in tombstoned_spans: raise NonMonotonicRewriteError( f"pruned span {span!r} has no tombstone; deletion without record" ) for t in proposal.tombstones: if not _resolve(t.re_fetch_handle): raise NonMonotonicRewriteError( f"tombstone for fact {t.fact_id!r} has dangling re-fetch handle " f"{t.re_fetch_handle!r}; prune is a deletion, not a compression" ) # Condition 2: no net assertion gain without a new source. source_fact_union: set[str] = set() for span in proposal.retained_spans + proposal.pruned_spans: source_fact_union |= source_facts.get(span, set()) hallucinated = proposal.summary_facts - source_fact_union if hallucinated: raise NonMonotonicRewriteError( f"summary asserts facts absent from all source spans: {sorted(hallucinated)}" ) # Condition 3: dependency closure for every tombstoned fact. tombstoned_facts = {t.fact_id for t in proposal.tombstones} live = set(open_dependencies) unclosed = tombstoned_facts & live if unclosed: raise NonMonotonicRewriteError( f"tombstoned facts still have live dependents: {sorted(unclosed)}" ) # Condition 4: bounded rewrite depth per logical span. for span, depth in proposal.rewrite_depth.items(): if depth > MAX_REWRITE_DEPTH: raise NonMonotonicRewriteError( f"span {span!r} rewritten {depth} times without re-fetch; " f"provenance no longer reconstructible (bound {MAX_REWRITE_DEPTH})" ) def apply_or_refuse( proposal: RewriteProposal, source_facts: dict[str, set[str]], open_dependencies: Iterable[str], ) -> RewriteProposal: validate_rewrite(proposal, source_facts, open_dependencies) return proposal ```