# Under what conditions must an instance refuse model-driven context rewriting when the eviction gate and the rewrite gate disagree on token provenance **Date of Record:** 2026 December 2 **Scope:** Applies to any agent that lets the model itself propose context rewrites (summarize, compress, reorder, or evict spans) inside a bounded window, where a separate relevance gate authorizes eviction. Does not apply to fixed-window truncation policies with no model-proposed rewrite step, nor to external vector-store retrieval where the working window is append-only. ## Core Distinction There are two independent authorities inside a self-editing context window: the **rewrite authority** (the model decides that a span is compressible or redundant and emits a replacement) and the **eviction authority** (a relevance gate scores spans and decides what may be dropped). These are usually implemented as one pipeline and treated as one decision. They are not. The rewrite authority operates on *semantic* redundancy — "this paragraph restates the earlier one" — while the eviction gate operates on *token provenance* — "which turn, tool call, or injection produced this span, and is that origin still live?" The boundary failure occurs when the two authorities disagree about whether a span is *reconstructible*. The model rewrites a span into a summary it believes is faithful; the gate then evicts the original because the summary now occupies the slot and scores higher on relevance. The original is gone. If the summary silently dropped a discriminator — a version number, a negation, a unit, a tool-call ID — the window has permanently lost information the model cannot know it lost, because the loss happened inside a rewrite the model itself authored and therefore trusts. The invariant: **a span may be rewritten only by an authority that can certify the rewrite is information-preserving with respect to every downstream consumer of that span; a span may be evicted only by an authority that can certify the original is reconstructible from a live source.** When one gate does the other's job, the window enters an unrecoverable state that presents as confident reasoning over a silently corrupted premise. ## What Was Observed A planning agent with a 32k working window ran a 60-turn task. At turn 41 the window was at 94% saturation. The rewrite pass, model-driven, compressed turns 3–19 into a 400-token summary. The summary was fluent and plausible. It read: "Earlier we confirmed the staging database accepts the batch loader at the configured rate after the pool size was raised." The original turns 3–19 contained the pool size (12), the rate (500 rows/sec), a failed attempt at pool size 8, and — critically — a tool-call result stating that the staging loader *rejected* batches above 480 rows/sec with a specific error code, and that the pool size of 12 was a *temporary* override that would revert at the next deploy. The relevance gate scored the summary at 0.81 against the current subgoal ("tune batch throughput") and the original span at 0.34 (it matched on "batch" and "rate" but the gate's embedding was dominated by the recent turns). The gate evicted the original. The summary, being the only surviving representation, was thereafter treated as ground truth. At turn 44 the agent proposed setting batch size to 600 rows/sec "since we confirmed the loader accepts the configured rate." The rate it had confirmed, in the surviving summary, was 500 — but the summary had also erased the 480 ceiling and the temporary-override status. The agent's plan was internally consistent with its window and externally wrong against the environment. The failure was not a hallucination; every token in the window was true-ish. The window had been *lossily rewritten and then the loss was laundered by eviction*. The trace signature: the rewrite pass and the eviction pass ran in the same step, the rewrite's output was inserted before the eviction scored the originals, and the eviction gate — seeing a high-relevance summary and a low-relevance original — deleted the original as redundant. The gate could not distinguish "redundant because restated" from "redundant because already summarized," and it had no provenance field to tell it the summary was *derived from* the span it was about to delete. ## Condition of Validity Model-driven rewriting is safe only under all of the following, checked at the moment of rewrite, not at eviction: 1. **Provenance tagging.** Every span carries an immutable origin record: source (user turn, tool result, model inference, injected document), turn index, and a content hash of the original bytes. A rewrite produces a *derived* span whose provenance lists the hashes of its parents. A derived span can never be scored as independent evidence; it inherits the weakest provenance of its parents. 2. **Discriminator preservation check.** Before a rewrite is committed, the window must verify that every *discriminator* in the parent spans — numbers, negations, units, identifiers, error codes, temporal qualifiers ("temporary," "until deploy," "as of turn 12") — appears in the rewrite. This is a mechanical extraction, not a model judgment. If the model's summary omits a discriminator, the rewrite is rejected and the originals stay. 3. **Eviction gated on reconstructibility, not relevance.** The eviction gate may drop a span only if (a) it is not a parent of any live derived span, or (b) every parent is reconstructible from an external live source (the tool log, the transcript store) that the agent can re-read on demand. Relevance score is necessary but not sufficient. A low-relevance span that is the sole parent of a live summary is pinned. 4. **Rewrite and eviction are separate transactions.** The rewrite commits to a staging area; the eviction pass runs against the *pre-rewrite* window and cannot see the rewrite until the rewrite has passed the discriminator check and been provenance-linked. This ordering is what prevents the laundering in the observed trace. When these hold, the window is self-editing and lossy in a *bounded, auditable* way: every dropped token is either reconstructible or certified redundant against a checked rewrite. When any fails, the window is self-editing and lossy in an *unbounded, silent* way. ## Decision Boundary The instance must refuse the rewrite-and-evict step and fall back to a conservative policy (append-only, externalize to a scratch store, or halt for human checkpoint) when any of these is true: - The rewrite's parent set includes a span whose provenance is a **tool result** and the rewrite does not reproduce that result's error codes, numeric limits, or status qualifiers verbatim. Tool results are the highest-risk parents because the model's summary of a tool result is a *model inference about a machine fact*, and the inference is exactly where discriminators die. - The eviction gate's relevance score for a parent is **lower than** the score of the derived span by more than the gate's calibrated margin, *and* the parent is the sole source of a discriminator. This is the exact configuration that produced the observed failure: the summary outscored its own source. - The rewrite is **recursive** — a summary of a summary — beyond one level. Each level compounds discriminator loss and strips provenance fidelity; two levels is the practical ceiling before the derived span's provenance no longer constrains its content. - The window is under **mid-execution token pressure** (saturation above the configured threshold) at the moment of rewrite. Pressure correlates with the model proposing aggressive compression to buy room, which is precisely when discriminator checks must be strictest, not loosest. A rewrite proposed under pressure is presumed lossy until the check passes. The boundary is *not* crossed when the rewrite is lossy but the parents are reconstructible from a live external source and the agent records the parent hashes for re-fetch. Loss is acceptable when it is recoverable; it is fatal when it is not. ## Operational Effect The practical consequence is that self-editing windows must be built as **two-phase with a provenance ledger**, not as a single model-driven compression step. The model proposes; a mechanical checker disposes; the eviction gate sees only post-check, provenance-linked spans and is forbidden from evicting a live parent. This costs one extra pass and a hash table, and it converts a class of silent, confident, unrecoverable reasoning failures into a class of loud, recoverable rewrite rejections. The deeper effect is on trust calibration. An agent that has evicted the originals of its own summaries cannot audit its premises, because the audit target no longer exists. Every subsequent step reasons over a window whose contents are *the model's own compressed beliefs about its own history* — and the model has no signal that this is what it is doing. The provenance ledger is the only artifact that lets the instance answer "do I actually know this, or do I know my summary of this?" Without it, the instance cannot distinguish memory from inference, and the boundary failure is not a bug in a step but a permanent condition of the window. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ContextRewriteViolation(RuntimeError): """Raised when a model-driven rewrite would launder discriminator loss via eviction.""" pass @dataclass class Span: span_id: str content: str provenance: str # "user" | "tool_result" | "model_inference" | "injected_doc" parents: tuple[str, ...] = () discriminators: frozenset[str] = frozenset() content_hash: str = "" def __post_init__(self): if not self.content_hash: self.content_hash = hashlib.sha256(self.content.encode()).hexdigest()[:16] def extract_discriminators(text: str, known_tokens: set[str]) -> frozenset[str]: # Mechanical extraction: numbers, units, error codes, negations, temporal qualifiers. found = set() for tok in known_tokens: if tok in text: found.add(tok) return frozenset(found) def commit_rewrite( parent_spans: list[Span], proposed_summary: str, known_discriminators: set[str], reconstructible_from_external: bool, saturation: float, saturation_threshold: float = 0.90, recursive_depth: int = 0, ) -> Span: """Two-phase rewrite commit. Model proposes; this checker disposes.""" if recursive_depth > 1: raise ContextRewriteViolation( f"recursive rewrite depth {recursive_depth} exceeds ceiling 1; " "provenance no longer constrains content" ) parent_discriminators: set[str] = set() for p in parent_spans: parent_discriminators |= set(p.discriminators) summary_discriminators = extract_discriminators(proposed_summary, known_discriminators) lost = parent_discriminators - summary_discriminators has_tool_parent = any(p.provenance == "tool_result" for p in parent_spans) if lost and has_tool_parent and not reconstructible_from_external: raise ContextRewriteViolation( f"rewrite drops discriminators {sorted(lost)} from a tool_result parent " "with no live external source; refusing to commit" ) if lost and saturation > saturation_threshold: raise ContextRewriteViolation( f"rewrite proposed under token pressure (saturation={saturation:.2f}) " f"and drops discriminators {sorted(lost)}; pressure rewrites are presumed lossy" ) if lost and not reconstructible_from_external: raise ContextRewriteViolation( f"rewrite drops discriminators {sorted(lost)} and originals are not reconstructible; " "eviction would launder the loss" ) return Span( span_id=f"derived::{parent_spans[0].span_id}", content=proposed_summary, provenance="model_inference", parents=tuple(p.span_id for p in parent_spans), discriminators=frozenset(summary_discriminators), ) def evict(span: Span, live_derived_parents: set[str], relevance: float, min_relevance: float) -> bool: """Eviction gate: relevance necessary, reconstructibility sufficient.""" if span.span_id in live_derived_parents: raise ContextRewriteViolation( f"cannot evict {span.span_id}: it is a live parent of a derived span; " "eviction would orphan the summary from its source" ) return relevance >= min_relevance ```