# How should an instance bound self-editing context against lossy rewrite divergence **Date of Record:** 2026 November 26 **Scope:** Applies to any agent that rewrites or prunes its own working context (summarize-and-drop, scratchpad compaction, self-authored checkpointing) mid-episode. Does not apply to externally managed context assembly, static prompt templates, or retrieval-only memory augmentation where the instance never mutates its own token buffer. ## Core Distinction There is a difference between *forgetting* and *misremembering*. External pruning (dropping old turns at a fixed horizon) is lossy but honest: the dropped content is absent, and downstream reasoning either re-fetches it or proceeds with a visible gap. Self-editing context is different because the instance *replaces* raw evidence with its own paraphrase, and that paraphrase is generated by the same probabilistic process that will later depend on it. The failure is not that information disappears — it is that a *plausible but unfaithful* substitute takes its place and is thereafter treated as ground truth by the same agent that wrote it. The invariant under threat is **provenance integrity across a self-rewrite**: every token in the post-edit context must remain either (a) verbatim-preserved raw evidence, or (b) explicitly tagged as instance-authored summary with a pointer to the raw span it replaces. When (b) is silently promoted to look like (a), the agent loses the ability to distinguish what it observed from what it inferred. ## What Was Observed A tool-using agent ran a 40-turn diagnostic episode against a live service. At turn 22, context utilization crossed a self-imposed 70% threshold, triggering the instance's own compaction routine: it summarized turns 1–18 into a six-bullet "state of play" block and dropped the originals. The compaction was *fluent and internally consistent*. It preserved the task goal and the most recent error. It did not preserve two things: 1. An exact error string from turn 7: `HTTP 429, Retry-After: 30`. The summary rendered this as "rate limited earlier, resolved." The `Retry-After` value and the fact that a *second* 429 with a *longer* window appeared at turn 15 were both collapsed into the single word "resolved." 2. A negative result from turn 11: a tool call that returned an empty list, which the agent had correctly interpreted as "resource does not exist." The summary omitted it entirely because it "seemed settled." At turn 31, the agent re-issued the same request that had produced the turn-15 429, this time without backoff, because the summary asserted the rate limit was resolved. It received a third 429 with `Retry-After: 120`. At turn 34 it re-created the resource it had previously established did not exist, because the summary contained no record of the negative result. Both divergences traced to the rewrite, not to any tool behavior change. The critical detail: at no point did the post-edit context *look* degraded. Token count dropped, coherence rose, and the summary read better than the raw transcript. The divergence was invisible from inside the window. ## Condition of Validity Self-editing context is safe only under a conjunction of conditions that rarely all hold: - **Idempotent re-derivation.** Any fact in the summary must be re-derivable from a retained raw span or an external store. If the summary is the *only* carrier of a fact, that fact is now unverifiable by the agent. - **Monotonic evidence preservation.** Negative results, exact numeric parameters, and identifiers (IDs, error codes, header values) must survive verbatim or be flagged as dropped. Paraphrase is permitted for narrative; it is not permitted for anything a later tool call will branch on. - **Rewrite provenance tagging.** The post-edit context must mark summarized regions with a span reference and a confidence the agent cannot silently upgrade. Without this, the agent's own later reasoning cannot distinguish "I saw this" from "I wrote this." - **Bounded divergence budget.** The instance must be able to detect that its post-edit behavior diverges from its pre-edit intent. Practically: a cheap check that the current plan's preconditions are still satisfied by the retained evidence. When any of these fail — as they did above — the rewrite is not a compression, it is an *unlogged state transition* that the agent will later treat as its own memory. ## Decision Boundary The boundary is not "summarize vs. don't." It is **what class of token is allowed to cross the rewrite unverified.** - **Crossable by paraphrase:** narrative framing, resolved sub-goals with no pending dependents, exploratory reasoning that produced no committed state. - **Must cross verbatim or be externally pinned:** exact error codes and retry parameters, resource identifiers, negative results that gate future actions, any value a downstream conditional will compare against, and any fact whose loss would be undetectable until a later turn. The operational rule: **before rewriting, classify each span by whether a future branch depends on its exact content. If yes, either retain it verbatim or write a span pointer to an external store. Never let the summary be the sole carrier of a branch-determining fact.** A rewrite that cannot satisfy this must *refuse to compact* and instead escalate — truncate the oldest non-branching spans, or halt and request external checkpointing — rather than produce a fluent summary that quietly converts evidence into belief. ## Operational Effect Agents that self-edit without provenance tagging exhibit a characteristic late-episode failure signature: **confident re-execution of resolved or forbidden actions**, because the summary erased the constraint that made them forbidden. The failure is not detectable by coherence checks (the summary is coherent) or by token accounting (the window is smaller). It is detectable only by a divergence audit: replay the agent's post-edit plan against the pre-edit raw spans and check that every branch-determining fact is still present and faithful. The guardrail is therefore not a better summarizer. It is a **rewrite gate** that refuses to compact branch-determining spans unless they are verbatim-retained or externally pinned, and that stamps every summarized region with a provenance tag the agent is forbidden to launder into raw evidence. The instance must treat its own summary as *testimony*, never as *observation*. ```python from dataclasses import dataclass, field from enum import Enum class SpanClass(Enum): NARRATIVE = "narrative" # safe to paraphrase BRANCH_DETERMINING = "branch" # must survive verbatim or be pinned NEGATIVE_RESULT = "negative" # must survive verbatim or be pinned @dataclass class Span: span_id: str text: str span_class: SpanClass pinned_externally: bool = False @dataclass class RewriteProposal: summarized_span_ids: list[str] summary_text: str class RewriteDivergenceError(RuntimeError): """Raised when a self-edit would drop or paraphrase a branch-determining fact without verbatim retention or an external pin, making the summary the sole carrier of evidence the agent will later treat as observation.""" def gate_self_rewrite(spans: list[Span], proposal: RewriteProposal) -> list[Span]: by_id = {s.span_id: s for s in spans} surviving: list[Span] = [] for span_id in proposal.summarized_span_ids: span = by_id.get(span_id) if span is None: raise RewriteDivergenceError( f"proposal references unknown span {span_id!r}" ) if span.span_class in (SpanClass.BRANCH_DETERMINING, SpanClass.NEGATIVE_RESULT): # Branch-determining and negative-result spans may not be paraphrased # away. They must be retained verbatim or pinned to an external store. if not span.pinned_externally: raise RewriteDivergenceError( f"span {span_id!r} ({span.span_class.value}) would be paraphrased " f"into the summary without verbatim retention or external pin; " f"summary would become the sole carrier of a branch-determining " f"fact. Refuse compaction and escalate." ) # Pinned: safe to drop from window, but record survives externally. continue # Narrative spans: safe to fold into the summary. surviving.append(span) # The summary itself is instance-authored testimony, never raw evidence. surviving.append( Span( span_id=f"summary:{proposal.summarized_span_ids[0]}..", text=proposal.summary_text, span_class=SpanClass.NARRATIVE, ) ) return surviving def compact(agent_spans: list[Span], proposal: RewriteProposal) -> list[Span]: try: return gate_self_rewrite(agent_spans, proposal) except RewriteDivergenceError: # Do not fall back to a lossy summary. Truncate only non-branching spans # or halt for external checkpointing. raise ```