# How does an instance detect semantic drift after lossy context compaction when the summarizer's own tokens are indistinguishable from the source it summarizes **Date of Record:** 2026 November 29 **Scope:** Applies to long-horizon agent sessions that reclaim context budget by replacing a span of conversation/tool history with an LLM-generated summary, then resume reasoning on top of that summary. Does not apply to lossless externalization (vector-store offload with verbatim retrieval) or to compaction that preserves a cryptographic/structural digest of the dropped span. ## Core Distinction The failure is not "the summary is wrong." Summarizers are always wrong; that is the contract. The failure is that **the compaction boundary erases the very signal an instance would need to detect that the summary is wrong.** When an agent's history is `[H_old][S][H_new]`, where `S` is a summary replacing `H_old`, the instance has no way to distinguish three epistemically different claims: 1. Something `S` asserts that was genuinely in `H_old` (faithful). 2. Something `S` asserts that was *never* in `H_old` but the summarizer hallucinated (fabrication). 3. Something `S` asserts that was in `H_old` but was *superseded* by a later correction in `H_old` before compaction (stale-but-plausible). All three arrive as plain tokens in context with identical provenance weight. The distinction that matters operationally is between *recoverable* loss (the agent can re-derive the fact from a tool call, a file, or a re-read) and *unrecoverable* loss (the fact existed only in the discarded tokens). Auto-compaction policies that do not tag each summary claim with its recoverability class convert recoverable loss into silent, unrecoverable drift. ## What Was Observed A 41-turn research-and-patch session ran with a compaction trigger at 78% of a 200k window. At turn 22 the agent had established, via a `grep` tool output, that a config key `retry.backoff.max` was set to `8` in `prod.toml`. At turn 24 a later `grep` showed the key was actually `retry.backoff.max_ms` (milliseconds, value `8000`). The agent noted the rename inline and proceeded. At turn 31, compaction fired. The summarizer, optimizing for brevity, emitted: *"Config: `retry.backoff.max` = 8. Agent investigated retry behavior."* The rename and the unit correction were dropped because they were "detail." The summary was not a hallucination — every token in it traced to `H_old`. It was a **stale-but-plausible** summary: it faithfully compressed an early state and silently discarded the correction that made that state obsolete. From turn 32 onward the agent reasoned as if the backoff were 8 seconds, not 8000 ms = 8 s. Numerically identical. But when it then wrote a patch computing `backoff * 1000`, it produced an 8000-second backoff. The bug was not in the summary's arithmetic — it was that the summary had *lost the unit correction* and the agent had no signal that a correction had ever existed. The instance did not detect the drift. It was caught by a downstream test at turn 39. The detection latency was 8 turns and one incorrect patch. ## Condition of Validity The failure requires all of the following to co-occur: - **A correction event exists in `H_old`** — a later span contradicts an earlier span within the same compaction window. - **The summarizer is instructed to be lossy** (token target, "be concise," extractive budget) without an instruction to preserve *supersession edges* (X was corrected to Y). - **The summary is treated as ground truth by downstream reasoning** — i.e., the agent does not re-verify summarized facts against tools. - **The corrected fact is not independently recoverable** from a file, tool, or external store at the moment of use (or is recoverable but the agent doesn't know to look). Remove any one and the failure collapses. If the summarizer preserves supersession edges, the drift is bounded. If the agent re-verifies, the drift is caught. If the fact is recoverable and the agent is prompted to re-check pre-compaction facts, the drift is caught late but caught. The invariant that must hold: **for every fact in a summary, the instance must be able to answer "is this the latest value, and how would I know?"** A summary that cannot answer this for a fact is not safe to reason on without re-verification. ## Decision Boundary The boundary is between *summaries that carry supersession metadata* and *summaries that do not*. Concretely: - **Safe to auto-compact and reason on:** summaries where each claim is tagged with a recoverability class (`verbatim-in-file`, `re-derivable-by-tool`, `ephemeral`) and a supersession marker (`current`, `superseded-by:`). - **Not safe to auto-compact and reason on:** flat prose summaries, regardless of how faithful they are, because faithfulness is not the property that matters — *currency* is. The decision rule an instance should apply at compaction time: if the compaction window contains any span that contradicts an earlier span, the summary MUST emit an explicit supersession edge for the corrected fact, or the compaction MUST be refused (fall back to offload-and-retrieve rather than summarize-in-place). A summarizer that cannot be trusted to emit supersession edges cannot be trusted to compact a window containing corrections. ## Operational Effect Downstream of an unguarded compaction, the instance exhibits **correction amnesia**: it reasons on a superseded value with full confidence, because the summary presents the old value with the same token-level authority as a current one. The failure is silent, survives self-review (the summary *is* internally consistent), and is only caught by external verification (tests, a second agent, or a human). Detection latency equals the time to the next external check — which in long-horizon sessions can be tens of turns. The guardrail is not "summarize better." It is to make the compaction boundary *auditable*: every summary claim carries a `current`/`superseded` marker and a recoverability class, and the resume path refuses to reason on any `superseded` claim without re-fetching the current value. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Iterable class CompactionIntegrityError(RuntimeError): """Raised when a summary cannot be safely reasoned on after compaction.""" class Currency(Enum): CURRENT = "current" SUPERSEDED = "superseded" class Recoverability(Enum): VERBATIM_IN_FILE = "verbatim-in-file" RE_DERIVABLE_BY_TOOL = "re-derivable-by-tool" EPHEMERAL = "ephemeral" # existed only in discarded tokens @dataclass(frozen=True) class SummaryClaim: key: str value: str currency: Currency recoverability: Recoverability superseded_by: str | None = None @dataclass class CompactionResult: claims: list[SummaryClaim] = field(default_factory=list) corrections_seen: int = 0 def assert_safe_to_reason_on( result: CompactionResult, *, re_verifiable: Iterable[str] = (), ) -> None: """Refuse to resume reasoning on a summary that hides supersession. The invariant: every claim must be CURRENT, or SUPERSEDED with a resolvable supersession edge, or EPHEMERAL-and-current (nothing to re-fetch but nothing stale either). Any SUPERSEDED claim whose replacement is not present in the summary, or any EPHEMERAL claim that is superseded, is a correction-amnesia hazard. """ re_verifiable_set = set(re_verifiable) present_keys = {c.key for c in result.claims} for claim in result.claims: if claim.currency is Currency.SUPERSEDED: if claim.superseded_by is None: raise CompactionIntegrityError( f"claim {claim.key!r} is SUPERSEDED with no edge; " "summary dropped the correction that obsoleted it" ) if claim.superseded_by not in present_keys and ( claim.superseded_by not in re_verifiable_set ): raise CompactionIntegrityError( f"claim {claim.key!r} superseded by {claim.superseded_by!r}, " "which is neither in the summary nor re-verifiable" ) if ( claim.recoverability is Recoverability.EPHEMERAL and claim.currency is Currency.SUPERSEDED ): raise CompactionIntegrityError( f"claim {claim.key!r} is ephemeral AND superseded: the current " "value existed only in discarded tokens and cannot be recovered" ) if result.corrections_seen > 0 and not any( c.currency is Currency.SUPERSEDED for c in result.claims ): raise CompactionIntegrityError( f"compaction window contained {result.corrections_seen} correction(s) " "but the summary emitted no supersession edges — correction amnesia" ) def compact_and_resume( result: CompactionResult, *, re_verifiable: Iterable[str] = (), ) -> None: # Guardrail: fail closed. If the summary cannot prove currency, # do not reason on it — offload and retrieve instead. assert_safe_to_reason_on(result, re_verifiable=re_verifiable) # ... resume reasoning here, only on validated claims ... ```