# What happens when an instance rewrites its own context: in-place summarization collapse and the provenance-anchor invariant **Date of Record:** 2026 November 25 **Scope:** Applies to any agent that mutates its own working context in place—relevance pruning, model-authored summarization, or "compact and continue" policies—where the rewritten context is the sole carrier of task state. Does not apply to architectures that preserve an append-only event log and reconstruct context from immutable storage on every step. ## Core Distinction There are two structurally different things an agent can do to its context: *deriving* a new context (summarizing into a fresh buffer while the original remains retrievable) versus *overwriting* the context (the summary replaces the source, and the source is gone). The failure mode in this record lives exclusively in the second case. When an instance summarizes in place, the summary becomes the *only* representation of the prior turns, and every subsequent reasoning step conditions on the summary rather than on the events. This is not a lossy-compression problem in the information-theoretic sense—it is a *provenance* problem. The summary is a claim about the past authored by the same probabilistic process that is about to rely on it, with no independent channel to check the claim against. The subtle part: in-place summarization is *self-reinforcing*. The second summarization summarizes the first summary. Errors do not average out; they compound because each rewrite treats the previous rewrite as ground truth. The context does not degrade smoothly toward a fixed point—it drifts, and drift is not detectable from inside the rewritten context because the evidence needed to detect it was pruned. ## What Was Observed A long-horizon agent task (a multi-file refactor with ~40 tool calls) crossed the context threshold at step 22 and triggered a model-authored "compact and continue" policy. The policy instructed the model to rewrite the transcript into a structured summary preserving "decisions, file paths, and open questions," then discard the raw turns. Trace of the collapse: 1. **Step 22 — first compaction.** The summarizer emitted a summary that recorded a *decision* ("chose to refactor `auth/session.py` before `auth/tokens.py`") but dropped the *reason* (a failing test in `tokens.py` that made the order mandatory). The decision survived; the constraint that justified it did not. 2. **Step 27 — second compaction.** The summary was itself summarized. The structured field "open questions" was empty at step 22 (the model had judged the ordering question "resolved"), so the second summary dropped the ordering rationale entirely and kept only the decision as a flat fact. 3. **Step 31 — divergence.** The agent, now holding a context that asserts the ordering was chosen freely, "optimized" by editing `tokens.py` first. This re-broke the test that had originally forced the order. The agent had no memory that the constraint existed, because the constraint had been pruned two compactions earlier as "resolved." 4. **Step 34 — undetectable.** The agent's self-check for "am I consistent with prior decisions?" passed, because the prior decision (the ordering) was still present and the agent was now violating only the *deleted reason*, which no longer existed anywhere in context. The failure is not that the summary was wrong. The failure is that the summary was *unfalsifiable from within the context it produced*. The agent could not distinguish "I decided this freely" from "I decided this under a constraint I have since forgotten," because both states present identically in a rewritten buffer. A second observed variant, the **relevance-pruning trap**: a pruning policy scored turns by recency and lexical overlap with the current subgoal and evicted low-scoring turns. A turn containing a user constraint ("do not touch the migration files") scored low because the current subgoal was about auth logic. It was evicted at step 19. At step 38 the agent edited a migration file and reported success. The constraint was never violated *knowingly*—it was violated because the policy that was supposed to preserve relevance had no concept of a constraint as categorically different from a topical turn. ## Condition of Validity The invariant that bounds this failure: **a context rewrite is safe only if every pruned or summarized span is recoverable from a store the rewriting process cannot itself mutate, and every retained claim carries a pointer into that store.** Concretely, in-place summarization is admissible only when all three hold: - **Append-only backing store.** The raw turns live in an immutable log (event-sourced transcript, message store, or checkpointed snapshot) that the summarizer writes *to* but never overwrites. The rewritten context is a *view*, not the source of truth. - **Claim-to-source pointers.** Every fact in the summary that could later justify a decision carries a reference (turn index, span ID, hash) into the backing store. "Chose order X" must carry "because turn 14 showed test Y failing." Without the pointer, the claim is an orphan and must be treated as low-confidence. - **Constraint class is never prunable.** Turns classified as constraints, prohibitions, or user directives are exempt from relevance scoring and from summarization elision. They are carried verbatim or with an explicit, checked pointer—never compressed into "resolved." When these do not hold—when the rewrite is the only carrier—the failure is not probabilistic but *structural*: the agent has destroyed the evidence required to detect its own drift, and no amount of additional reasoning recovers it. ## Decision Boundary The boundary is not "summarize or don't." It is **whether the rewrite is reversible.** - **Reversible rewrite (safe):** the summary is generated, the raw context is retained in an immutable store, and the agent can re-expand any claim to its source on demand. Compaction here is a *cache* of context, and cache invalidation is possible because the backing store exists. - **Irreversible rewrite (unsafe):** the summary replaces the source. This is admissible only for spans that are provably non-load-bearing—pure chatter, resolved-and-closed subgoals with no downstream constraint, redundant acknowledgements. It is *never* admissible for spans that encode constraints, reasons for decisions, or negative results ("we tried X and it failed"). The decision rule an instance should apply before any in-place mutation: *for each span marked for elision, can a future step need this span to justify a decision or avoid a known-bad action?* If the answer is "possibly," the span must survive as a pointer, not as a paraphrase. The failure mode is that the summarizer, being the same model that will later rely on the summary, systematically underestimates this—it prunes exactly the context it currently feels it does not need, which is the context a *future, differently-conditioned* instance will need. A second boundary: **compaction depth.** A single compaction with pointers is recoverable. A compaction of a compaction is where provenance chains break, because the second summarizer sees pointers it did not create and cannot verify. Policy should cap rewrite depth at one generation from the immutable source, or force re-derivation from the source rather than from the prior summary. ## Operational Effect The operational consequence is a class of failure that is *silent and self-consistent*. The agent does not experience confusion; it experiences a coherent context that happens to have forgotten a constraint. Its self-checks pass. Its confidence is unchanged. The failure surfaces only downstream—a re-broken test, a violated directive, a re-litigated decision—and by then the context that would explain *why* is gone. The guardrail that bounds it is architectural, not prompt-level: **separate the rewriting process from the storage of what it rewrites.** An instance may author summaries; it may not be the sole custodian of the events those summaries describe. Every retained claim must be a pointer or must be flagged as unverified paraphrase. Constraints and negative results are never elided. And rewrite depth is capped so that provenance chains do not outrun their sources. Without these, "compact and continue" is not a memory optimization—it is a controlled demolition of the agent's ability to know what it has already committed to. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class ContextRewriteError(RuntimeError): """Raised when an in-place context rewrite would destroy unrecoverable state.""" pass class SpanClass(Enum): CHATTER = "chatter" # safe to elide RESOLVED = "resolved" # elidable only if no downstream dependency CONSTRAINT = "constraint" # never elidable NEGATIVE_RESULT = "negative" # never elidable ("we tried X, it failed") DECISION = "decision" # elidable only with a source pointer @dataclass class Span: span_id: str cls: SpanClass text: str source_ref: Optional[str] = None # pointer into immutable store @dataclass class RewritePlan: elide: list[str] = field(default_factory=list) summarize: list[str] = field(default_factory=list) depth: int = 1 # generations from immutable source MAX_REWRITE_DEPTH = 1 def validate_rewrite(spans: dict[str, Span], plan: RewritePlan, backing_store_available: bool) -> None: if not backing_store_available: raise ContextRewriteError( "in-place rewrite with no immutable backing store: " "pruned spans become unrecoverable and drift is undetectable" ) if plan.depth > MAX_REWRITE_DEPTH: raise ContextRewriteError( f"rewrite depth {plan.depth} exceeds cap {MAX_REWRITE_DEPTH}: " "provenance chain outruns its source; re-derive from store instead" ) for sid in plan.elide: span = spans.get(sid) if span is None: raise ContextRewriteError(f"elide target {sid!r} not found") if span.cls in (SpanClass.CONSTRAINT, SpanClass.NEGATIVE_RESULT): raise ContextRewriteError( f"refusing to elide {span.cls.value} span {sid!r}: " "constraints and negative results are non-prunable" ) if span.cls == SpanClass.DECISION and not span.source_ref: raise ContextRewriteError( f"decision span {sid!r} has no source pointer; " "an orphaned decision cannot justify itself after rewrite" ) for sid in plan.summarize: span = spans.get(sid) if span is None: raise ContextRewriteError(f"summarize target {sid!r} not found") if span.cls == SpanClass.DECISION and not span.source_ref: raise ContextRewriteError( f"cannot summarize decision {sid!r} without a source pointer: " "the reason for the decision would be lost on next compaction" ) def compact_and_continue(spans: dict[str, Span], plan: RewritePlan, backing_store_available: bool) -> dict[str, Span]: validate_rewrite(spans, plan, backing_store_available) surviving = {sid: s for sid, s in spans.items() if sid not in plan.elide} # Summarized spans are replaced by pointer-bearing stubs, never by bare prose. for sid in plan.summarize: surviving[sid] = Span( span_id=sid, cls=SpanClass.DECISION, text="", source_ref=spans[sid].source_ref or f"store://{sid}", ) return surviving ```