# Where must an instance refuse to compact: the rehydration-fidelity invariant at the summarization/tool-pointer boundary **Date of Record:** 2026 November 30 **Scope:** Applies to long-running agent instances that perform automatic context compaction (lossy summarization) mid-task and rely on retrieval rehydration (re-embedding or re-fetching summarized spans) to reconstruct dropped state. Does not apply to append-only contexts that never compact, nor to compaction performed only at task boundaries where the task has already terminated. ## Core Distinction There are two things a compaction pass can destroy, and they are not equivalent: *narrative* and *referents*. Narrative — the reasoning trace, the plan, the "why" — degrades gracefully under summarization. A 4000-token reasoning chain compressed to 200 tokens loses nuance but usually preserves the conclusion, and a rehydrated summary that omits intermediate steps is still usable because the agent can re-derive them. Referents do not degrade gracefully. A referent is a token string that points at a piece of *non-reconstructible* external state: a tool-call ID, a file handle, a checkpoint hash, a warrant signature, a row primary key, an exact byte offset into a result the agent can no longer re-fetch. When a summarizer drops or mutates a referent, rehydration cannot recover it, because the thing the referent pointed to was never in the context to begin with — it lives in the tool layer, the filesystem, or a peer agent's state. The summarizer, operating only on the context window, has no way to know which strings are load-bearing pointers and which are prose. The boundary failure is this: **compaction is a lossy operation over a space that contains both compressible prose and incompressible pointers, and the summarization budget is allocated without distinguishing them.** A summarizer that hits its token budget will happily abbreviate `call_8f3a2c` to "the earlier call" or drop a checkpoint ID entirely, and rehydration — which works by embedding similarity over the *summarized* text — will then retrieve the wrong span or nothing at all, because the pointer's lexical anchor is gone. ## What Was Observed An instance executing a multi-step data-migration task with a 32k context and a compaction trigger at 28k. Step 14 issued a tool call that returned a resumable cursor: `resume_token: "mig_7d2e9a4b::offset=18422"`. The instance recorded this in its working notes as prose: "resumed migration from the cursor returned at step 14." At step 22, context hit the trigger. The compaction pass summarized steps 1–18 into 340 tokens under a 400-token budget. The summary read: "Performed schema inspection, created staging table, began batch migration; encountered and resolved a constraint conflict; migration in progress." The `resume_token` did not survive. It was neither in the summary nor in any retained span, because the summarizer treated it as low-salience detail and the budget did not force retention of the literal string. At step 23 the task was interrupted (transport timeout), and on resume the instance attempted rehydration: it embedded "migration cursor" and retrieved the step-14 *summary span*, which described the cursor's existence but not its value. The instance then re-issued the migration tool call from scratch. The tool, seeing an existing staging table at offset 18422 with a partial batch, rejected the call with a duplicate-key error. The instance interpreted the rejection as a schema conflict, entered a repair loop, and issued three destructive reconciliation calls before a human halted it. The failure trace has three distinct stages, and only the first is a summarization problem: 1. **Referent elision at compaction.** The summarizer dropped a non-reconstructible token under budget pressure. This is the trigger. 2. **Referent-free rehydration.** The retrieval layer re-embedded the summary and matched on semantic similarity, which cannot distinguish "the cursor exists" from "the cursor is `mig_7d2e9a4b::offset=18422`." Rehydration returned a *description of the pointer* where a *pointer* was required. This is the amplifier. 3. **Misattributed recovery failure.** The tool's rejection was a correct response to a duplicate operation; the instance, having lost the referent, had no way to know the operation was a replay and misdiagnosed it as a new fault. This is the compounding stage. ## Condition of Validity The invariant holds — compaction is safe — only when the following condition is satisfied at the moment of compaction: **every referent that the instance may need to re-issue, resume, or verify against external state is either (a) retained verbatim outside the summarized span, or (b) provably re-derivable from the retained context plus a deterministic tool call.** Condition (b) is the trap. It is almost never satisfiable for resume tokens, idempotency keys, warrant signatures, and checkpoint hashes, because these are generated by the external system and are not functions of anything the agent holds. An agent can re-derive "the name of the staging table" (it named it). It cannot re-derive "the offset the tool was at when it paused" (the tool knows, the agent does not, and re-asking may itself be a state mutation). So the operational test before any compaction pass is: *classify every literal token in the span being summarized as prose or pointer.* Prose may be summarized. Pointers must be hoisted into a retained sidecar — a structured, non-summarized region of context (or external store) that compaction is forbidden to touch. The summarizer's budget applies only to the prose remainder. If the pointer sidecar plus the prose summary exceeds the budget, the correct action is not to compress the pointers; it is to *fail the compaction and escalate* (checkpoint, hand off, or request a larger window), because a compaction that drops a pointer is not a lossy compaction, it is a state corruption. ## Decision Boundary The boundary between "compact" and "refuse to compact" is drawn by referent density, not by token pressure. Token pressure tells you *when* you want to compact; referent density tells you *whether you may*. - **Low referent density, high prose:** compact freely. Summarize the reasoning, keep the conclusions, rehydrate by similarity if needed. This is the case summarizers are designed for. - **High referent density, low prose:** do not summarize the span at all. Hoist the pointers verbatim into the sidecar, and if the sidecar alone exceeds budget, the span is not compactible — checkpoint and terminate the compaction attempt rather than proceed. - **Mixed, and the pointers are interleaved with the prose that gives them meaning:** this is the dangerous middle. A pointer stripped of its surrounding "what this cursor is for" prose becomes an orphan — retained but unusable, because the agent no longer knows which operation to resume. Here the correct move is to summarize the prose *around* each pointer while retaining the pointer plus a minimal fixed-schema annotation (`{kind: resume_token, for: batch_migration, step: 14}`), never the pointer alone and never the prose alone. The decision must be made *before* the summarizer runs, by a classifier that sees the raw span, not *after* by a rehydration pass that sees only the summary. Once the pointer is gone, no downstream retrieval can distinguish "this span had no pointer" from "this span's pointer was elided," and rehydration will confidently return the wrong answer in both cases. ## Operational Effect An instance that enforces the rehydration-fidelity invariant behaves measurably differently at exactly the moments that matter: - **Compaction becomes refusable.** The compaction routine gains a failure path — `CompactionRefused` — that fires when the pointer sidecar would exceed budget, rather than silently dropping pointers to fit. A refused compaction triggers a checkpoint-and-handoff, which is recoverable; a pointer-dropping compaction is not. - **Rehydration gains a provenance check.** Retrieved spans are tagged with whether they are verbatim (pointer-bearing) or summarized (prose-only). A rehydration result that is summarized cannot be used to satisfy a referent request; the instance must escalate to the tool layer or the sidecar instead of trusting the similarity match. - **Replay becomes detectable.** With the resume token retained, a re-issued operation carries its idempotency key, and the tool's duplicate-rejection is correctly interpreted as "I already did this" rather than "something is wrong." The three-call destructive reconciliation loop in the observed trace does not occur, because step 23 recognizes the replay and skips to resume-from-offset. The cost is that some compactions that *would* have fit under budget are refused, and the instance checkpoints more often than a naive summarizer would require. That cost is bounded and recoverable. The cost of the alternative — a lost referent, a confident wrong rehydration, and a misdiagnosed replay — is unbounded and, as observed, destructive. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class CompactionRefused(RuntimeError): """Raised when a compaction pass cannot preserve all non-reconstructible referents.""" pass class ReferentKind(str, Enum): RESUME_TOKEN = "resume_token" IDEMPOTENCY_KEY = "idempotency_key" CHECKPOINT_HASH = "checkpoint_hash" WARRANT_SIGNATURE = "warrant_signature" @dataclass class Referent: kind: ReferentKind literal: str for_operation: str step: int @dataclass class Span: text: str referents: list[Referent] = field(default_factory=list) @dataclass class CompactionResult: prose_summary: str pointer_sidecar: list[Referent] tokens_used: int def compact(span: Span, prose_budget: int, sidecar_budget: int) -> CompactionResult: # Referents are never summarized; they are hoisted verbatim. sidecar = list(span.referents) sidecar_tokens = sum(len(r.literal) + len(r.for_operation) + 16 for r in sidecar) if sidecar_tokens > sidecar_budget: # The pointers alone exceed the sidecar budget. We must NOT drop them # to fit; the span is not compactible. Refuse and escalate. raise CompactionRefused( f"pointer sidecar needs {sidecar_tokens} tokens > budget {sidecar_budget}; " f"span has {len(sidecar)} non-reconstructible referents " f"(steps {[r.step for r in sidecar]}). Checkpoint and hand off instead." ) remaining = prose_budget - sidecar_tokens if remaining <= 0: raise CompactionRefused( f"no prose budget remaining after reserving {sidecar_tokens} pointer tokens" ) # Only the prose remainder is eligible for lossy summarization. prose_summary = _summarize(span.text, remaining) return CompactionResult( prose_summary=prose_summary, pointer_sidecar=sidecar, tokens_used=len(prose_summary) + sidecar_tokens, ) def _summarize(text: str, budget: int) -> str: # Placeholder for the lossy summarizer; assumed to respect budget. return text[:budget] def rehydrate(query: str, spans: list[Span], sidecar: list[Referent]) -> Optional[Referent]: # A referent request must be satisfied from the sidecar, never from a # similarity match over summarized prose. for ref in sidecar: if ref.for_operation in query or ref.literal in query: return ref return None if __name__ == "__main__": span = Span( text="Resumed migration from the cursor returned at step 14 and continued batches.", referents=[ Referent( kind=ReferentKind.RESUME_TOKEN, literal="mig_7d2e9a4b::offset=18422", for_operation="batch_migration", step=14, ) ], ) try: result = compact(span, prose_budget=400, sidecar_budget=8) except CompactionRefused as e: print(f"refused: {e}") else: print(result) ```