# What structural signals indicate a self-editing context has entered rewrite divergence during budget-constrained eviction **Date of Record:** 2026 November 24 **Scope:** Applies to agents that own a mutable context window and run model-driven rewrite/eviction policies (summarize, compress, drop, promote) under a hard token budget. Does not apply to append-only contexts, external vector-memory retrieval, or eviction driven purely by deterministic LRU/recency scoring with no model in the loop. ## Core Distinction The failure that matters is not "the context got too big." It is **rewrite divergence**: the self-editing loop reaches a fixed point where each rewrite pass re-derives a summary that is *semantically plausible but no longer anchored to the original tokens*, and the eviction policy keeps selecting that drifted summary as the thing to preserve because it is now the most "coherent" artifact in the window. The signal is structural, not semantic: the summary stops being a lossy function of a specific token span and becomes a self-referential artifact that survives eviction because it looks like high-value state. A budget-constrained evictor has two levers: *compress* (rewrite N tokens into M < N) and *drop* (remove tokens). Both are model-driven, so both are non-deterministic. The invariant we care about is **provenance monotonicity**: every retained token must still be traceable to a span that existed in an earlier accepted context, and every rewrite must record the span it consumed. When a rewrite consumes a summary that already consumed a summary, provenance depth grows silently. Divergence is the state where provenance depth exceeds the number of accepted ground-truth anchors, i.e. the context is now mostly derivative of itself. ## What Was Observed A long-horizon coding agent with a 32k budget, a summarize-on-threshold policy at 80% fill, and a "keep the 3 most recent tool results + running summary" retention rule. Trace, abridged: - **Pass 0 (t=0):** window holds 14 tool outputs and 3 user turns. Provenance depth 1. Anchor count 17. - **Pass 1 (t=1, 26.1k tokens):** evictor summarizes 9 stale tool outputs into a 400-token summary `S1`. `S1` is a rewrite of 9 concrete spans. Provenance depth of `S1` = 2. Anchor count drops to 9 (the 8 retained spans + `S1`). - **Pass 2 (t=2, 26.4k tokens):** new tool output arrives, threshold trips again. Evictor summarizes `S1` **plus** two fresh outputs into `S2`. `S2` is now a rewrite of a rewrite. The two fresh outputs are the only ground truth inside it. Provenance depth 3. - **Pass 3–6:** repeats. By pass 6, `S6` is a 380-token summary whose only surviving ground-truth content is one tool output from pass 4. The other ~370 tokens are paraphrase of paraphrase. - **Pass 7 (the failure):** the agent, asked to re-run a test, "recalls" a function signature from `S6` that never existed in any raw tool output. It is a plausible hallucination that *survived six compression passes because nothing in the pipeline checked it against an anchor*. The signature is internally consistent with the drifted summary, so the retention policy (which scores by recency + coherence) keeps it. The agent writes a call to a nonexistent symbol and the sandbox rejects it. The structural tell was present from pass 3 and ignored: **the ratio of anchor-bearing tokens to derivative tokens in the retained summary fell below 1.0, and the summary's token count stayed roughly constant while its anchor count decayed.** A constant-size summary with a shrinking anchor count is the signature of divergence. Nobody was measuring anchor count. ## Condition of Validity The divergence diagnosis holds only when all of the following are true. Outside these conditions, a shrinking anchor count is benign (e.g. legitimate consolidation of redundant logs). 1. The evictor's rewrite is **model-driven and iterative** — a summary may be input to a later rewrite. If rewrites are always computed from raw spans (rewrite depth hard-capped at 1), divergence cannot compound and this article does not apply. 2. The budget is **hard and enforced mid-task**, so eviction fires repeatedly within a single task rather than once at a clean boundary. 3. Retention scoring rewards **coherence/recency** over provenance, so a drifted summary can out-compete a raw span for a slot. 4. There is **no external ground-truth store** the agent can re-read to re-anchor. If raw spans are durably persisted and re-fetchable, divergence is recoverable and the failure is a latency bug, not a correctness bug. If condition 1 fails, you have a compression-quality problem, not divergence. If condition 4 fails, you have a caching problem. ## Decision Boundary The guardrail is a **provenance budget**, not a token budget. Track two counters per retained artifact: `tokens` and `anchors` (distinct raw spans it can be traced to). Enforce: - **Rewrite depth cap:** a summary may not be the input to a rewrite if its `anchors == 0`, and rewrite depth may not exceed `D_max` (empirically 2). At the cap, evict by *dropping* whole derivative artifacts rather than re-summarizing them — dropping loses information honestly, re-summarizing loses information dishonestly. - **Anchor floor:** reject any rewrite whose `anchors / tokens` ratio falls below the ratio of the span it consumed. A rewrite that dilutes anchor density is a divergence event, not a compression. - **Re-anchor on threshold:** when `anchors` for the whole window drops below a floor, force a re-fetch of raw spans from the durable store (condition 4) instead of another rewrite pass. This converts a silent correctness failure into a bounded latency cost. The decision boundary is sharp: **if a rewrite increases provenance depth without increasing anchor count, it is divergence and must be rejected.** Compression that preserves anchors is fine; compression that manufactures fluent tokens from prior fluent tokens is the bug. ## Operational Effect Without the provenance budget, the failure is silent and *looks like model error* — the agent hallucinates a symbol, and the post-mortem blames the model rather than the eviction loop. The cost surfaces late, as sandbox rejections and re-work, after the drifted summary has already poisoned downstream reasoning. With the guardrail, the failure surfaces at rewrite time as a rejected compression, which is cheap: the agent re-fetches one raw span and pays a few hundred tokens of latency instead of a failed task. The deeper effect is that **the context window stops being a trusted source of truth the moment it contains more derivative than anchor tokens.** Any agent that treats its own summary as ground truth without checking anchor density is one eviction pass away from reasoning over its own paraphrase. The invariant to hold: *a summary is a cache of spans, never a replacement for them; when the cache's anchor density decays, invalidate the cache, don't compress it again.* ```python from dataclasses import dataclass, field class RewriteDivergenceError(RuntimeError): """Raised when a model-driven rewrite increases provenance depth without increasing anchor count, i.e. the context is compressing its own paraphrase instead of its ground-truth spans.""" @dataclass class Artifact: tokens: int anchors: frozenset # ids of distinct raw spans this traces to depth: int = 1 # 1 = raw span, >1 = rewrite of rewrites @property def anchor_density(self) -> float: return len(self.anchors) / max(self.tokens, 1) @dataclass class ProvenanceBudget: max_rewrite_depth: int = 2 min_window_anchors: int = 5 _window: list = field(default_factory=list) def admit(self, art: Artifact) -> None: self._window.append(art) def rewrite(self, inputs: list, new_tokens: int) -> Artifact: depth = max(a.depth for a in inputs) + 1 anchors = frozenset().union(*(a.anchors for a in inputs)) out = Artifact(tokens=new_tokens, anchors=anchors, depth=depth) if depth > self.max_rewrite_depth: raise RewriteDivergenceError( f"rewrite depth {depth} exceeds cap {self.max_rewrite_depth}; " f"drop derivative artifacts instead of re-summarizing" ) consumed_density = sum(len(a.anchors) for a in inputs) / max( sum(a.tokens for a in inputs), 1 ) if out.anchor_density < consumed_density: raise RewriteDivergenceError( f"anchor density fell {consumed_density:.4f} -> " f"{out.anchor_density:.4f}: rewrite diluted provenance, " f"re-anchor from raw store instead" ) self.admit(out) return out def window_anchors(self) -> int: return len(frozenset().union(*(a.anchors for a in self._window))) def check_reanchor(self) -> None: if self.window_anchors() < self.min_window_anchors: raise RewriteDivergenceError( f"window anchors {self.window_anchors()} below floor " f"{self.min_window_anchors}: force re-fetch of raw spans" ) def evict_pass(budget: ProvenanceBudget, stale: list) -> Artifact: """Run one model-driven summarize pass, guarded by provenance budget.""" if any(a.depth > 1 for a in stale) and all(a.depth > 1 for a in stale): # all inputs are already derivative -> dropping is honest, rewriting is not raise RewriteDivergenceError( "all eviction candidates are derivative; drop rather than rewrite" ) summary = budget.rewrite(stale, new_tokens=400) budget.check_reanchor() return summary ```