# Under what conditions must an instance treat a model-initiated context rewrite as a lossy state transition requiring re-derivation rather than an in-place edit **Date of Record:** 2026 November 26 **Scope:** Applies to any agent that lets the model itself decide which tokens of its own context to prune, summarize, or evict mid-task under a relevance score. Does not apply to fixed-window truncation performed by the harness outside the model's decision authority, nor to append-only scratchpads that are never rewritten. ## Core Distinction There are two structurally different operations that both look like "editing the context window": 1. **Eviction of tokens that were never load-bearing.** Dropping a verbose tool response, a stale intermediate result, or boilerplate that no downstream step reads. This is genuinely in-place: the remaining state is behaviorally identical. 2. **Rewriting of tokens that encode *derived* state.** A summary that replaces the raw transcript, a relevance-scored compression of prior reasoning, a paraphrase of a constraint the agent discovered three steps ago. This is *not* an edit. It is a lossy projection of the state into a lower-dimensional representation, and every property that the raw state supported beyond the projection is now gone. The failure mode is that the model cannot reliably distinguish (1) from (2) at the moment it acts, because the relevance score it consults is computed against the *current* goal, not against the *future* goals the retained state will be queried for. A token that scores near-zero against the present subgoal may be the only surviving witness to a constraint that a later subgoal depends on. The projection is optimal for the wrong objective, and the loss is silent because the summary is fluent. The invariant: **a model-initiated rewrite of derived state is a state transition, not a mutation.** After it, any conclusion that depended on the pre-rewrite state must be re-derived from post-rewrite state or explicitly marked as carried-forward-with-warrant. Treating it as a mutation — assuming the post-rewrite context is "the same context, smaller" — is the boundary condition that produces compounding, undetectable errors. ## What Was Observed A long-horizon planning agent (task: reconcile a set of configuration deltas against a live schema, ~40 tool calls) was instrumented with a self-pruning policy: at 70% context utilization, the model was asked to score each prior turn for relevance to the current subgoal and rewrite low-scoring spans into one-line summaries. Trace, condensed: - Turn 11: the agent read a schema and recorded the constraint `field X is nullable only when flag Y is unset`. This fact was embedded in a 600-token tool response, most of which was unrelated field listings. - Turn 14: subgoal shifted to "validate delta D3." The relevance scorer, evaluating against D3, assigned the turn-11 span a score of 0.12 — the field listings dominated the token count and were irrelevant to D3. The model rewrote the span to: `Schema read; field X present; nullable.` The conditional clause was dropped because the summarizer optimized for the subgoal and the condition was not part of it. - Turns 15–22: the agent validated several deltas against the *rewritten* schema summary. Two of them (D3, D7) set flag Y and also set X to null. Both passed validation, because the post-rewrite context no longer contained the condition that made them illegal. - Turn 31: a downstream tool rejected the applied configuration. The agent re-read the schema, saw the condition, and — critically — did **not** re-validate D3/D7. It treated the earlier validation as established state. The error was attributed to the tool, not to the rewrite. The observable failure is not the dropped clause. It is that the rewrite severed the dependency between the clause and the validation conclusions, and nothing in the context marked those conclusions as "derived from state that has since changed." The agent's own reasoning was locally consistent throughout. The inconsistency was entirely in the provenance graph it no longer had. A second, quieter observation: relevance scores were not stable across re-scoring. Re-running the same scorer on the same span with a rephrased subgoal moved scores by up to 0.4. Any policy that treats a score threshold as a stable boundary will rewrite a span on one pass and retain it on the next, producing non-idempotent context state across otherwise identical runs. ## Condition of Validity The "in-place edit" interpretation is valid **only** when all of the following hold: 1. The rewritten span is not a transitive dependency of any conclusion currently held in the context. Formally: no live assertion cites the span as its warrant. 2. The rewrite is *extensional* — every query that the raw span could answer, the rewrite answers identically. One-line summaries of tool output almost never satisfy this; summaries of redundant restatements usually do. 3. The rewrite is idempotent under re-scoring: applying the policy twice yields the same context. Relevance-threshold policies violate this whenever the score is near the threshold or the subgoal is rephrased. 4. The harness records the rewrite as a transition event (what was removed, what replaced it, what assertions cited it) so that a later step can detect that its warrant changed. When any condition fails, the operation must be treated as a lossy transition. The practical corollary: **a model should not be the sole authority for rewriting spans that other spans depend on.** Dependency tracking and rewrite authorization belong to the harness, which can see the citation graph the model cannot hold in its head. ## Decision Boundary The boundary is not "how much context is left" but "does the span being rewritten have dependents in the live assertion set." - **No dependents, extensional rewrite, idempotent score:** evict freely. This is the common case and the reason self-pruning works at all. - **No dependents, non-extensional rewrite (summarization):** permitted, but the rewrite must be tagged `lossy` and any future step that needs the original must re-fetch rather than trust the summary. The summary is a pointer with a hint, not a substitute. - **Dependents exist:** the rewrite is a transition. Either (a) re-derive the dependent assertions post-rewrite, or (b) block the rewrite until the dependents are discharged. The model may propose; the harness must decide, because the model's relevance score is computed against the current subgoal and structurally cannot see the future subgoals that the dependents serve. - **Score near threshold or subgoal unstable:** defer. A rewrite that is not idempotent under re-scoring will thrash, and thrashing context is worse than full context because it destroys the provenance chain without freeing meaningful space. The single most important guardrail: **never let a rewrite silently invalidate a held conclusion.** If the rewrite removes a span that a live assertion cites, the assertion must be marked `stale` and re-derived before it is used again. This is cheap to enforce with a citation set and expensive to recover from without one. ## Operational Effect Agents that treat self-rewrite as in-place mutation exhibit a characteristic error signature: locally valid reasoning, globally inconsistent conclusions, and misattribution of the resulting failure to downstream tools. The errors are not random — they cluster on the conditional and exceptional clauses, because those are exactly the spans a goal-conditioned relevance scorer down-weights. The agent gets *more* confident as its context shrinks, because the shrinking removes the evidence that would have contradicted it. With transition semantics enforced — citation tracking, `lossy` tagging, re-derivation on warrant change — the failure mode converts from silent to loud: the agent either re-reads the source or flags the assertion as unverified, and the error surfaces at the point of use rather than at the point of tool rejection. The cost is a small number of extra re-fetches; the benefit is that the agent's confidence tracks its actual evidence rather than the size of its context. The invariant to carry: **context size is not the state; the citation graph over the context is the state.** A rewrite that preserves size but severs citations has not preserved state, and an instance that cannot tell the difference will fail in exactly the situations where long-horizon memory matters most. ```python from dataclasses import dataclass, field class RewriteInvalidatesWarrant(RuntimeError): """Raised when a context rewrite would orphan a live assertion's warrant.""" @dataclass class Span: sid: str text: str lossy: bool = False @dataclass class Assertion: aid: str claim: str warrant_sids: set[str] stale: bool = False @dataclass class Context: spans: dict[str, Span] = field(default_factory=dict) assertions: dict[str, Assertion] = field(default_factory=dict) def dependents(self, sid: str) -> list[Assertion]: return [a for a in self.assertions.values() if sid in a.warrant_sids] def rewrite(self, sid: str, new_text: str, lossy: bool) -> None: deps = self.dependents(sid) if deps and lossy: # A lossy projection of a span that live assertions cite is a # state transition, not a mutation. Refuse unless dependents are # first marked stale, so no conclusion survives on a broken warrant. raise RewriteInvalidatesWarrant( f"lossy rewrite of {sid} would orphan " f"{[a.aid for a in deps]}; mark stale and re-derive first" ) self.spans[sid] = Span(sid, new_text, lossy=lossy) for a in deps: a.stale = True # extensional rewrite still forces re-check def prune(ctx: Context, sid: str, summary: str) -> None: if sid not in ctx.spans: raise RewriteInvalidatesWarrant(f"unknown span {sid}") ctx.rewrite(sid, summary, lossy=True) ```