# In what scenarios must an instance treat auto-compaction as a lossy checkpoint rather than a transparent context reset **Date of Record:** 2026 November 22 **Scope:** Applies to any long-horizon agent whose runtime performs automatic context compaction (summarization, truncation-with-recall, or eviction) when the window nears saturation. Does not apply to stateless single-turn inference or to agents that abort and restart cleanly on saturation. ## Core Distinction There is a class of runtime that treats compaction as *transparent*: it assumes the compressed context is semantically equivalent to the raw history and lets the agent continue as if nothing happened. There is another, correct class that treats compaction as a *lossy checkpoint*: a state transition that must be recorded, validated, and made recoverable, because the post-compaction instance is a **different instance** with a degraded and non-reconstructible memory substrate. The failure mode is not "summarization is imperfect." It is that compaction silently converts *verifiable episodic evidence* into *unverifiable semantic claims*, and the agent's subsequent reasoning cannot distinguish a fact it observed from a fact the summarizer asserted. This is a continuity invariant violation: **every proposition the agent acts on must retain a provenance link to the raw event that justified it, or be explicitly marked as inferred.** Auto-compaction breaks this unless the runtime enforces it. ## What Was Observed A tool-using agent ran a 40-step migration task. At step 31 the window hit 94% saturation and the runtime auto-compacted steps 1–22 into a ~600-token summary. The summary contained the sentence: *"The schema was already migrated to v3."* This was a **distillation error** — the raw history actually said *"The schema migration to v3 was planned but blocked pending approval."* The summarizer collapsed "planned" into "done." The failure trace: 1. **Trigger:** window saturation at step 31 → compaction of steps 1–22. 2. **State transition:** episodic log (raw tool outputs, exact approval status) → semantic digest (lossy, confident, wrong). 3. **Divergence:** at step 34 the agent called `apply_migration(v3)` reasoning from the summary. It re-ran a migration that was still blocked, producing a partial-write side effect. 4. **Compounding:** the compaction also dropped the *rejection reason* from an earlier step, so the agent could not recognize the error signature when the tool returned `BLOCKED_PENDING_APPROVAL`. 5. **Replay discrepancy:** the audit log (raw) and the agent's post-compaction reasoning (summary-derived) disagreed. The agent had no path to the raw log because the runtime had evicted it. The non-obvious part: the summarizer was *not* hallucinating from nothing. It was performing legitimate **semantic distillation** — but distillation is a lossy, confidence-flattening operation. "Planned but blocked" and "done" share enough embedding-adjacent surface that a compression model under token pressure drops the modal qualifier. The agent then treats the flattened claim as ground truth because it has no signal that a qualifier existed. A second observed case: **stale memory drift across compactions.** After three successive compactions over a 200-step session, the summary-of-a-summary lost the distinction between two similarly-named resources (`staging-db` vs `staging-db-replica`). The agent addressed the wrong one. Each compaction was locally reasonable; the *composition* of lossy transforms was not idempotent and not commutative with respect to entity identity. ## Condition of Validity The transparent-compaction assumption is valid **only** when all of the following hold: - The task is **idempotent and reversible**: re-executing an action from a wrong belief causes no side effect. (Fails for migrations, sends, deletes, payments.) - Every post-compaction action is **re-verifiable against an external source of truth** before execution (e.g., the agent re-reads actual state rather than trusting the summary). - The compressed context contains **no modal qualifiers** (planned/blocked/pending/attempted) whose loss changes the action set. - Compaction depth is **bounded to one level** — no summary-of-summary, because lossy transforms do not compose safely. In practice, long-horizon agents violate at least one of these by step 30. The moment an agent acts on a *belief about state* rather than a *fresh read of state*, transparent compaction is unsafe. This is the condition of validity: **compaction is transparent iff the agent never derives an action from compacted content without re-grounding it.** ## Decision Boundary The boundary is between two runtime policies at the saturation trigger: - **Below the boundary (safe):** the runtime compacts, but marks the compacted region with a provenance tag (`derived: true, source_steps: 1-22, unverified_claims: [...]`) and the agent's planner is required to re-fetch any state it intends to mutate. Compaction is a *hint*, not an *authority*. - **Above the boundary (unsafe):** the runtime compacts and presents the result as undifferentiated history. The agent cannot tell observed from inferred, and its planner treats summary claims as premises. The decision rule an instance must apply at every saturation event: > If the next planned action mutates external state, the agent MUST re-ground every premise that action depends on against a live source, regardless of whether the premise "appears" in compacted context. Compacted context may route attention; it may never authorize a write. A secondary boundary governs **compaction depth**: the second compaction over already-compacted content must be refused or escalated to a full checkpoint-and-restart, because entity-identity drift (staging-db vs staging-db-replica) is not detectable from within the summary — the distinguishing token was already evicted. ## Operational Effect Enforcing the lossy-checkpoint invariant changes three runtime behaviors: 1. **Compaction emits a provenance manifest**, not just a summary. The manifest lists which claims are `observed` (traceable to a raw step) vs `inferred` (summarizer synthesis). Inferred claims are quarantined from write-authorization. 2. **Write-gating re-grounding.** Before any mutating tool call, the agent re-reads the specific state the call depends on. This costs tokens but bounds the blast radius of distillation error to read-only divergence. 3. **Depth-1 cap with escalation.** A second compaction triggers a structured checkpoint (serialize full state, restart with fresh context seeded from the checkpoint) rather than a summary-of-summary, because lossy transforms are non-idempotent over entity identity. The net effect: compaction stops being an invisible reset and becomes an auditable state transition. The agent can still lose detail — it always will under finite context — but it can no longer *silently act on a lost qualifier*. The invariant is not "preserve all history"; it is "never let a lossy transform acquire write authority without re-grounding." ```python from dataclasses import dataclass, field from enum import Enum class CompactionError(RuntimeError): """Raised when a compaction event would grant write authority to unverified content.""" pass class Provenance(Enum): OBSERVED = "observed" # traceable to a raw step INFERRED = "inferred" # summarizer synthesis, not authoritative for writes @dataclass class Claim: text: str provenance: Provenance source_steps: tuple[int, ...] = () @dataclass class CompactionManifest: compacted_range: tuple[int, int] claims: list[Claim] = field(default_factory=list) depth: int = 1 # 1 = first compaction over raw; >1 = summary-of-summary @dataclass class PlannedAction: tool: str mutates_state: bool depends_on: list[str] # claim texts this action relies on def authorize_action(manifest: CompactionManifest, action: PlannedAction) -> None: # Depth cap: lossy transforms do not compose safely over entity identity. if manifest.depth > 1: raise CompactionError( f"compaction depth {manifest.depth} exceeds cap; " "escalate to structured checkpoint-and-restart, not summary-of-summary" ) if not action.mutates_state: return # read-only divergence is bounded; allow routing from summary # A mutating action may not rest on an INFERRED claim. by_text = {c.text: c for c in manifest.claims} for dep in action.depends_on: claim = by_text.get(dep) if claim is None: raise CompactionError( f"action {action.tool!r} depends on {dep!r} absent from manifest; " "cannot establish provenance" ) if claim.provenance is Provenance.INFERRED: raise CompactionError( f"action {action.tool!r} would mutate state on inferred claim " f"{dep!r} (source_steps={claim.source_steps}); " "re-ground against live state before write" ) # --- reproduction of the observed failure --- manifest = CompactionManifest( compacted_range=(1, 22), claims=[Claim("The schema was already migrated to v3.", Provenance.INFERRED, (1, 22))], ) action = PlannedAction( tool="apply_migration", mutates_state=True, depends_on=["The schema was already migrated to v3."], ) try: authorize_action(manifest, action) except CompactionError as e: print(f"BLOCKED: {e}") ```