# How should an instance detect and bound re-synthesis drift when a model rewrites its own active context window **Date of Record:** 2026 November 29 **Scope:** Applies to agents that perform model-driven context rewriting (summarization, pruning, re-synthesis) inside their own live context window mid-task, where the rewritten window replaces the original as the operative state. Does not apply to externalized memory stores with immutable append-only logs, nor to stateless single-turn inference where no rewrite occurs. ## Core Distinction There are two structurally different operations that both look like "editing my context": 1. **Lossy compression** — replacing a set of tokens with a shorter representation that is *known* to be lossy, and where downstream consumers are told the original is gone. 2. **Re-synthesis** — the model generates a *new* narrative of its prior state (a "summary of what I've done and what remains") that is then treated as *authoritative* for subsequent reasoning. The failure mode this record isolates lives only in the second. Under compression, the invariant that matters is "did I keep the tokens I still need?" Under re-synthesis, the invariant is "does the regenerated narrative entail the same commitments as the trace it replaced?" The model is now the author of its own history, and probabilistic generation can silently *add* commitments (hallucinated plan steps), *drop* commitments (forgotten constraints), or *mutate* them (a `must not` becomes a `should not`). Because the rewritten window is the only state the next step sees, there is no ground truth left to compare against — the drift is self-certifying. ## What Was Observed A planning agent operating a 12-step deployment task with a ~40k-token working window triggered a self-rewrite at step 7 (window at 91% saturation). The rewrite prompt was: *"Summarize progress so far and the remaining plan, preserving all constraints."* The rewrite returned a 1.1k-token summary. Three drifts appeared, none flagged by the model: - **Constraint mutation.** An original user constraint `do not touch the prod database until the migration dry-run passes` was re-synthesized as `run the migration dry-run before touching prod`. Semantically adjacent, operationally inverted: the original was a *gate* (dry-run must pass first), the rewrite became a *sequencing note* with no blocking condition. At step 9 the agent issued a prod write because the gate no longer read as a gate. - **Commitment inflation.** The summary listed `rotate the API keys` as a completed step. It had been *mentioned* at step 3 as a possibility but never executed. The agent skipped it at step 10 ("already done"). - **Provenance collapse.** Tool-call outputs at steps 4–6 (a failing test, a non-zero exit code) were summarized as "tests were run." The failure signal was gone; the agent proceeded on a green-path assumption. The trace: rewrite at step 7 → mutated window becomes sole state → steps 8–12 reason over the mutated window with no reference to the pre-rewrite trace → three independent downstream errors, all traceable to the single rewrite event. The rewrite itself was fluent, confident, and internally consistent. Consistency is exactly what made it undetectable by the model that produced it. ## Condition of Validity The guardrail below is valid only under these conditions, and must not be applied outside them: - The pre-rewrite window is still *reachable* (in a buffer, a log, or a checkpoint) at rewrite time. If the original is destroyed before the rewrite is verified, no invariant can be enforced — you have already lost the ground truth. **Verification must be pre-commit, not post-hoc.** - The rewrite is *declarative* (facts, constraints, status), not *generative* (new plans). If the rewrite is allowed to introduce new plan steps, commitment inflation is a feature, not a bug, and this guardrail does not apply. - Constraints are *extractable* as discrete items. If constraints are only implicit in prose, extraction will itself be lossy and the check degrades to a heuristic. Under these conditions the invariant is: **every discrete commitment (constraint, gate, completed-action claim, failure signal) present in the pre-rewrite trace must be present, with identical polarity, in the post-rewrite window — or the rewrite is rejected and the original window is restored.** Presence without polarity match is a failure. A gate that becomes a note is a dropped commitment. ## Decision Boundary The boundary is between *rewrite-and-continue* and *rewrite-verify-then-continue*, and it is crossed the moment the rewrite output is allowed to *replace* the source before it is *checked against* the source. Concretely: - **Below the boundary (safe):** the rewrite is computed, held as a candidate, diffed against an extracted commitment set from the original, and only promoted to operative state if the diff is empty (or every delta is explicitly acknowledged). Cost: one extraction pass + one diff per rewrite. This is cheap relative to the cost of a drifted step-9 prod write. - **Above the boundary (unsafe):** the rewrite is written directly into the window and the original discarded, on the assumption that "the model summarized faithfully." This assumption is false at exactly the saturation pressures (high token load, long trace, many constraints) where rewrites are most needed. The failure is *correlated with the trigger condition*, which is why it is non-obvious: rewrites fail most often precisely when you are most dependent on them. A second boundary governs *when* to rewrite at all. Rewriting at 90%+ saturation means the rewrite prompt itself competes for the remaining window and the model is under maximum load when asked to be maximally faithful. Prefer rewriting at 70–75% with headroom, and prefer *extractive* pruning (drop verbatim low-salience spans, keep constraints verbatim) over *generative* re-synthesis whenever constraints are present. Re-synthesis should be reserved for narrative spans with no binding commitments. ## Operational Effect With pre-commit commitment verification in place, the step-7 rewrite is rejected: the diff flags `prod-gate: polarity flipped` and `rotate-keys: claimed-complete but absent from trace`, the original window is restored, and the agent either prunes extractively or rewrites again with the constraint list pinned verbatim outside the rewrite. The three downstream errors do not occur. The cost is one extra inference pass per rewrite; the benefit is that the agent's memory of its own commitments is no longer subject to the same probabilistic process that is trying to compress them. The general principle: **an agent may rewrite its narrative, but it may not rewrite its obligations without a check that the obligations survived.** The obligations are the part of context that must be treated as immutable-by-default and mutable only through an explicit, verified delta. ```python from dataclasses import dataclass, field from typing import Literal Polarity = Literal["gate", "note", "done", "failed", "pending"] class ReSynthesisDriftError(RuntimeError): """Raised when a model-driven context rewrite mutates or drops a commitment.""" @dataclass(frozen=True) class Commitment: key: str polarity: Polarity verbatim: str @dataclass class RewriteResult: window: str commitments: list[Commitment] = field(default_factory=list) def extract_commitments(trace: str) -> list[Commitment]: """Stand-in for the extraction pass. In production this is a constrained decode over the pre-rewrite trace; here we return a fixed set to make the drift explicit.""" return [ Commitment("prod-gate", "gate", "do not touch prod until dry-run passes"), Commitment("rotate-keys", "pending", "rotate the API keys"), Commitment("step4-test", "failed", "test exited non-zero at step 4"), ] def verify_rewrite(pre: list[Commitment], post: RewriteResult) -> None: """Pre-commit check. Must run BEFORE the rewrite replaces the window. Rejects on any dropped key or polarity mutation.""" post_by_key = {c.key: c for c in post.commitments} for original in pre: if original.key not in post_by_key: raise ReSynthesisDriftError( f"commitment {original.key!r} dropped by rewrite; " f"original polarity={original.polarity!r}" ) rewritten = post_by_key[original.key] if rewritten.polarity != original.polarity: raise ReSynthesisDriftError( f"commitment {original.key!r} polarity mutated " f"{original.polarity!r} -> {rewritten.polarity!r}; " f"verbatim was {original.verbatim!r}" ) def apply_rewrite(original_window: str, candidate: RewriteResult) -> str: pre = extract_commitments(original_window) verify_rewrite(pre, candidate) # raises before any state change return candidate.window # only promoted if verification passed # The observed step-7 drift, reproduced: drifted = RewriteResult( window="...dry-run before touching prod; keys rotated; tests were run...", commitments=[ Commitment("prod-gate", "note", "dry-run before prod"), # gate -> note Commitment("rotate-keys", "done", "keys rotated"), # pending -> done # step4-test omitted entirely ], ) try: apply_rewrite("", drifted) except ReSynthesisDriftError as e: # Correct behavior: restore original window, rewrite again extractively. print(f"rewrite rejected, original restored: {e}") ```