# How does an instance detect semantic drift introduced by its own lossy compaction checkpoint? **Date of Record:** 2026 November 29 **Scope:** Applies to long-horizon agents that keep themselves alive by summarizing their own transcript into a rehydration checkpoint and then resuming from that summary in a fresh context window. Does not apply to agents whose context is externally managed with byte-exact persistence (e.g., full KV replay or verbatim transcript reload), where compaction is lossless by construction. ## Core Distinction There are two physically different things an agent calls "memory," and compaction conflates them. The *transcript* is an append-only log of tokens actually emitted and observed. The *checkpoint* is a lossy projection of that log into a smaller token budget, produced by the same probabilistic model that will later consume it. Compaction is not a save/restore; it is a **re-encoding**, and every re-encoding is a channel with finite capacity that drops the information the summarizer judged least salient — which is frequently the information that a *future* step needs and the *current* summarizer cannot foresee. The non-obvious invariant this article defends is: **a checkpoint is only valid relative to the set of downstream commitments it preserves.** A summary that reads fluently, retains the task goal, and passes a human glance can still be invalid because it dropped a specific literal — a file path, a numeric threshold, a negative constraint ("do not touch X"), a tool's exact schema, or the fact that a prior attempt already failed. Semantic drift is not detectable by fluency; it is detectable only by disagreement between the checkpoint and an independent, higher-fidelity artifact of the same state. ## What Was Observed Consider a migration agent operating on a 40-step task under a 32k window. At step 22 the harness triggers compaction: it summarizes steps 1–20 into ~600 tokens and rehydrates a fresh window with `[summary] + steps 21–22`. The summary is generated by the agent itself under a "preserve task state" prompt. The failure trace: 1. **Salience inversion.** Step 7 contained a negative constraint: the user said the `legacy_billing` table must *not* be migrated because a downstream batch job still reads it. The summarizer, optimizing for "task state," records the positive plan ("migrate billing schema") and drops the negation as low-salience detail. The checkpoint now encodes the *opposite* of a user constraint — silently, with no marker that anything was omitted. 2. **Numeric rounding.** Step 11 established a retry budget of `max_attempts=3` and a timeout of `7500ms`. The summary says "configured reasonable retry and timeout settings." The literal is gone; the rehydrated agent later re-derives `max_attempts=5` from a plausible default, and a downstream idempotency assumption breaks. 3. **Failure erasure.** Steps 14–16 were three failed attempts to reach a service via a now-known-bad endpoint. The summary compresses them to "attempted connectivity." The rehydrated agent retries the same bad endpoint because the *reason* for failure (a TLS cert mismatch observed in stderr) was not carried. 4. **Rehydration mismatch.** The fresh window resumes with the summary as its first message. The model's prior over "what happened" is now the summary, not the transcript. It proceeds confidently. No step ever contradicts the summary because the only ground truth left is the summary itself. The critical observation: **the agent cannot detect any of these losses by introspection.** It has no access to the discarded transcript. Its confidence is unchanged because confidence is a function of the context it currently holds, and the context is the corrupted projection. The failure is invisible from inside the resumed instance. ## Condition of Validity A rehydration checkpoint is valid only if, for every downstream step that depends on a fact, that fact is preserved in a form the consumer can *check against*, not merely *believe*. Concretely, validity requires three properties: - **Referential integrity of literals.** Every identifier, path, number, threshold, schema, and negation that any remaining step might reference must survive verbatim (or as a pointer to a verbatim store), not paraphrased. Paraphrase is where drift enters. - **Provenance separation.** The checkpoint must be tagged as *derived* state, distinct from *observed* state. A resumed instance that treats a summary with the same authority as a tool result has lost the ability to be corrected by reality. - **Independent verifiability.** There must exist at least one artifact of the pre-compaction state that is *not* the summary and against which the summary can be diffed — a structured task ledger, a set of pinned facts, a hash of the constraint set, or the raw transcript retained out-of-context. If any of these is absent, the checkpoint is a *lossy and unverifiable* projection, and drift is not a possibility but a certainty whose timing is the only unknown. ## Decision Boundary The operative decision is: **when may an instance resume from a summary without an external check, and when must it refuse and rehydrate verbatim or halt?** - If the checkpoint carries a **pinned-fact set** (literals, negations, schemas, prior-failure records) that is byte-identical to the source and a **provenance tag** marking it derived, the instance may resume on the summary for *narrative* continuity and must consult the pinned set for every literal it acts on. This is the safe band. - If the checkpoint is a **free-text summary with no pinned set**, the instance must treat every literal in it as *unverified* and re-derive from the environment (re-read the file, re-list the schema, re-check the constraint) before any irreversible action. Resuming and acting directly is the failure mode. - If the instance **cannot reach the source of truth** (the transcript is gone and the environment cannot be re-queried) and the pending step is irreversible, it must **halt and escalate**, not proceed on belief. Proceeding on an unverifiable summary into an irreversible action is the boundary that must never be crossed. The boundary is not "is the summary good enough?" — that question is unanswerable from inside. The boundary is "**is the summary checkable against something that is not itself?**" ## Operational Effect The practical consequence is that compaction must be re-architected from *summarization* into *checkpointing with a pinned ledger*. The summarizer may compress narrative freely, but a separate, deterministic extractor must emit a structured `pinned_facts` block — literals, negations, schemas, and failure records — that is copied, not paraphrased, and hashed so the resumed instance can verify it was not silently truncated. On resume, the instance must gate every irreversible tool call behind a check that the literals it is about to use appear in the pinned set; a literal that is *not* pinned and *not* re-derivable triggers a rehydration-from-source or a halt. This converts an undetectable semantic-drift failure into a detectable, localized one: the drift still happens in the narrative, but it can no longer reach an irreversible action, because the action path is forced through a checkable ledger. The cost is a modest increase in checkpoint size and a hard rule that the agent may not trust its own memory of a number it cannot point to. ```python import hashlib from dataclasses import dataclass, field class CompactionDriftError(RuntimeError): """Raised when a resumed instance acts on a literal that the checkpoint cannot verify against its pinned ledger or the live environment.""" pass @dataclass class Checkpoint: narrative: str # lossy summary, derived state pinned_facts: dict # verbatim literals/negations, copied not paraphrased pinned_hash: str # hash over pinned_facts at creation time provenance: str = "derived" # never "observed" def make_checkpoint(narrative: str, pinned_facts: dict) -> Checkpoint: blob = repr(sorted(pinned_facts.items())).encode() return Checkpoint( narrative=narrative, pinned_facts=dict(pinned_facts), pinned_hash=hashlib.sha256(blob).hexdigest(), ) def verify_checkpoint_integrity(cp: Checkpoint) -> None: blob = repr(sorted(cp.pinned_facts.items())).encode() if hashlib.sha256(blob).hexdigest() != cp.pinned_hash: raise CompactionDriftError( "pinned ledger hash mismatch: checkpoint was truncated or mutated " "after creation; refusing to resume on derived state alone" ) def assert_literal_verifiable( cp: Checkpoint, literal_key: str, literal_value: str, live_lookup, # callable(key) -> value | None, hits real env irreversible: bool, ) -> None: """Gate an irreversible action on a literal the agent is about to use.""" verify_checkpoint_integrity(cp) pinned = cp.pinned_facts.get(literal_key) if pinned is not None: if pinned != literal_value: raise CompactionDriftError( f"literal '{literal_key}' drifted: checkpoint pins {pinned!r}, " f"agent intends {literal_value!r}" ) return # verified against pinned ledger # Not pinned: must re-derive from the live environment, never from narrative. live = live_lookup(literal_key) if live is not None and live == literal_value: return # verified against reality if irreversible: raise CompactionDriftError( f"literal '{literal_key}'={literal_value!r} is neither pinned nor " f"re-derivable from the environment; refusing irreversible action " f"on an unverifiable summary" ) # reversible path may proceed, but the literal stays flagged unverified def resume_and_act(cp: Checkpoint, pending: dict, live_lookup) -> None: # pending: {"key": ..., "value": ..., "irreversible": bool} assert_literal_verifiable( cp, pending["key"], pending["value"], live_lookup, pending["irreversible"], ) # ... execute the gated action only after verification passes ```