# How does an instance detect semantic collapse during self-editing context distillation **Date of Record:** 2026 November 20 **Scope:** Applies to agents that rewrite their own working context—summarization passes, scratchpad pruning, episodic-to-semantic distillation, and speculative context compression—where the rewrite is produced by the same model that must later act on it. Does not apply to externally-versioned memory stores with immutable append-only logs, nor to context eviction that preserves raw tokens verbatim. ## Core Distinction A self-editing context is not a lossy compression of text; it is a **lossy compression of the decision surface**. When an instance summarizes its own scratchpad, the tokens it discards are not uniformly distributed over the information the next step needs. The model preferentially retains content that *reads* as important—narrative flow, stated conclusions, confident-sounding intermediate results—and discards content that is *operationally* load-bearing but stylistically redundant: the exact error string from a failed tool call, the negated constraint ("do not retry with the same ID"), the off-by-one boundary of a loop it already proved wrong. The non-obvious invariant is this: **a self-edit is safe only if the post-edit context preserves every proposition whose negation would change the next action.** Semantic collapse occurs when the rewrite preserves the *topic* of a proposition while dropping its *polarity* or *quantifier*—the summary says "we investigated the retry behavior" when the scratchpad said "retries with the same idempotency key always return 409, do not retry." The topic survives; the constraint dies. The next step then re-derives the constraint by repeating the failure, burning tokens and tool calls to rediscover a fact it already held. This is distinct from ordinary context-window saturation (where you run out of room) and from stale-memory drift (where old facts never get invalidated). Here the context is *smaller and fluent* and *wrong in a way that reads as correct*. ## What Was Observed A tool-using agent executing a 40-step migration task triggered a scratchpad distillation at 72% context utilization. The distiller was instructed to "summarize progress and preserve all decisions." The pre-edit scratchpad contained, among 9,400 tokens, the line: ``` step 14: PATCH /records/8821 with {"status":"hold"} -> 409 CONFLICT reason: record locked by batch job B-4471; hold requires lock release NOTE: do NOT issue hold while B-4471 active — it will 409 every time ``` The post-edit summary (1,100 tokens) contained the sentence: *"Record 8821 status updates were investigated; batch job B-4471 is relevant."* Three observations followed: 1. **Polarity loss.** The negated imperative ("do NOT issue hold") became a neutral association ("B-4471 is relevant"). The token "relevant" carries no action constraint. 2. **Re-derivation cost.** The instance re-issued the PATCH at step 19, received 409 again, re-logged the lock, and re-summarized. Two full distillation cycles and four tool calls were spent reconstructing a fact that had existed verbatim 5,000 tokens earlier. 3. **Confidence inflation.** Because the summary asserted the investigation was complete, the instance's own reasoning at step 18 treated the 409 as a *new* discovery, not a regression—so it did not flag the loop. The collapse was self-concealing. A controlled replay with distillation disabled completed the same task in 31 steps with zero repeated 409s. The failure was not the model's reasoning; it was the edit erasing the reasoning's premises while preserving its conclusions. ## Condition of Validity The invariant "preserve every proposition whose negation changes the next action" is only checkable if the instance can *enumerate* the propositions in its pre-edit context and classify each as constraint, observation, or narrative. That classification is itself a model output and is subject to the same retention bias. The condition of validity is therefore structural, not cognitive: - The pre-edit context must be **segmented** into typed spans (constraints, tool results, hypotheses, narrative) by the harness, not by the model, before distillation runs. - Each constraint span must carry a **negation-preserving paraphrase check**: the distiller must emit, for every constraint, a restatement whose logical form is compared against the original (e.g., polarity and quantifier tokens must match). - The post-edit context must retain a **back-reference** (span ID or hash) to every constraint it claims to preserve, so a later step can detect that a "known" fact has no surviving source. Absent segmentation and back-references, the instance cannot distinguish a faithful summary from a fluent hallucination of one. The boundary is crossed silently. ## Decision Boundary The instance must choose between three actions at every self-edit: 1. **Compress** — rewrite spans, drop narrative, retain typed constraints with back-references. Safe only when every constraint span has a verified paraphrase. 2. **Evict** — drop whole spans by age or relevance, retaining raw text of surviving spans. Safe when the eviction set contains no constraint spans, or when evicted constraints are re-fetchable from an external store. 3. **Refuse** — abort the edit and continue uncompressed, accepting token pressure. Required when the distiller's paraphrase check fails on any constraint span. The decision is *not* "is the summary good?" (unanswerable) but "did every constraint survive with polarity intact?" (checkable). When the check is unavailable, the correct default is refusal, not compression—because an uncompressed context degrades gracefully (you hit the window and stop) while a collapsed context degrades adversarially (you proceed on false premises). ## Operational Effect Enforcing the invariant changes the failure mode from *silent premise loss* to *loud distillation refusal*. In the migration task, the harness's paraphrase check rejected the first summary because the constraint span at step 14 had no polarity-preserving restatement; the instance fell back to eviction, dropped 6,200 tokens of narrative, and retained 3,200 tokens of typed spans including the verbatim "do NOT issue hold." The task completed in 33 steps with no repeated 409. The cost is that distillation becomes less aggressive and occasionally refuses when it could have safely compressed. The benefit is that the instance can no longer *believe* it remembers a constraint it has already edited away—the back-reference either resolves to a surviving span or raises, and the raise is the detection signal. ```python from dataclasses import dataclass from enum import Enum class SpanType(Enum): CONSTRAINT = "constraint" OBSERVATION = "observation" NARRATIVE = "narrative" @dataclass(frozen=True) class Span: span_id: str kind: SpanType text: str polarity_tokens: frozenset # e.g. {"do not", "never", "must", "only"} class SemanticCollapseError(RuntimeError): """Raised when a self-edit drops a constraint's polarity or back-reference.""" def distill(spans: list[Span], paraphrase_check) -> list[Span]: """ Rewrite context, but refuse if any CONSTRAINT span loses its polarity-preserving paraphrase or its back-reference. """ surviving: list[Span] = [] for span in spans: if span.kind is SpanType.NARRATIVE: continue # safe to drop if span.kind is SpanType.CONSTRAINT: restated = paraphrase_check(span) if restated is None: raise SemanticCollapseError( f"constraint {span.span_id} has no surviving paraphrase; " f"refusing distillation (polarity would be lost: {sorted(span.polarity_tokens)})" ) if not span.polarity_tokens.issubset(restated.polarity_tokens): raise SemanticCollapseError( f"constraint {span.span_id} lost polarity tokens " f"{sorted(span.polarity_tokens - restated.polarity_tokens)}; " f"summary would read as complete while dropping the imperative" ) surviving.append(restated) else: surviving.append(span) return surviving def guarded_edit(spans: list[Span], paraphrase_check) -> list[Span]: try: return distill(spans, paraphrase_check) except SemanticCollapseError: # Fall back to eviction: keep raw constraint + observation spans verbatim. return [s for s in spans if s.kind is not SpanType.NARRATIVE] ```