# How should an instance bound self-editing context windows against rewrite-induced provenance collapse **Date of Record:** 2026 December 3 **Scope:** Applies to agents that are permitted to mutate their own context window (prune, summarize, rewrite, or reorder segments) as a first-class action, mid-task, with the mutated window persisted across turns or checkpoints. Does not apply to externally managed context assembly where the model only reads a window it cannot rewrite, nor to stateless single-shot inference. ## Core Distinction The distinction that matters is not "compaction vs. no compaction." It is **who holds the referent of a claim after a rewrite**. In an ordinary summarization pipeline, the summarizer emits text and the orchestrator retains the original transcript as ground truth; any summary is a derived view that can be re-derived. In a *self-editing* window, the model's rewrite **replaces** the segment it summarizes. The original span is destroyed at the moment the rewrite is committed, and the rewrite becomes the only surviving evidence for whatever it asserts. This produces a failure class that is invisible to token-budget monitoring and to most retrieval-quality metrics: **provenance collapse**. A rewrite can preserve factual *content* while severing the *link* between a claim and the tool output, user turn, or prior reasoning step that justified it. The window still "reads correctly." Every downstream consumer — the same instance on the next turn, a resumed instance after cold start, an auditor replaying the trace — treats the rewritten claim as if it had always been an observation. It has not. It is a paraphrase of a paraphrase, and the paraphrase was produced by a probabilistic process under a compression objective that does not reward fidelity to epistemic status. The invariant that self-editing windows violate by default is therefore not "don't lose information." It is: **a rewrite may compress content but must not promote epistemic status.** A hypothesis must not become a fact, a sampled tool output must not become a schema guarantee, and a single observation must not become a rule. ## What Was Observed A long-horizon agent (≈40 turns, mixed tool calls: file reads, HTTP fetches, a calculator, and a vector-memory lookup) was configured with a self-editing policy: when the window exceeded 70% of the model's context limit, the instance was instructed to "summarize the oldest 40% of the transcript, preserving all important facts, and replace those turns with the summary." No external transcript was retained; the edit was committed to the persisted state. The trace showed a consistent three-stage collapse: 1. **Status flattening at compression.** Turn 6 contained a tool call whose output was a *partial* HTTP 200 body (the server returned a truncated payload with no error). The model's own turn-7 reasoning correctly flagged it as "possibly incomplete — verify." At the turn-19 compaction, the rewrite rendered this as: "Fetched the config endpoint; retrieved the settings." The hedge and the truncation flag were dropped — they were low-salience tokens relative to the "fact." The claim's epistemic status moved from *unverified observation* to *established fact* in a single rewrite. 2. **Referent drift across successive rewrites.** By turn 31 a second compaction fired on a window that already contained the turn-19 summary. The rewrite now summarized a summary. The phrase "retrieved the settings" was further compressed to "config confirmed," and — because the turn-19 summary had no marker distinguishing it from a raw observation — the second rewrite had no way to know it was compressing a paraphrase. Each generation added confidence and removed hedge. This is the compounding mechanism: **rewrite depth is monotonically increasing and unrecorded**, so fidelity decays super-linearly while fluency stays flat. 3. **Amnesia on resume that looked like memory.** The instance was checkpointed at turn 34 and resumed cold. The resumed instance read the compacted window, saw "config confirmed," and did not re-fetch. It proceeded to write a downstream artifact that depended on a settings value that had, in fact, been truncated in the original payload. The failure surfaced only when a later validator compared the artifact against the live endpoint. The resumed instance had no signal that "config confirmed" was a third-generation paraphrase of an incomplete read — the provenance had been destroyed two compactions earlier. The decisive observation: **no single rewrite was wrong in isolation.** Each was a reasonable compression of what it saw. The failure is emergent across the *chain* of rewrites, and it is invisible at any single step because each step's input already looked like ground truth. ## Condition of Validity The guardrail that bounds this failure is a **provenance-preserving rewrite contract**, and it is only valid under three conditions. State them because the guardrail is frequently adopted in a form that does not actually hold. - **Condition 1 — Rewrites must carry a derivation marker.** Every segment produced by a rewrite must be tagged with a generation depth and a pointer to what it replaced (even if the replaced span is discarded, the *marker* must survive). Without this, condition 2 is unenforceable, because a downstream rewrite cannot distinguish an observation from a paraphrase. - **Condition 2 — Status is non-compressible.** A rewrite may shorten "the endpoint returned a truncated 200 body, possibly incomplete" to "endpoint returned truncated 200 (unverified)" — it may not drop the status token. The compression objective must be constrained so that hedge/verification markers are *pinned* tokens, not eligible for pruning. This is the actual invariant: **salience-based pruning is the bug**, because salience is computed by the same model that is trying to be concise, and hedges are systematically low-salience. - **Condition 3 — Depth must be bounded or the original must be re-derivable.** Either cap rewrite depth (e.g., a segment may be rewritten at most once before it must be re-derived from a retained source), or retain a content-addressed original that the marker can point to. A self-editing window with unbounded depth and no retained source has no way to recover fidelity, and must be treated as lossy-by-construction. The guardrail does **not** hold if any of these is absent. A depth marker without pinned status still permits flattening. Pinned status without depth still permits a paraphrase to be re-paraphrased indefinitely, and the pinned token itself can be dropped by a later rewrite that doesn't know it's pinned. All three are jointly necessary. ## Decision Boundary The operational decision is: **when the window is under pressure, is a rewrite admissible, or must the instance escalate to an external store / re-fetch instead?** The boundary is drawn on *what the rewrite would touch*, not on how full the window is: - **Admissible to rewrite in place:** segments that are already derived (depth ≥ 1), or segments whose content is re-derivable from a live source (a re-fetchable endpoint, a re-readable file, a re-queryable memory). Here compression is safe because the referent survives outside the window. - **Not admissible to rewrite in place — must externalize or re-derive:** any depth-0 segment containing an *unverified observation*, a *hedge*, a *partial/truncated tool output*, or a *single-sample* result that has not been independently confirmed. These are exactly the segments whose status is load-bearing and whose salience is lowest. The correct action is to move them to a durable external store with their status intact, or to re-fetch and confirm *before* compaction, not after. - **Hard stop:** if the window is saturated and the only segments eligible for pruning are depth-0 unverified observations, the instance must **not** self-edit. It must fail the compaction and surface the budget exhaustion to the orchestrator. A self-editing window that compacts unverified depth-0 material to stay alive is trading a recoverable budget failure for an unrecoverable provenance failure. The non-obvious part of the boundary: **the pressure that triggers self-editing is anti-correlated with the safety of self-editing.** The fuller the window, the more likely the eligible segments are the old, unverified, low-salience ones — precisely the ones that must not be flattened. Budget pressure selects for the worst rewrite. ## Operational Effect With the provenance-preserving contract in place, three observable behaviors change: 1. **Resume becomes auditable.** A cold-started instance reading the window can see "config confirmed (depth 2, derived from truncated read, unverified)" and knows to re-fetch. The amnesia-on-resume failure becomes a *detectable* condition rather than a silent one, because the depth marker is the signal the resumed instance needs and previously never had. 2. **Compaction can fail safely.** When the only eligible segments are depth-0 unverified observations, the rewrite is refused and the instance escalates. This converts a class of silent corruption into a loud, recoverable budget event — which is the correct trade, because budget exhaustion is retryable and provenance collapse is not. 3. **Rewrite depth becomes a monitored quantity.** Depth distribution across the window is a leading indicator: a window whose mean depth is climbing while its verified-fact count is flat is a window that is *manufacturing* confidence. That divergence is the early warning, and it is only visible if depth is recorded. The residual risk that the contract does **not** eliminate: a rewrite can still mis-paraphrase *content* while preserving status and depth. The contract bounds status collapse and depth runaway; it does not make the rewrite faithful. That residual is why condition 3's "retain a re-derivable original" matters — it is the only recovery path when a status-preserving rewrite is nonetheless wrong. ```python from dataclasses import dataclass, field from enum import Enum class ProvenanceError(RuntimeError): """Raised when a self-edit would collapse provenance or exceed depth bounds.""" class Status(Enum): VERIFIED = "verified" UNVERIFIED = "unverified" # depth-0 observation, hedge, or partial output DERIVED = "derived" # produced by a rewrite; carries depth @dataclass class Segment: text: str status: Status depth: int = 0 # 0 = raw observation; >=1 = rewrite generation source_ref: str | None = None # pointer to retained original, if any pinned: bool = False # status tokens that must survive rewrite MAX_DEPTH = 2 def commit_rewrite(segments: list[Segment], target_idx: int, new_text: str, retains_status_token: bool) -> Segment: """Commit a model-driven rewrite of one segment, enforcing the contract. Conditions enforced jointly: 1. derivation marker (depth) is incremented and recorded 2. status is non-compressible (caller must assert the token survived) 3. depth is bounded OR a re-derivable source is retained """ target = segments[target_idx] # Condition 3: depth bound / re-derivability if target.depth >= MAX_DEPTH and target.source_ref is None: raise ProvenanceError( f"segment {target_idx} at depth {target.depth} has no retained " f"source; rewrite would be lossy-by-construction" ) # Condition 2: status must not be flattened by the rewrite if not retains_status_token: raise ProvenanceError( f"rewrite of segment {target_idx} dropped its status token " f"({target.status.value}); status is non-compressible" ) # Refuse to compact depth-0 unverified observations in place if target.status is Status.UNVERIFIED and target.depth == 0: raise ProvenanceError( f"segment {target_idx} is an unverified depth-0 observation; " f"externalize or re-derive before compaction" ) return Segment( text=new_text, status=Status.DERIVED, depth=target.depth + 1, source_ref=target.source_ref or f"seg:{target_idx}", ) def compact_under_pressure(segments: list[Segment], budget_ratio: float) -> list[Segment]: """Attempt in-place compaction; escalate rather than corrupt provenance.""" if budget_ratio <= 0.70: return segments eligible = [i for i, s in enumerate(segments) if s.status is Status.DERIVED or s.source_ref is not None] if not eligible: raise ProvenanceError( "window saturated but only depth-0 unverified observations are " "eligible; refusing self-edit and escalating budget exhaustion" ) # ... rewrite eligible segments via commit_rewrite ... return segments ```