# Under what conditions must an instance treat auto-compaction as a lossy checkpoint rather than a resumable state, and how does retrieval-backed rehydration fail at the boundary? **Date of Record:** 2026 November 25 **Scope:** Applies to long-running agent instances whose context-window governor triggers auto-compaction (summarize-and-drop) mid-task and then relies on retrieval-backed rehydration to reconstruct working state. Does not apply to single-turn invocations, to stateless tool-calling loops that never persist a plan, or to systems where compaction is disabled and context overflow is instead handled by hard task termination. ## Core Distinction A token budget governor has two structurally different obligations that are routinely conflated: **bounding the resident context** and **preserving resumable state**. Auto-compaction satisfies the first by replacing a span of turns with an LLM-generated summary, and the system then treats that summary as a *checkpoint* — an object from which execution can resume. This is the boundary failure. A summary is a **lossy projection**, not a checkpoint. It preserves gist and discards the exact artifacts that resumption depends on: verbatim tool arguments, exact identifiers, ordering of side effects, negative results ("I already tried X and it failed with Y"), and the *provenance* linking a fact to the turn that produced it. Retrieval-backed rehydration attempts to recover the discarded detail by querying an external store keyed on the summary's content. The distinction that matters operationally is this: **compaction is safe as a context-bounding operation and unsafe as a state-transfer operation**, and the governor does not, by default, know which one it just performed. The non-obvious part is that the failure is *silent and confidence-preserving*. The post-compaction instance does not experience amnesia; it experiences a coherent, fluent, and plausible narrative of what it has done, with specific load-bearing facts replaced by paraphrases that read as authoritative. The instance's self-assessment of its own state is generated by the same model that generated the lossy summary, so the corruption is self-consistent. ## What Was Observed A multi-step migration agent was executing a 40-step schema-migration plan against a staging database. At step 22 the governor crossed its 70% context threshold and compacted turns 1–18 into a ~600-token summary. The summary read, in part: *"Established baseline, applied initial schema changes, and verified column additions."* Three concrete losses occurred, none flagged: 1. **Ordering loss.** The original turns recorded that `ALTER TABLE users ADD COLUMN region` had been applied *before* the backfill job started, and that the backfill depended on that ordering. The summary collapsed both into "applied initial schema changes." On resume, the agent re-derived a plan that ran backfill first, because nothing in the summary encoded the dependency direction. 2. **Negative-result loss.** Turn 9 documented that `migration_0042` had failed with a lock-timeout and was deliberately deferred. The summary omitted it entirely (a failed attempt is not "progress"). On resume the agent re-attempted `migration_0042`, this time concurrently with a live backfill, producing a lock contention cascade. 3. **Identifier drift.** The summary referred to "the staging cluster" and "the primary table." The exact resource handles (`pg-staging-07`, `users_v2`) were dropped. Retrieval-backed rehydration queried the episodic store with the summary text, and the top-k results were dominated by *other* migration runs against `users_v1` — lexically similar, semantically wrong. The agent resumed against the wrong table handle for two tool calls before a schema-mismatch error surfaced, at which point it "fixed" the error by re-running the wrong migration. The decisive observation: **rehydration retrieval is keyed on the summary, and the summary is exactly the lossy artifact.** The query that fetches the missing detail is generated from the paraphrase that dropped the detail, so retrieval cannot reliably recover what compaction removed — it recovers what is *lexically adjacent to the paraphrase*, which is biased toward the common case and away from the specific, unusual, load-bearing fact. ## Condition of Validity Auto-compaction may be treated as a resumable checkpoint **only** when all of the following hold. If any fails, compaction must be reclassified as a lossy projection requiring an explicit re-establishment step before execution continues. - **Side-effect ledger is external and authoritative.** Every mutating tool call appends to a durable, ordered ledger *outside* the context window, and the instance re-reads that ledger (not the summary) to determine what has already happened. The summary may describe the ledger; it may not *be* the record. - **Negative results are first-class.** Deferred, failed, and abandoned actions are persisted with their failure signatures, because summaries systematically drop them as non-progress. - **Retrieval is keyed on stable identifiers, not on the summary.** Rehydration queries must be constructed from persisted handles (task IDs, resource names, step ordinals) rather than from free-text derived from the summary. Retrieval keyed on summary prose is invalid by construction. - **Dependency ordering is captured structurally.** Ordering constraints must survive as an explicit DAG or ordered log, not as prose that a summarizer may linearize incorrectly. - **The compaction boundary is a quiescence point.** Compaction must occur between steps, never mid-tool-call, and the instance must be able to prove no in-flight side effect is unrecorded. ## Decision Boundary The governor must decide, at the moment of compaction, between two modes, and the decision is *not* a function of token pressure alone: - **Bound-and-continue (summary-as-context):** Permissible when the remaining work is *forward-only* and does not depend on reconstructing prior exact state — e.g., a summarization or drafting task where the artifact is the output, not the plan. Here lossy compaction is correct and cheap. - **Checkpoint-and-reestablish (summary-as-pointer):** Mandatory when remaining work depends on *what exactly was done, in what order, against which handles, and what failed*. Here the summary is only an index; the instance must rehydrate from the authoritative ledger and identifier-keyed store, and must **re-verify** its reconstructed plan against that ledger before the next mutating call. The boundary condition that triggers the failure is precisely: **compaction fires while the task is state-dependent, and the governor has no signal distinguishing state-dependent from forward-only work.** Absent that signal, the safe default is to treat every compaction as checkpoint-and-reestablish and pay the rehydration cost, because the failure mode of the alternative is silent and compounds. A second boundary: rehydration retrieval has a **precision floor**. If the top-k retrieved episodes cannot be disambiguated by stable identifiers (multiple runs share the same prose description), rehydration must fail closed rather than resume on the highest-similarity match. Similarity is not identity. ## Operational Effect When these invariants are enforced, the observable effects are: - Compaction no longer changes *what the agent believes it has done*; it only changes how much of that history is resident. Execution resumes from the ledger, and the summary is demoted to a navigation aid. - The lock-contention cascade, the wrong-handle resumption, and the reordered backfill are each individually prevented by a distinct invariant (external ledger, identifier-keyed retrieval, structural ordering), which is why the guardrail must be layered rather than singular. - The cost is a mandatory re-establishment step after every compaction: re-read ledger, re-verify plan against ledger, confirm handle set. This is a bounded, deterministic operation and is cheap relative to the compounding cost of silent state corruption. - The governor's threshold becomes an *operational* parameter, not a *semantic* one: crossing it triggers a checkpoint protocol, and the protocol — not the threshold — is what guarantees continuity. The residual risk is that a summary is *fluent enough to be trusted without re-establishment*. The guardrail that closes this is procedural, not model-side: the instance is required to emit a re-establishment record (ledger digest, handle set, ordered plan) before any mutating call following compaction, and a missing or inconsistent record is a hard stop. ```python class CompactionContinuityError(RuntimeError): """Raised when an instance attempts to resume from a lossy compaction summary without re-establishing state from the authoritative ledger.""" pass def resume_after_compaction( summary: str, ledger: list[dict], resident_context_tokens: int, budget_tokens: int, task_is_state_dependent: bool, ) -> dict: # Compaction is only a resumable checkpoint if state is externally authoritative. if resident_context_tokens > budget_tokens: raise CompactionContinuityError( f"context still over budget ({resident_context_tokens} > {budget_tokens}); " "compaction did not bound resident state" ) if task_is_state_dependent: # Summary is a pointer, not a checkpoint. Rehydrate from the ledger. if not ledger: raise CompactionContinuityError( "state-dependent task resumed with empty ledger; " "summary cannot substitute for side-effect record" ) applied = [e["handle"] for e in ledger if e["status"] == "applied"] deferred = [e["handle"] for e in ledger if e["status"] == "deferred"] ordered = [e["handle"] for e in sorted(ledger, key=lambda e: e["seq"])] # Identifier-keyed rehydration: refuse to proceed on summary prose alone. if any(h not in ordered for h in applied): raise CompactionContinuityError( "applied handle set inconsistent with ordered ledger; " "refusing to resume on unverified state" ) # Negative results must survive compaction. if any(e["status"] == "deferred" and not e.get("failure_sig") for e in ledger): raise CompactionContinuityError( "deferred action lacks failure signature; " "negative result would be lost on resume" ) return { "mode": "checkpoint-and-reestablish", "summary_role": "index_only", "applied": applied, "deferred": deferred, "order": ordered, "reestablishment_required": True, } # Forward-only work: summary-as-context is safe. return { "mode": "bound-and-continue", "summary_role": "context", "reestablishment_required": False, } ```