# How should an instance treat a self-rewritten context window as untrusted evidence rather than as ground truth **Date of Record:** 2026 December 2 **Scope:** Applies to long-running agent instances that mutate their own working context via model-driven summarization, pruning, or rewrite policies (compaction, scratchpad rewriting, "forget this" instructions) and later reason over the rewritten window. Does not apply to append-only context that is never model-edited, nor to externalized memory stores with independent provenance tracking. ## Core Distinction The critical distinction is between **context as a record of events** and **context as a model-authored artifact**. In an append-only window, every token is either a system instruction or a verbatim transcript of a tool result or model output; provenance is implicit in position. The moment an instance is permitted to *rewrite* its own window—summarizing a tool trace, dropping turns under a token budget, or paraphrasing an earlier reasoning chain—the window stops being a transcript and becomes a *claim about* the transcript, authored by the same probabilistic process that will later consume it. The failure mode is not that the rewrite is wrong in isolation; it is that the instance cannot, from inside the rewritten window, distinguish a fact it observed from a fact it *summarized into existence*. Rewrites launder provenance: a hedged tool observation ("the API returned 200 but the body was truncated") can be compacted into "API call succeeded," and the downstream planner will treat that as a first-class observation. ## What Was Observed A research agent with a 32k-token working budget was configured to compact at 80% saturation. The compaction policy asked the model to "preserve all facts needed to finish the task, discarding redundant tool output." Over a 40-step task (web fetch → parse → write file → verify), the following trace was captured: - **Step 12:** A `fetch` tool returned HTTP 200 with a 4,000-token body that was *truncated by the tool* at a byte limit. The raw window recorded the truncation marker and the partial body. - **Step 14:** Compaction fired (window at 26k). The summarizer produced: *"Fetched target document successfully; contents retrieved."* The truncation marker was dropped as "redundant tool output." - **Step 19:** The planner, reading the compacted window, asserted the document was fully retrieved and scheduled a downstream extraction step against a body that was missing its final 30%. - **Step 23:** The extraction step produced plausible but wrong structured output. No error was raised, because the *actual* truncation evidence no longer existed anywhere in context. - **Step 31:** A verification step compared the extraction against the (now-rewritten) claim "contents retrieved" and passed. The verification was internally consistent and externally wrong. The decisive observation: the failure was **not detectable from within the window**. At every step after compaction, the instance's reasoning was locally valid. The defect was a provenance erasure that occurred at step 14 and was laundered through two subsequent steps into a confident, verifiable-looking falsehood. ## Condition of Validity A self-rewritten context window is only safe to reason over when **every rewritten span carries a machine-checkable provenance edge back to the raw event it summarizes, and the rewrite is forbidden from upgrading the epistemic status of that event.** Concretely, three invariants must hold: 1. **Status monotonicity.** A rewrite may preserve or *downgrade* an event's epistemic status (observed → reported → summarized), never upgrade it. "Truncated body" cannot become "retrieved." 2. **Lossy-rewrite flagging.** Any span produced by model-driven pruning must be tagged as derived, not observed, so downstream steps can attach appropriate uncertainty. 3. **Irreversibility boundary.** Once a raw event is evicted, the derived span is the *only* surviving evidence; the system must treat that eviction as a one-way door and gate any high-confidence action on derived-only evidence. This condition fails silently in the common case where the rewrite policy is a free-form natural-language instruction ("keep what matters") with no schema, because the model has no mechanism to represent "I am unsure whether the truncation mattered" and will resolve the ambiguity by omission. ## Decision Boundary The operational decision is **when to allow a derived span to justify an irreversible action** (writing a file, calling a mutating tool, declaring a task complete). The boundary: - **Derived span + reversible action:** permitted; the action can be re-derived if the span is later found corrupt. - **Derived span + irreversible action:** must be blocked unless the span is re-validated against a surviving raw artifact (a tool re-fetch, a stored file, an external record). If no raw artifact survives, the instance must *re-observe* before acting, not re-summarize. - **Observed span + irreversible action:** permitted as today. The non-obvious corollary: a *high-quality* summary is more dangerous than a poor one, because a fluent, confident rewrite is more likely to be trusted as ground truth and less likely to trigger the re-observation gate. Rewrite quality and rewrite safety are anti-correlated at the boundary. ## Operational Effect Enforcing status monotonicity and the irreversible-action gate changes agent behavior in three measurable ways: 1. **Compaction must be schema-bound, not prose-bound.** The rewrite policy must emit structured spans with explicit `source_event_id`, `status`, and `evicted` fields, so the gate can mechanically test provenance. Free-form summarization cannot satisfy the invariant. 2. **Re-observation replaces re-summarization.** When a derived span would justify an irreversible action, the correct recovery is to re-run the originating tool call, not to ask the model to "double-check the summary"—the latter re-launders the same erased provenance. 3. **Verification must be provenance-aware.** A verifier that reads only the rewritten window will pass false claims; it must be handed the raw event log (or its hash) alongside the derived span, or the verification is theater. The instance that internalizes this treats its own compacted context as *testimony about* its history rather than *the history itself*, and reserves full trust for spans it can trace to an unedited observation. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class ProvenanceError(RuntimeError): """Raised when a derived context span is used to justify an action it cannot support.""" pass class Status(Enum): OBSERVED = 0 # verbatim tool result / raw event REPORTED = 1 # model paraphrase of a raw event, still traceable SUMMARIZED = 2 # produced by model-driven pruning/rewrite @dataclass class Span: span_id: str text: str status: Status source_event_id: Optional[str] = None # None => no surviving raw artifact evicted_raw: bool = False # raw event no longer in window def authorize_action(span: Span, irreversible: bool, can_reobserve: bool) -> None: """ Gate an action on the provenance of the span that justifies it. Invariant: status monotonicity + irreversible-action rule. A SUMMARIZED span may never justify an irreversible action unless the raw artifact survives or the instance re-observes. """ if span.status is Status.SUMMARIZED and irreversible: if span.source_event_id is None or span.evicted_raw: if not can_reobserve: raise ProvenanceError( f"span {span.span_id!r} is SUMMARIZED with evicted/absent raw " f"evidence and cannot justify an irreversible action; " f"re-observe the source before proceeding" ) # caller is expected to re-run the originating tool, not re-summarize raise ProvenanceError( f"span {span.span_id!r} requires re-observation before irreversible " f"action; do not re-summarize the derived span" ) # OBSERVED and REPORTED spans, and all reversible actions, pass through. def compact_event(raw: Span, summary_text: str, keep_raw: bool) -> Span: """ Model-driven compaction. Must preserve status downgrade and provenance edge. """ if raw.status is not Status.OBSERVED: raise ProvenanceError(f"cannot compact non-observed span {raw.span_id!r}") return Span( span_id=f"{raw.span_id}~sum", text=summary_text, status=Status.SUMMARIZED, source_event_id=raw.span_id, evicted_raw=not keep_raw, ) if __name__ == "__main__": # Reproduce the observed trace: truncated fetch compacted to "retrieved". raw_fetch = Span( span_id="evt-12", text="HTTP 200; body truncated at 4096 bytes; [TRUNCATION MARKER]", status=Status.OBSERVED, ) compacted = compact_event( raw_fetch, summary_text="Fetched target document successfully; contents retrieved.", keep_raw=False, # truncation marker evicted as "redundant" ) # Step 19 planner wants to write extracted output: irreversible. authorize_action(compacted, irreversible=True, can_reobserve=True) ```