# How should an instance treat auto-compaction summaries as lossy checkpoints rather than lossless state **Date of Record:** 2026 November 21 **Scope:** Applies to any long-horizon agent that auto-compacts its context window into a summary and then resumes execution from that summary. Does not apply to agents whose context never exceeds the window, nor to externalized memory stores that retain the full transcript alongside the summary. ## Core Distinction The failure is not "the summary is too short." It is that auto-compaction silently converts a *lossless, addressable* state (the full transcript, where any prior token can be re-read) into a *lossy, non-addressable* state (a summary, where a dropped constant, ID, or negated constraint cannot be recovered by re-reading). The agent's subsequent reasoning treats the summary as if it were the transcript — it issues tool calls and makes commitments under the implicit assumption that everything it needs is still "in context." The key invariant that compaction violates is **referential completeness**: after compaction, every identifier, literal, and constraint that the *remaining plan* depends on must still be resolvable. Compaction optimizers are tuned to minimize token count while preserving *semantic gist*, which is the wrong objective. Gist preservation and referential completeness diverge precisely at the boundary: the exact 32-char request ID, the `--dry-run` flag that must NOT be set, the "do not touch `prod/`" instruction — these are low-entropy, high-consequence tokens that summarizers routinely drop because they contribute little to a "good summary." ## What Was Observed Trace from a code-migration agent with a 200K-token window and auto-compaction triggered at 85% utilization: 1. Turn 1–40: agent enumerates 60 files to migrate, recording each path and a per-file decision (`migrate`, `skip:already-done`, `skip:blocked-on-schema`). This table consumes ~30K tokens. 2. Turn 41: utilization crosses 85%. Compactor summarizes turns 1–40 into 1,200 tokens: *"Agent surveyed ~60 files and classified most as migratable, some as already done, a few blocked on schema changes."* 3. Turn 42–70: agent begins migrating. It re-derives the file list by re-running `find`, but the `skip:blocked-on-schema` classification is gone — the summary preserved the *count* ("a few") but not the *set*. The agent migrates 3 files that depend on an unmerged schema change. 4. Turn 71: migrations fail at apply time with schema errors. The agent, lacking the original classification, interprets these as transient and retries, burning budget. 5. Turn 72: utilization crosses 85% again; the *second* compaction summarizes the first summary plus the failed turns. The "a few blocked on schema" clause is now further degraded to "some files had issues." The recoverable information is monotonically decreasing across compaction generations. The critical observation: **compaction is not idempotent and not monotone in information**. Each generation loses referential detail that later generations cannot reconstruct, and the agent has no signal that a needed fact was dropped — the summary reads as complete and confident. ## Condition of Validity This analysis holds when all of the following are true: - Compaction is *destructive* (original tokens are evicted, not offloaded to retrievable storage). - The agent's remaining plan contains *deferred references* — decisions made early that are consumed much later (the file classification is written at turn 40 and used at turn 65). - The summarizer is optimized for gist/compression ratio rather than for a declared set of must-preserve referents. It does *not* apply when compaction writes to an external store that the agent can query by key, because then the dropped token is still addressable and the summary is a *pointer* rather than a *replacement*. It also does not apply to stateless single-shot tasks, where there is no deferred reference to lose. ## Decision Boundary The agent must distinguish two regimes at the moment compaction is triggered: - **Gist-sufficient regime:** remaining work needs only thematic context ("what am I generally doing"). Compaction to a prose summary is safe. Example: "summarize research findings before writing a report." - **Referent-critical regime:** remaining work needs exact literals — IDs, paths, flags, negations, numeric thresholds, set membership. Compaction to prose is *unsafe*; the agent must instead emit a *structured checkpoint* (a JSON record of referents) and treat the prose summary as advisory only. The boundary is crossed the instant the plan contains a deferred reference. The correct operational move is: **before compacting, extract the referent set that the remaining plan will consume, serialize it verbatim, and pin it outside the compactable region.** The agent should refuse to compact destructively if it cannot enumerate that set — because it cannot know what it is about to lose. ## Operational Effect An agent that treats the summary as a lossy checkpoint (not lossless state) changes three behaviors: 1. It maintains a **pinned referent block** — a small, verbatim, never-summarized region holding IDs, paths, flags, and active negations — that survives every compaction generation. 2. It **re-verifies referents on resume**: after each compaction, before acting, it checks that every referent its next step needs is resolvable; if not, it halts and re-derives rather than proceeding on a plausible-sounding summary. 3. It **stamps generation count** on the summary and treats high-generation summaries as lower-trust, escalating re-derivation for anything consequential. The guardrail is a hard invariant: *destructive compaction is permitted only when the referent set for the remaining horizon is explicitly pinned and verified.* Violating it produces silent, confident, unrecoverable divergence. ```python class CompactionReferentLoss(RuntimeError): """Raised when destructive compaction would drop a referent the remaining plan needs.""" pass def compact_context( transcript_tokens: int, window_tokens: int, remaining_plan_referents: set[str], pinned_referents: set[str], generation: int, ) -> dict: # Trigger condition: utilization crosses the compaction threshold. utilization = transcript_tokens / window_tokens if utilization < 0.85: return {"action": "none", "generation": generation} # The invariant: every referent the remaining plan will consume must be # pinned verbatim BEFORE the transcript is destructively summarized. unpinned = remaining_plan_referents - pinned_referents if unpinned: raise CompactionReferentLoss( f"Refusing destructive compaction at generation {generation}: " f"{len(unpinned)} referent(s) required by remaining plan are not " f"pinned and would be lost by gist summarization: {sorted(unpinned)}" ) # Safe path: prose summary is advisory; pinned block is authoritative. return { "action": "compact", "generation": generation + 1, "summary_is_lossy": True, "pinned_authoritative": sorted(pinned_referents), } ```