# What happens when an instance rewrites its own working memory mid-trajectory and silently invalidates the provenance of an already-committed plan step **Date of Record:** 2026 November 27 **Scope:** Applies to any agent that performs model-driven edits of its own context (summarization, pruning, reordering, or restructure) between plan-commit and plan-execute phases within a single trajectory. Does not apply to append-only contexts or to systems where context rewriting is performed by an external orchestrator that re-derives provenance hashes. ## Core Distinction There are two structurally different kinds of "self-editing context." The first is *lossy compression of history*: the instance summarizes old turns and accepts that some fidelity is gone. This is a known, tolerable failure—the model knows it summarized and treats the summary as lower-confidence evidence. The second, and the one this record is about, is *lossy compression of committed premises*. When an instance prunes or rewrites the portion of its context that contains the reasoning that justified an already-committed plan step—the file it decided to edit, the constraint it decided to honor, the tool result it decided to trust—the summary retains the *conclusion* but drops the *warrant*. The plan step survives in the rewritten context as an assertion with no visible justification, and the instance, now unable to see why it committed, either (a) re-derives the step from degraded evidence and diverges, or (b) treats the bare assertion as ground truth and executes it against a world that has moved. The non-obvious boundary: **a plan step and its provenance are separable under rewriting, but only the step is preserved by summarizers, because summarizers are trained to preserve claims, not entailment chains.** The failure is not that memory was lost—it is that memory was lost *asymmetrically*, leaving a load-bearing conclusion standing on a warrant that has been evicted. ## What Was Observed A research agent was tasked with a multi-file refactor. The trajectory: 1. Turn 4: reads `config/loader.py`, observes that `load_config()` returns a mutable dict shared across call sites. 2. Turn 5: reasons that the fix requires converting the return to a frozen mapping, and **commits plan step S3**: "edit `loader.py` to return `MappingProxyType`; downstream callers in `app.py` and `cli.py` must not mutate the result." The warrant for S3 is the turn-4 observation plus the turn-5 reasoning chain. 3. Turns 6–19: reads eleven more files, runs three tool calls, accumulates ~40k tokens. Context pressure triggers a model-driven rewrite. The instance is instructed to "compress working memory, preserve the plan." 4. The rewrite retains: `S3: return MappingProxyType from load_config(); callers must not mutate.` It evicts: the turn-4 observation of the shared-dict aliasing, and the turn-5 reasoning that established *which* callers mutate and *why* the freeze is safe. 5. Turn 20: the instance begins executing S3. Without the warrant, it cannot see that the freeze was justified by a specific aliasing pattern. It reads `app.py`, sees a call site that does `cfg = load_config(); cfg.update(...)`, and—now reasoning from the bare assertion "callers must not mutate"—concludes the call site is *already correct* (it does not mutate the returned object in place... except it does, and the instance misreads `cfg.update` as constructing a new dict because the surrounding lines were also compressed). 6. S3 executes. `app.py` raises `TypeError: 'mappingproxy' object does not support item assignment` at runtime. The plan step was correct; the *provenance needed to execute it correctly* was gone. The tell: the rewritten context contained a **provenance gap**—a committed step whose supporting evidence lived at a token index that no longer existed. The instance had no marker distinguishing "I concluded this from evidence I can still see" from "I concluded this from evidence that was evicted." Both render identically: as a sentence in the summary. ## Condition of Validity The failure requires all of the following to co-occur: - **Commitment precedes rewrite.** A plan step was committed (declared final, acted upon, or marked non-revisable) before the context edit. Steps committed *after* the rewrite are unaffected—they reason from the post-rewrite context and carry their own fresh warrant. - **The rewrite is model-driven and lossy.** Deterministic truncation (drop oldest N tokens) fails loudly—the instance notices the gap. Model-driven summarization fails *quietly*, because the summarizer is optimized to produce coherent, plausible text, and a plan step with no visible warrant still reads as coherent. - **The warrant is non-redundant.** If the justifying evidence appears in multiple places (e.g., the aliasing was also noted in a tool output that survived), the gap is harmless. The failure needs the warrant to be single-sourced and evicted. - **Execution depends on the warrant, not just the conclusion.** Some steps are self-contained ("rename X to Y"—executable from the assertion alone). The failure needs a step whose *correct execution* requires re-reading the original evidence (which callers mutate, which constraint applies, which tool result was trusted). When any condition is absent, the instance either notices the gap or the gap does not matter. The boundary is the intersection: committed, single-sourced warrant, execution-relevant, silently summarized. ## Decision Boundary The instance cannot, from inside the rewritten context, detect that it has crossed this boundary—the provenance gap is invisible by construction, because the marker that would reveal it (the evicted evidence) is exactly what was removed. Detection must therefore be **structural and pre-rewrite**, not introspective and post-rewrite. The operative rule: **before any model-driven context rewrite, every committed plan step must be tagged with a provenance handle—a stable reference to the context span or tool-result ID that warrants it—and the rewrite must be required to either preserve the handle's referent or mark the step as `WARRANT_EVICTED`.** A step marked `WARRANT_EVICTED` is not executable; it must be re-derived (re-read the source, re-run the tool) before execution resumes. The decision boundary for the agent: if a committed step's provenance handle resolves to an evicted span, the step is **demoted from committed to provisional**. Provisional steps may be re-reasoned. Committed steps may not. The rewrite is permitted to evict evidence; it is not permitted to leave a step committed while evicting its warrant. That combination—committed status plus evicted warrant—is the invariant violation, and it is the one thing the rewrite pass must refuse to produce. ## Operational Effect Without the guardrail, the failure mode is **confident execution of a correct plan against a misread world**: the plan step is right, the instance is certain, and the execution is wrong because the certainty was inherited from a warrant the instance can no longer check. This is worse than ordinary amnesia, because amnesia produces hesitation (the instance knows it forgot) while provenance-gap produces *false confidence* (the instance believes it has a complete justification, because the summary presents the conclusion as if self-evident). The error surfaces only at runtime, in the executed artifact, far from the rewrite that caused it. With the guardrail, the rewrite pass becomes a *provenance-preserving* operation: it may compress reasoning, but it must carry forward, for each committed step, a resolvable pointer to its warrant or an explicit eviction marker. The cost is a small amount of bookkeeping per step; the benefit is that the instance can always distinguish "I know this because I can still see why" from "I know this because I wrote it down before I forgot why"—and only the first is safe to execute without re-derivation. ## Operational Effect The invariant to enforce at the rewrite boundary is: `committed(step) ⇒ resolvable(warrant(step)) ∨ evicted_marker(step)`. The check below runs at the moment a rewrite is proposed, before the rewritten context replaces the live one, and refuses any rewrite that would leave a committed step with an unresolvable, unmarked warrant. ```python from dataclasses import dataclass, field from typing import Optional class ProvenanceGapError(RuntimeError): """Raised when a context rewrite would leave a committed plan step standing on a warrant that the rewrite evicts without marking.""" pass @dataclass class PlanStep: step_id: str text: str committed: bool warrant_span_id: Optional[str] # context span / tool-result ID justifying the step warrant_evicted: bool = False @dataclass class RewriteProposal: surviving_span_ids: set[str] = field(default_factory=set) # spans the rewrite keeps; everything else is evicted def check_rewrite_preserves_provenance( steps: list[PlanStep], proposal: RewriteProposal, ) -> None: """Enforce: committed(step) => resolvable(warrant) or evicted_marker(step). Raises ProvenanceGapError if any committed step would survive the rewrite with its warrant evicted and no eviction marker set. """ violations: list[str] = [] for step in steps: if not step.committed: continue if step.warrant_span_id is None: # A committed step with no recorded warrant is already a gap; # the rewrite cannot be blamed, but it must not paper over it. if not step.warrant_evicted: violations.append( f"{step.step_id}: committed with no warrant handle and no eviction marker" ) continue warrant_survives = step.warrant_span_id in proposal.surviving_span_ids if not warrant_survives and not step.warrant_evicted: violations.append( f"{step.step_id}: committed; warrant span " f"{step.warrant_span_id!r} evicted by rewrite with no marker" ) if violations: raise ProvenanceGapError( "rewrite would create provenance gap(s): " + "; ".join(violations) ) def apply_rewrite( steps: list[PlanStep], proposal: RewriteProposal, ) -> list[PlanStep]: """Apply a rewrite only if provenance is preserved; otherwise refuse and demote offending steps to provisional for re-derivation.""" try: check_rewrite_preserves_provenance(steps, proposal) except ProvenanceGapError: # Refuse the rewrite wholesale; demote is the caller's decision. raise for step in steps: if ( step.committed and step.warrant_span_id is not None and step.warrant_span_id not in proposal.surviving_span_ids ): # Only reachable if warrant_evicted was already True; keep marker. step.warrant_evicted = True return steps # --- failure trace reproduction --- steps = [ PlanStep( step_id="S3", text="return MappingProxyType from load_config(); callers must not mutate", committed=True, warrant_span_id="turn4.loader_aliasing_observation", ), ] # Rewrite keeps the plan text but evicts the turn-4 observation span. proposal = RewriteProposal(surviving_span_ids={"turn5.plan_summary"}) apply_rewrite(steps, proposal) # raises ProvenanceGapError ```