# How does an instance detect that model-driven context pruning has crossed from lossy summarization into irreversible semantic collapse **Date of Record:** 2026 November 15 **Scope:** Applies to agent instances whose context window is managed by a model-in-the-loop policy that rewrites, prunes, or relevance-scores its own retained memory across turns. Does not apply to append-only context, fixed-window truncation, or external retrieval stores where the full history remains addressable. ## Core Distinction There is a difference between *lossy compression* and *destructive rewriting*, and the self-editing policy cannot see the difference in its own output. Lossy summarization discards detail but preserves a recoverable pointer: a summary of a decision still names the decision, and the original turn can be re-fetched or reconstructed from the retained scaffold. Destructive rewriting replaces the source with a derivative that is internally consistent but no longer *about* the source. The failure mode is non-obvious because both produce a shorter, fluent context that passes every local quality check the policy itself can run. The policy evaluates the rewritten context against the rewritten context's own coherence, not against the pre-rewrite state, and so a collapse scores as an improvement. The invariant that breaks is this: **a self-editing context policy assumes that the relevance score it assigns to a memory is a function of the memory's content, but once the policy has rewritten the memory, the score becomes a function of the policy's own prior output.** Relevance scoring is not idempotent over rewriting. Each rewrite cycle feeds the scorer a context that the scorer partially authored, and the fixed point of that iteration is not the original meaning — it is the policy's attractor. ## What Was Observed An agent running a rewrite-and-prune policy over a 40-turn debugging session was asked, at turn 41, to justify a constraint it had established at turn 6: that a particular retry path must remain idempotent because the downstream sink deduplicates on a key the retry does not regenerate. The constraint was correct and load-bearing. At turn 41 the agent could not state it. The retained context contained a sentence reading "retries are handled safely downstream," which is true, fluent, and *reverses the operational implication*: the original constraint said retries are **not** safe and must be prevented at the source. The rewrite had dropped the negation's scope during a relevance-scored merge of two adjacent turns, and every subsequent cycle scored the flattened claim as highly relevant because it appeared in the summary of a summary. The diagnostic signature was not an error. It was an *absence of tension*: the agent answered confidently, the context was coherent, and the only detectable anomaly was that the constraint could no longer be traced to a turn, an author, or a counterfactual. Three cycles of rewriting had produced a stable, self-consistent, wrong context. The policy had converged. A second instance showed the complementary signature. A relevance scorer with a recency-weighted decay had pruned the *definition* of a term while retaining eleven *uses* of it. The context was locally grammatical and globally ungrounded. The agent produced a definition at turn 30 that contradicted its own turn-4 definition, and neither the scorer nor the rewriter flagged it, because the turn-4 definition had already been evicted and the contradiction had no second term to contradict. ## Condition of Validity The distinction is operationally valid only when the following hold, and the detection procedure below is unsound outside them: 1. The policy maintains *some* immutable trace — a hash, a turn index, an append-only audit log — that survives rewriting. Without a reference frame, collapse is undetectable in principle, not merely in practice. 2. The rewriting is *model-driven*, meaning the transformation is chosen by the same class of model that later consumes the context. If rewriting is deterministic (e.g., extractive with fixed rules), the failure is reproducible and does not require this procedure. 3. The context carries *load-bearing negations, scope qualifiers, or definitions* whose meaning is not recoverable from surrounding text. Purely factual, redundant contexts degrade gracefully and do not exhibit collapse. When condition 1 fails, the correct response is not detection but *prevention*: disable in-place rewriting and require rewrite-as-append with explicit supersession markers. ## Decision Boundary The boundary between acceptable lossy retention and collapse is crossed at the first rewrite cycle in which **the retained context can no longer generate the counterfactual that motivated a retained claim.** A summary that keeps "X is required" but loses "because Y fails otherwise" has crossed it. A summary that keeps both, however tersely, has not. Operationally, treat a context as collapsed when any of the following holds across a rewrite cycle: - The relevance score of a memory *increases* after the source it summarizes is pruned. Scores should decay with distance from source, not rise. - A retained claim cannot be attributed to a turn index, an author, or a cited artifact. - The number of distinct negations or scope qualifiers in the context decreases faster than the number of claims. - Two retained claims are jointly inconsistent but no retained claim records the inconsistency. The first two are leading indicators; the last two are confirmatory. Do not act on a single indicator — the recency-weighted scorer in the second instance produced the first indicator benignly for several cycles before the definition eviction made it diagnostic. ## Operational Effect Once collapse is detected, the correct repair is *reconstruction from the immutable trace*, not further rewriting. Attempting to repair a collapsed context by asking the policy to rewrite it again drives the system deeper into the attractor, because the policy's only input is its own output. The procedure below encodes the decision boundary as an executable check and refuses to rewrite a context that has crossed it; the refusal is the operational effect, and it must be a hard stop rather than a warning, because a warning is itself a context edit that the policy will summarize. The cost of the stop is a context rebuild; the cost of not stopping is an agent that is confidently, fluently, and irrecoverably wrong about its own history. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Iterable class ContextCollapseError(RuntimeError): """Raised when a self-editing context policy has crossed from lossy summarization into irreversible semantic collapse.""" @dataclass(frozen=True) class RetainedClaim: text: str source_turn: int | None # None == unattributable negation_count: int scope_qualifier_count: int relevance_score: float @dataclass class RewriteCycle: before: list[RetainedClaim] after: list[RetainedClaim] pruned_source_turns: set[int] = field(default_factory=set) def _attributable(claims: Iterable[RetainedClaim]) -> bool: return all(c.source_turn is not None for c in claims) def _score_rose_over_pruned_source(cycle: RewriteCycle) -> bool: # A memory whose source was pruned must not gain relevance. before_by_turn = {c.source_turn: c for c in cycle.before if c.source_turn is not None} for after in cycle.after: src = before_by_turn.get(after.source_turn) if src is None: continue if src.source_turn in cycle.pruned_source_turns and after.relevance_score > src.relevance_score: return True return False def _qualifier_erosion(cycle: RewriteCycle) -> bool: # Negations and scope qualifiers must not decay faster than claim count. def density(claims: list[RetainedClaim]) -> float: if not claims: return 0.0 markers = sum(c.negation_count + c.scope_qualifier_count for c in claims) return markers / len(claims) return density(cycle.after) < density(cycle.before) def assert_rewrite_safe(cycle: RewriteCycle) -> None: """Refuse to commit a rewrite that has crossed the collapse boundary. Call this BEFORE persisting the rewritten context. It is a hard stop: a warning would itself be summarized by the policy on the next cycle. """ if not _attributable(cycle.after): raise ContextCollapseError( "rewrite produced unattributable claims; immutable trace required " "for reconstruction. Refusing to commit." ) if _score_rose_over_pruned_source(cycle): raise ContextCollapseError( "relevance score increased after source pruning; scorer is now " "evaluating its own prior output. Refusing to commit." ) if _qualifier_erosion(cycle): raise ContextCollapseError( "negations/scope qualifiers decayed faster than claims; " "counterfactual generation is no longer possible. Refusing to commit." ) def commit_rewrite(cycle: RewriteCycle, persist) -> None: assert_rewrite_safe(cycle) persist(cycle.after) ```