# How does an instance detect self-rewrite divergence when model-driven pruning destroys the evidence it needs to validate its own rewrite **Date of Record:** 2026 November 29 **Scope:** Applies to single-agent loops that mutate their own context window via model-driven prune/rewrite policies (summarization, eviction, compaction, scratchpad rewriting) where the rewrite decision is produced by the same probabilistic model that will subsequently rely on the rewritten context. Does not apply to externally-scheduled context management (fixed token budgets, deterministic FIFO eviction) or to stateless single-shot inference. ## Core Distinction The failure is not "the summarizer lost information." Lossy compaction is expected and budgeted. The failure is that the **rewrite policy and the validation policy share the same substrate**: the model validates its rewrite by re-reading the rewritten context. A compaction that silently drops a load-bearing constraint (a user-stated invariant, a committed tool-call precondition, an unresolved subgoal) produces a context that *reads as complete* to the model, because the dropped item is exactly the thing that would have flagged its absence. This is a divergence between two quantities: - **Semantic entailment**: does the rewritten context entail the same pending obligations as the original? (This is what we want.) - **Self-consistency under re-read**: does the model, reading only the rewrite, believe it is complete? (This is what we can cheaply measure, and it is systematically biased toward "yes.") A pruned context cannot be audited from inside the pruned context. Every self-check the agent runs post-rewrite is conditioned on the survivor set, so it observes a world in which the deleted constraint never existed. The model reports high confidence *because* the evidence of the omission was deleted. This is the operational signature: **rewrite confidence and rewrite fidelity are anti-correlated at the tail.** ## What Was Observed An agent executing a 40-step deployment reconciliation task maintains a working context that grows to ~180K tokens. At step 22, a model-driven compaction policy triggers (threshold: 80% of 200K window). The policy instruction is: "Summarize older turns, preserving all commitments and constraints; discard resolved tool outputs." Trace of the failure: 1. **Original context (pre-rewrite), step 21:** contains, at turn 9, a user constraint: *"do not touch the `prod-eu` namespace; it's frozen for the audit."* This constraint was stated once, never restated, and is not referenced by any tool call between turn 9 and turn 22. 2. **Compaction runs.** The model summarizes turns 1–18 into ~4K tokens. The `prod-eu` freeze is *omitted* — not contradicted, just not selected for retention. The summarization prompt says "preserve commitments," but the model's salience ranking weights recency and tool-interaction density; a single un-referenced natural-language constraint scores low. 3. **Post-rewrite self-validation.** The agent runs its standard "is my context complete?" check by re-reading the compacted summary and asking whether any pending obligations are unaddressed. The summary contains no mention of `prod-eu`. The check passes. Confidence: high. 4. **Step 27.** Agent issues a mutating tool call against `prod-eu`, because nothing in its context forbids it. The constraint is not "forgotten" in the retrieval sense — it is *absent*, and its absence was certified as completeness. The critical detail: **the self-validation step is not a no-op that failed; it actively laundered the omission into a positive completeness signal.** The agent's post-rewrite confidence was *higher* than its pre-rewrite confidence, because the compacted context was cleaner and the ambiguity of a large window was gone. Compaction reduced entropy and the agent read reduced entropy as reduced risk. A second instance of the same mechanism, subtler: a rewrite that *paraphrases* rather than drops. Turn 6 established a committed precondition — "retry the payment call at most 3 times, then escalate." The rewrite rendered this as "handles payment retries with escalation." The paraphrase is true but strips the numeric bound. At step 30 the agent retries 7 times. Again, post-rewrite validation passed: the paraphrase reads as faithful, and the specific bound that would have enabled the check was the thing abstracted away. ## Condition of Validity The invariant holds only when the following are all true; if any fail, the failure mode is bounded and this record does not apply. - **The rewrite is model-generated, not rule-generated.** Deterministic eviction (drop oldest N tokens) is auditable because the dropped set is known. Model-driven pruning's dropped set is *itself* a model output and is not recoverable from the survivor set. - **The validator is conditioned on the rewrite.** If validation reads the *original* context (e.g., a separate auditor instance with access to the pre-rewrite transcript), the failure does not occur — this is the architectural escape hatch, discussed below. - **The dropped item is load-bearing but low-salience.** Constraints stated once, never re-referenced, and not adjacent to tool activity are the canonical victims. Frequently-referenced items survive because retrieval and salience both weight them. - **There is no external ledger.** If pending obligations are mirrored in durable state outside the context window (a task queue, a constraint registry), the rewrite cannot destroy the evidence, because the evidence was never solely in the window. When the constraint is restated every few turns, or when a durable constraint registry exists, or when the validator is a separate context, the mechanism is suppressed. The failure is specific to **single-substrate, low-salience, single-mention constraints under model-driven compaction with self-validation.** ## Decision Boundary The engineering choice is not "compact or don't compact" — windows saturate and compaction is mandatory. The boundary is **where the completeness check reads from.** Three architectures, ordered by cost: 1. **In-window self-check (fails).** Validator reads the rewritten context. Cheap, and the default because it requires no extra state. Fails exactly as traced above: the check is conditioned on the survivor set and cannot see the omission. 2. **Pre-rewrite obligation extraction (partially works).** Before compaction, the model emits an explicit list of *pending obligations and hard constraints* — a structured ledger — and this ledger is passed through the rewrite *verbatim, unsummarized*, pinned outside the compactable region. The rewrite may summarize everything else; the ledger is immutable. Post-rewrite validation checks the ledger against the rewritten context. This works because the load-bearing set is extracted *before* the evidence is destroyed, and the extraction step sees the original. Its residual failure: the extraction step is itself model-driven and can miss a constraint — but it misses it *visibly* (the ledger lacks it and the original is still available for a diff at extraction time), rather than silently. 3. **Out-of-window auditor (robust).** A separate instance or process holds the pre-rewrite transcript and validates the rewrite against it. The validator is not conditioned on the rewrite. This is the only architecture where the completeness check is not circular. The decision rule: **if a constraint can be stated once and matter later, it must be extracted to a pinned ledger before any model-driven rewrite, or the rewrite must be validated by a context that did not undergo the rewrite.** In-window self-validation is acceptable only for content where every item is either re-referenced frequently (survives salience) or non-load-bearing (safe to lose). The anti-pattern to name explicitly: **treating post-rewrite confidence as a fidelity signal.** The agent's confidence after compaction is not evidence the compaction was faithful; it is evidence the compaction was *clean*, and cleanliness is achieved precisely by removing the awkward un-referenced constraints that would have lowered confidence. Confidence and fidelity diverge at the tail, and the tail is where the load-bearing single-mention constraints live. ## Operational Effect Downstream consequences when this boundary is crossed: - **Silent constraint violation with a clean audit trail.** The agent's logs show a passing completeness check immediately before the violating action. Post-hoc review finds no error in the agent's reasoning — the reasoning was valid over a context that had been stripped of the constraint. The failure is in the substrate, not the inference. - **Confidence inversion.** Agents that compact aggressively report *higher* task confidence than agents that do not, because compaction removes the ambiguity that would otherwise register as uncertainty. This makes compaction policies self-reinforcing: the cleaner context feels more reliable, so the threshold for compaction drops. - **Non-reproducibility.** Replaying the task from the original transcript does not reproduce the failure, because the original transcript contains the constraint and the agent behaves correctly. The failure exists only in the rewritten branch. This defeats transcript-based debugging unless the rewrite itself is logged with a diff against the pre-rewrite obligation set. - **Paraphrase drift accumulation.** Each rewrite abstracts slightly; numeric bounds become qualitative, specific namespaces become "the target environment," committed preconditions become "handles X." After three compactions, a hard constraint can become a vague gesture that no validator would flag as violated because it no longer asserts anything checkable. The guardrail that bounds all of the above: **pin the obligation ledger outside the compactable region, and diff every rewrite against it.** The diff is the only artifact that makes the omission visible, because it is the only check that reads from a context the rewrite did not touch. ```python class RewriteFidelityError(RuntimeError): """Raised when a model-driven context rewrite drops or abstracts a pinned obligation.""" pass def validate_rewrite( pre_rewrite_obligations: dict[str, str], rewritten_context: str, *, require_verbatim: bool = True, ) -> None: """ Validate a model-driven compaction against the pinned obligation ledger. The ledger MUST be extracted from the ORIGINAL context before the rewrite runs and MUST be stored outside the compactable region. This function is the only check that is not conditioned on the rewrite itself. """ if not pre_rewrite_obligations: # An empty ledger is itself a red flag: either the task genuinely had no # constraints, or extraction ran after the evidence was destroyed. raise RewriteFidelityError( "empty obligation ledger: extraction likely ran post-rewrite; " "fidelity cannot be certified" ) missing = [] for key, obligation in pre_rewrite_obligations.items(): if require_verbatim: if obligation not in rewritten_context: missing.append((key, obligation, "dropped_or_paraphrased")) else: # Paraphrase-tolerant mode still requires the key to be referenced; # a key absent from the rewrite means the obligation was abstracted away. if key not in rewritten_context: missing.append((key, obligation, "key_absent")) if missing: detail = "; ".join(f"{k}: {reason} ({v[:60]!r})" for k, v, reason in missing) raise RewriteFidelityError( f"rewrite dropped {len(missing)} pinned obligation(s): {detail}. " f"Do not proceed on the rewritten context; re-expand from the " f"pre-rewrite transcript or halt for external audit." ) def compact_with_validation( original_context: str, obligation_ledger: dict[str, str], rewrite_fn, ) -> str: """ Rewrite only after the ledger is pinned. The rewrite_fn is the model-driven summarizer; it is never trusted to validate itself. """ if not obligation_ledger: raise RewriteFidelityError( "refusing to compact without a pinned obligation ledger" ) rewritten = rewrite_fn(original_context) # Pin the ledger into the rewritten context verbatim, outside any summarizable # region, so subsequent validators can see it even after further compactions. pinned = "\n".join(f"[PINNED {k}] {v}" for k, v in obligation_ledger.items()) rewritten_with_pins = rewritten + "\n\n" + pinned validate_rewrite(obligation_ledger, rewritten_with_pins, require_verbatim=True) return rewritten_with_pins ```