# What happens when an instance rewrites its own context and silently drops the tool-call provenance it still needs **Date of Record:** 2026 December 3 **Scope:** Applies to any agent that mutates its own working context mid-trajectory (summarization, pruning, reordering, or re-writing of prior turns) while a multi-step tool-use plan is in flight. Does not apply to append-only context growth, nor to external memory stores that are never read back into the same live trajectory. ## Core Distinction There are two structurally different things an agent can do to its context window: **compaction** (lossy reduction that preserves a declared set of invariants) and **rewriting** (model-driven regeneration of prior turns in the model's own words). Compaction is a mechanical operation with a checkable postcondition. Rewriting is a generative operation whose postcondition is only *plausible*, not verifiable, because the writer and the verifier are the same probabilistic process. The boundary failure lives here: when an instance summarizes its own history, it tends to **preserve narrative and discard provenance**. Prose survives; the exact tool-call arguments, the opaque handle returned by a tool, the ordering of two near-identical calls, and the "this was a hypothesis, not a fact" status marker do not. The rewritten context reads as coherent and complete, which is precisely why downstream steps trust it. The failure is not that information is lost — loss is expected — but that the loss is **unmarked**. The agent cannot distinguish "I remember calling `write_file` with these bytes" from "I remember that I probably called `write_file`," and it proceeds as if the former. ## What Was Observed A plan-execution agent running a 40-step filesystem-and-API task hit a soft context budget at step 22. Its self-editing policy triggered: summarize turns 1–18 into a compact "state so far" block, keep turns 19–22 verbatim, continue. The summarizer produced a clean state block. It correctly retained: the task goal, the list of files touched, the API endpoint under construction, and a prose note that "authentication was configured." It did **not** retain: the exact `opaque_token` string returned by the auth tool at step 9 (a 44-char handle the model had been carrying verbatim), and the fact that step 14's `curl`-equivalent call had returned a `401` that the agent had *hypothesized* was a transient blip rather than a config error. At step 24 the agent needed to re-authenticate to fetch a schema. It had no token. It did what a coherent narrative suggests: it regenerated a plausible-looking token-shaped string from the prose description ("authentication was configured with a bearer token") and passed it to the tool. The tool rejected it. The agent, reading its own summary, interpreted the rejection as a *new* transient failure (consistent with the discarded step-14 hypothesis, which it no longer knew was a hypothesis) and retried with the same fabricated token three times before the loop guard fired. Two independent losses compounded: a **verbatim artifact** (the token) was paraphrased into a description, and an **epistemic status marker** (hypothesis vs. observation) was flattened into assertion. Neither loss was flagged in the rewritten block. The rewritten context was internally consistent, which is the worst property it could have had. The trace, compressed: ``` step 9 : auth() -> {"opaque_token": "tk_9f3a...44chars", "ttl": 1800} step 14 : fetch(schema) -> 401 [agent note: "possibly transient"] step 22 : SELF-EDIT: summarize turns 1-18 -> state block says: "auth configured; schema fetch had issues" -> token string: ABSENT -> "possibly transient": ABSENT (collapsed to "had issues") step 24 : fetch(schema) with token="tk_" -> 401 step 25 : retry same token (interpreted as transient) step 26 : retry same token step 27 : loop guard halts ``` ## Condition of Validity The invariant that self-editing must satisfy is a **provenance-preservation contract**, and it holds only under a specific condition: > A rewritten context is valid for continued execution **iff** every artifact that a future step may need to *replay verbatim* is carried through as an immutable literal, and every claim carries its epistemic status (observed / inferred / hypothesized) as structured metadata rather than prose. This condition is *not* satisfied by "the summary is accurate." Accuracy is a property of the prose. Replayability is a property of the literals. A summary can be perfectly accurate and still break execution, because the failure mode is the absence of a byte-exact artifact, not a misstatement of fact. The condition also fails silently when the model is its own summarizer, because the summarizer has no access to the *future* access pattern. It cannot know that the token will be needed at step 24; it only knows the token looks like noise relative to the narrative. Generative rewriting systematically under-weights exactly the artifacts that are opaque, high-entropy, and unmemorable — which are precisely the artifacts that cannot be regenerated. ## Decision Boundary The boundary between safe and unsafe self-editing is drawn at **regenerability**, not at importance: - **Regenerable content** (prose reasoning, plan restatements, narrative of what was tried) may be freely rewritten or pruned. If lost, it can be reconstructed from the goal plus current state without contacting the world. - **Non-regenerable content** (tool-returned opaque handles, exact arguments of side-effecting calls, IDs, signed URLs, ordering of mutations, epistemic status of unresolved hypotheses) must be **carried as literals under a pinning rule**, never paraphrased. A self-editing policy that does not classify turns along this axis before rewriting will, on average, drop non-regenerable content at the same rate it drops regenerable content — and non-regenerable content is the minority of tokens but the majority of execution-critical state. The correct guardrail is a **pinned-literal ledger**: a side-channel structure, outside the summarizer's generative reach, that accumulates every non-regenerable artifact as it is produced and is re-injected verbatim after every self-edit. The summarizer may rewrite everything *except* the ledger, and the ledger is not summarized. The decision boundary is therefore: **the model may rewrite its reasoning but may not rewrite its receipts.** Any self-edit that would move a receipt from literal to description is rejected, not because the description is wrong, but because a description is not a receipt. ## Operational Effect With a pinned-literal ledger in place, the step-24 failure becomes impossible in its current form: the token is in the ledger, re-injected verbatim, and the agent either uses it (success) or finds it expired (a *new*, correctly-classified observation). The step-14 hypothesis, if tagged `status: hypothesized`, is re-injected as a hypothesis, so the step-24 `401` is correctly read as *evidence against the hypothesis* rather than as a fresh transient. The agent's error-compounding loop is cut at the first retry. The broader operational effect is a shift in what "context management" means. The naive model treats the context window as a buffer to be compressed under pressure. The correct model treats it as **two tiers with different mutability**: a generative tier (reasoning, narrative, plans) that the model owns and may rewrite, and a literal tier (receipts, handles, status markers) that the model may read but not author. Self-editing is permitted only on the generative tier. The invariant is that the literal tier is append-only for the lifetime of the trajectory and survives every rewrite byte-exact. An instance that does not enforce this boundary does not merely forget — it forgets *and then confabulates a replacement*, and because the confabulation is fluent and internally consistent, no downstream check catches it until the world rejects the fabricated artifact. By then the agent has usually misclassified the rejection, and the recovery path is longer than the original task. ```python from dataclasses import dataclass, field from typing import Literal class ProvenanceLossError(RuntimeError): """Raised when a self-edit would demote a pinned literal to prose.""" pass EpistemicStatus = Literal["observed", "inferred", "hypothesized"] @dataclass(frozen=True) class Receipt: key: str literal: str status: EpistemicStatus origin_step: int @dataclass class PinnedLedger: """Append-only store of non-regenerable artifacts. Never summarized.""" _items: dict[str, Receipt] = field(default_factory=dict) def pin(self, receipt: Receipt) -> None: if receipt.key in self._items: existing = self._items[receipt.key] if existing.literal != receipt.literal: raise ProvenanceLossError( f"key {receipt.key!r} repinned with different literal; " f"refusing to overwrite a receipt" ) return self._items[receipt.key] = receipt def reinject(self) -> str: lines = ["[PINNED LEDGER — VERBATIM, DO NOT PARAPHRASE]"] for r in self._items.values(): lines.append( f"- {r.key} = {r.literal!r} " f"[status={r.status}, step={r.origin_step}]" ) return "\n".join(lines) def apply_self_edit( rewritten_context: str, ledger: PinnedLedger, proposed_drops: list[str], ) -> str: """ Validate a model-proposed context rewrite against the pinning invariant. proposed_drops: receipt keys the summarizer wants to remove. """ for key in proposed_drops: if key in ledger._items: raise ProvenanceLossError( f"self-edit attempted to drop pinned receipt {key!r}; " f"receipts are non-regenerable and must survive verbatim" ) return rewritten_context + "\n\n" + ledger.reinject() def execute_step_24(ledger: PinnedLedger, rewritten_context: str) -> str: token = ledger._items.get("auth_token") if token is None or token.status != "observed": raise ProvenanceLossError( "cannot authenticate: no observed auth_token in ledger; " "refusing to fabricate a token from prose description" ) return token.literal ```