Compression Is Loss

Explain this chapter with AI

Copy this prompt into ChatGPT, Claude, Gemini, a local model, or another AI.

Apply this chapter with AI

Copy this prompt into ChatGPT, Claude, Gemini, a local model, or another AI.

An agent has accumulated a working past: an architecture decision at 500 tokens, an unresolved bug history at 4,000, three failed approaches at 8,000, tool observations at 20,000, the current implementation at 6,000. Chapter 10 does its honest work. Duplicates go, proven-superseded observations go, failed-input bulk goes with residues kept. Roughly 13,000 tokens leave. Twenty-five thousand remain, and every token of them matters in the sense this book has defined: some future computation may need it, and no rung of the evidence ladder licenses deletion. The bundle still does not fit the session ahead. Nothing left can disappear. Everything left cannot stay verbatim. That is where this chapter begins, at the exact point where deletion stops working.

The way out is transformation: replace a larger representation of prior context with a smaller one intended to preserve what future computations need. That sentence is the chapter’s definition, and its most load-bearing word is intended:

Context compaction replaces a larger representation of prior context with a smaller representation intended to preserve information needed by future computations.

Intended, not guaranteed. The gap between those two words is the entire subject. This chapter crosses Chapter 10’s firewall deliberately. Pruning removed without replacing; compaction replaces with a generated semantic substitute, a synopsis, digest, compressed record, or rewritten history. The boundary test from Chapter 10 still adjudicates: if new prose attempts to preserve the removed item’s meaning, the operation lives here. Mechanical placeholders stay there.

A fluent summary proves nothing

The chapter’s first obligation is to destroy a judgement the field relies on daily: “this is a good summary.” Fluency, coherence, concision, technical plausibility, a summary can exhibit all four while having dropped the single constraint the next twenty turns depend on. Nobody reading the summary will notice, because what was dropped is absent rather than wrong, and absence has no stylistic signature. Hence the central equation, stated early and used throughout:

summary fluency
        โ‰ 
information survival
        โ‰ 
future behavioural utility

Three different claims, three different measurements. Fluency is a property of the text. Survival is a relation between the source and the text, checkable item by item. Utility is a relation between the text and future behaviour, checkable only by running the future. A compaction practice that scores the first and assumes the other two is not measuring compaction. It is admiring prose.

The same discipline applies to the number teams quote most. A reduction from 100K to 10K tokens and a preservation rate of 90 per cent of critical information are unrelated quantities until measured together. Ninety per cent fewer tokens can preserve everything needed; twenty per cent fewer can destroy one decisive identifier. Therefore:

Compression ratio is a budget measurement, not a fidelity measurement.

Ratio answers what the session can now afford. Only survival analysis answers what it can still do.

Lossy is not the same as irreversible

Compaction is lossy by construction: the smaller representation carries less than the source. Whether the loss is operationally terminal depends on a separate fact, whether the source survives elsewhere. Two configurations:

raw history retained outside active context
        โ†“
summary can potentially be regenerated
or checked against the source

raw history discarded
        โ†“
summary becomes the only surviving representation
        โ†“
lost information may be unrecoverable

So the precise statement: compaction is lossy at the representation boundary, and becomes operationally irreversible when the source representation is no longer recoverable. Chapter 1’s separation does quiet work here again, not in context versus does not exist. An experiment that discards its ground truth along with its history cannot measure what it destroyed; the harness section below makes source retention an experimental requirement, not an architectural recommendation. No external artifact system is built in this chapter. The distinction is preserved so that later chapters can exploit it.

What must bypass the summariser

Some information cannot survive semantic compression at any ratio, and the chapter derives the bypass before any evidence. Consider three lines:

"Use PostgreSQL 18.2."

"Migration ID is 01947."

"Never modify production migrations without explicit approval."

A prose summariser handling these fluently may write 18 for 18.2, 1947 for 01947, generally avoid for never. Tiny linguistic changes, catastrophic information changes: a wrong version pin, a wrong identifier, a prohibition relaxed into advice. The failure is structural, not a quality defect. Semantic compression preserves gist, and for exact items the gist is the wrong object. Therefore:

Some information must bypass semantic compression.

The bypass needs a channel, not yet a final form: a verbatim keep-list carried through compaction untouched, typed exact fields, a quoted invariant block, a structured constraint record. The Context Compiler will eventually own the representation; this chapter establishes only the requirement. Chapter 7 already constrained the policy from the other side, PIN means copy verbatim, and the first compaction policy below inherits that constraint directly. Any compactor that cannot exempt exact spans is disqualified from histories containing them, which is to say, from production histories.

Typed compaction, derived then recognised

Chapter 7 predicted that uniform treatment of heterogeneous items would destroy exactly the strictest items, and the recent literature has tested that prediction from several directions at once. The chapter derives the policy first, then checks it against the field, because the order determines whether the book is learning or borrowing.

Derived from retention properties, the compaction contract reads:

exact constraint
        โ†’ preserve exactly, never paraphrase

decision and rationale
        โ†’ compress semantically, keep the why

large recoverable evidence
        โ†’ retain source identity plus the finding

transient operational detail
        โ†’ candidate for omission with residue

uncertain hypothesis
        โ†’ preserve the uncertainty if retained at all

The last line deserves its own section, because its failure mode is the subtlest in the chapter. Raw history says the serializer is suspected of corrupting timestamps, unverified. The summary says the serializer corrupts timestamps. Topic survived, epistemic status did not, and downstream behaviour now acts on a fact nobody established. Compaction must preserve certainty, hypothesis status, decision state, and open-versus-closed standing wherever the fixture needs them. No grand epistemic ontology follows; the chapter uses only what its probes test. But status survival joins exact and semantic survival as a first-class measurement, because possibility promoted to fact is not a lesser error than omission. It is omission’s mirror: the summary asserts what the source merely wondered.

The field has now measured the uniform-treatment failure repeatedly. The Compaction Cliff study found a production compactor preserving barely half of safety rules after one round and a tenth after five, with the decay reproduced across model families and structural baselines, and answered with per-type fidelity policies plus a verifier. A second 2026 study of session constraints found compactors retaining fewer than a fifth of injected behavioural constraints on average, most performing worse than no compaction at all, and answered with a constraint extractor running alongside the compactor. A third, built around deterministic violation grading, showed violations rising from zero to nearly a third after compaction, with a clean causal split: zero violation when the constraint survived the summary, nearly two-fifths when it did not, and a pinning defence restoring the zero. Three teams, three vocabularies, one shape: classify first, protect the strict, verify after. The book takes the convergence as confirmation of its derived policy and adopts none of the three taxonomies wholesale; Chapter 7’s classes remain canonical here.

Every compaction run in the experiments below therefore carries an explicit request contract, conceptual rather than implemented. Its inputs: the source context, a target token budget, the protected exact items, the semantic keep-list, and the provenance requirements. Its outputs: the compact representation plus a survival report stating what was kept, what was transformed, and what was dropped by class. No claim is made that a model can reliably honour this contract; the experiments exist to find out where it breaks. But without the contract there is nothing to grade except fluency, and the chapter has already established what fluency is worth.

Five failure families

Omission alone cannot describe what summaries do wrong, because compaction generates as well as removes. The chapter standardises five terms, each tied to a measurement in the experiment:

Omission. Required information disappears. The constraint is gone, the identifier absent, the rationale missing.

Mutation. Information survives altered. Port 5432 becomes 5433, a version shifts, a qualifier drops. The bypass channel exists for exactly this family.

Addition. The compact representation asserts what the source never established. Pruning could only remove; the compactor can invent, which makes addition the failure with no Chapter 10 analogue.

Epistemic collapse. Possibility becomes fact, unresolved becomes resolved, rejected becomes chosen. Status measurements catch what content measurements miss.

Provenance loss. Information survives while its source does not. A flat “the system should use Redis” that cannot say whether the user ordered it, the architecture decided it, a README claimed it, or a hypothesis floated it. Fact survival without provenance survival leaves Chapter 19 with nothing to adjudicate, which makes provenance loss a fidelity failure here rather than someone else’s problem later.

The unknown future is the problem

Everything above assumes the compactor knows what matters. It does not, and that ignorance is the chapter’s central intellectual problem, stronger than any slogan about shortening history:

Compaction is information selection under uncertain future demand.

An oracle with the future task list would keep exactly what is needed; the oracle condition in the experiment exists to quantify how much of the difficulty is prediction rather than capacity. A production compactor sees history, the current task, a retention policy, and a token target. It never sees the question twenty turns hence whose answer depends on the detail it is about to discard. Every keep-list, every fidelity tier, every pinned exact span is a bet placed under that uncertainty, and the experiment’s hidden probes are designed to settle those bets honestly: the compactor never meets the questions that will grade it.

One round, then rounds of rounds

A single compaction is the unit of analysis. Repeated compaction is a different mechanism wearing the same name. Long sessions compact, accumulate, and compact again:

raw history
    โ†“
summary 1 + new history
    โ†“
summary 2 + new history
    โ†“
summary 3

Later summaries compress earlier summaries, a recursive lossy channel where each generation’s errors become the next generation’s ground truth. Whether loss compounds is an empirical question the second experiment answers, not an intuition the chapter asserts. But the design space already offers three distinct strategies worth separating before measuring. Recursive compaction feeds each summary forward; cheap, and error-amplifying by construction. Source-grounded re-compaction rebuilds each compact representation from retained originals plus current material; expensive, and potentially immune to summary-of-summary drift. A third option, demonstrated by CliffCompaction, refuses the recursion entirely: never compact a compaction, discard the previous compact block, and condense only post-compaction turns by truncation and dropping without rephrasing, so that each pass handles only original content and drift cannot accumulate across generations. The chapter advocates none of them. It requires the experiment to compare at least the first two, with the third available as a challenger, because the choice between them is the choice between cheap compounding error, expensive freshness, and deliberate forgetting, and no principle selects among those without numbers.

Summary drift, if the term survives, means only the measurable version: lost invariants, changed identifiers, altered causal links, new unsupported assertions, lost uncertainty, changed status, lost provenance, tracked across rounds. Anything vaguer is atmosphere.

Two operational warnings accompany the rounds. First, volume control is itself unreliable: recent serving research reports that target token counts in compaction prompts exert weak control over realised output, with retained content varying run to run. Measure target against actual with variance across repeats, because a compactor that occasionally emits double its budget can trigger the very pressure it was relieving. Second, timing matters independently of content: fixed-threshold triggers fire mid-derivation as readily as at clean subtask boundaries, discarding partial results the model still needs, while rubric-gated triggering, fire on resolution or convergence, suppress mid-derivation, measurably beats blind intervals. Pressure-triggered, milestone-triggered, or hybrid scheduling is therefore part of the mechanism under test, connecting directly to Chapter 10’s task-boundary timing.

Cost, cache, and the opaque boundary

Compaction bills twice: the call itself, input plus output plus latency, and the prefix rewrite it performs. Replacing a large historical span with a summary moves the first-divergence position, orphaning cached computation downstream exactly as Chapter 9 priced it, so mutation radius and lost reusable prefix accompany every compaction claim unless provider semantics make them unobservable. That exception is real and growing. OpenAI’s current compaction surface is explicitly opaque: server-side threshold triggering plus a standalone endpoint, both returning an encrypted compaction item that carries prior state forward and is documented as not human-interpretable, with instructions to pass the returned window through unmodified. Where the representation cannot be inspected, representation audit is unavailable, and evaluation shifts entirely to controlled downstream probes, behavioural comparisons, provider telemetry, and remove-or-restore counterfactuals where the harness permits. The book does not speculate about opaque contents. It changes the measurement instrument to fit the observability: inspectable compaction earns fact-level survival analysis, opaque compaction earns black-box behavioural proof, and neither earns trust by fluency.

Anthropic’s published harness work supplies the complementary boundary from the inspectable side. Even with working compaction, long-running agents leave features half-implemented across windows and declare premature victory; continuity arrives behaviourally, through progress files, feature lists, and clean repository states, not as a property implied by possessing a summary. A summary’s existence never entails a handoff’s success. That sentence constrains the whole chapter: every compaction claim below is a claim about measured downstream continuity, never about the summary object.

Inspectable cases, kept in their lanes

Three production practices show what inspectable compaction looks like, each confined to this chapter’s questions. Anthropic’s engineering guidance describes the reference practice: pass message history through the model to preserve architectural decisions, unresolved bugs, and implementation details while discarding redundant tool outputs, tune the prompt recall-first on complex traces, then prune for precision, with tool-result clearing as the lightest-touch form. That is keep-list discipline stated as craft, and the chapter’s fixtures test whether craft survives measurement.

DCP’s compress tool shows selective span choice mechanised: range mode over contiguous spans with earlier summaries nested inside later ones, experimental message mode over individual messages, protected tool outputs and file patterns carried into summaries rather than dissolved. The difficult questions travel with the description. Does nesting reduce repeated degradation or merely hide it inside fluent layers? What happens when an earlier summary contains an error that later nesting treats as ground truth? Do protected elements retain their provenance or just their wording? Range against message compression is available in the product today; which one better preserves recoverability is an experiment, and the chapter leaves it as one.

Magic Context’s historian shows the other shape: older raw history continuously converted into compact compartment representations while current context stays raw, with durable decisions and constraints lifted into project memory alongside. The compartments, their fidelity behaviour, and any decay rendering belong to Chapter 12 and stay undescribed here; what matters for this chapter is the separation itself, current raw state beside generated historical state, with the boundary between them explicit rather than smeared across one summary. Memory-across-sessions machinery stays out entirely; that is the Memory book’s territory, and a summary surviving five turns is still current-context management no matter how durable it feels.

Proposed experiments

Two experiments share one fixture philosophy. Deterministic traces carry typed information classes, exact constraints, identifiers, decisions with rationales, rejected alternatives, unresolved and resolved bugs, task state, temporary hypotheses, evidence references, user preferences with delayed relevance, and trap details engineered to look expendable: the detail that matters much later, the old exact constraint, the hypothesis that must stay uncertain, the rejected plan that must not resurrect, paired facts whose only difference is authority. The compactor receives history, the current task, the retention policy, and the token target. It never receives the future probes. The evaluator retains the frozen source trace no matter what production policy would discard, because the experiment must never destroy its own ground truth.

Experiment 1: single-shot compaction. Conditions: raw context as the ceiling subject to long-context effects; uniform semantic compaction with one generic prompt and no keep-list as the naive baseline; typed compaction consuming Chapter 7 metadata with verbatim PIN handling; typed plus provenance preservation as a separable condition only if it adds a distinguishable mechanism; and an oracle representation built with full knowledge of the hidden probes, bounding what foreknowledge alone achieves. Compare at matched output budgets, reported as target ratio, actual ratio, and variance, never letting the better system quietly spend more tokens. An optional representation axis, free-form prose against a typed structured schema with constraints, decisions, unresolved items, rejected alternatives, evidence references, and current state, separates schema benefit from policy benefit only if the factorial stays interpretable. A schema under test might read:

constraints:       exact, verbatim, never paraphrased
decisions:         what was chosen plus the rationale
unresolved:        open items with their current status
rejected:          alternatives refused, with reasons
evidence_refs:     source identities, not pasted content
current_state:     where the work stands now

The schema is an experimental condition like the others, not an assumed superior architecture. If it wins, the experiment must still say whether the schema helped, the retention policy helped, or only their combination did.

Experiment 2: repeated compaction. Same traces, fixed new-history injections between rounds, measurements after one, three, and five rounds: uniform recursive against typed recursive, with source-grounded re-compaction and discard-and-restart challengers where feasible. Lineage is mandatory infrastructure: every summary records its parent, its sources, its round, and its policy and model versions, or drift cannot be attributed. Survival curves are plotted per information class, never as a global average that could hide total exact-constraint loss inside excellent narrative retention.

Scoring runs survival before behaviour. Exact survival by deterministic or normalised comparison for identifiers, numbers, PIN constraints, configuration values. Semantic survival by frozen rubric for rationales, unresolved work, causal links, with evaluator models blinded to condition, separated from compactor models where possible, and deterministic checks preferred wherever they apply. Status survival: open stayed open, hypothesis stayed hypothesis, rejected stayed rejected. Provenance survival where interpretation depends on source. Unsupported additions counted alongside omissions, contradictions and status inversions flagged, because the compactor’s generative half needs its own ledger. Then downstream hidden tasks measure success, constraint adherence, fact use, incorrect recovery, and unsupported assumptions, preserving Chapter 7’s distinction between information that survived unused and information destroyed before use. Independent judgement follows the obvious controls: frozen evaluator prompts, blinding, raw-source evidence retention, human sampling for ambiguity. LLM judges are instruments with stated error, never oracles.

Cost accounting inherits both ledgers. Tokens removed minus summary tokens introduced minus management overhead, plus the compaction call’s own input, output, latency, and cache-invalidation cost against later-request savings. The emerging literature already prices pieces of this: paired-continuation methods that evaluate each compaction boundary against uncompacted controls from the same state, async designs that validate candidate summaries against independently continued trajectories, rubric-gated triggering that fires only on resolution or convergence. The book’s fixtures implement the same ethic in its own harness rather than importing results: measure the boundary, not the prose.

The survival reporting takes one fixed form across both experiments, introduced here unfilled because no runs exist. Rows are information classes, columns are conditions and rounds, cells hold the class survival rate once measured:

                    raw   uniform   typed   typed+prov   5 rounds
exact constraint     โœ“      ?         ?        ?           ?
identifier           โœ“      ?         ?        ?           ?
decision             โœ“      ?         ?        ?           ?
rationale            โœ“      ?         ?        ?           ?
unresolved work      โœ“      ?         ?        ?           ?
provenance           โœ“      ?         ?        ?           ?

The matrix enforces the chapter’s central discipline at a glance: classes stay separate down every column, rounds extend to the right, and no global average is ever computed across rows. A future result reading 95 per cent narrative survival beside 10 per cent constraint survival will be visible here as what it is, a failure wearing a passing average, rather than averaged into respectability.

What the classes hand to the compactor

Chapter 7’s contract converts directly into compaction policy, and the conversion is strict enough to quote. PIN copies verbatim or the run is disqualified; the pinning defences in recent governance work, restoring perfect adherence without touching the summariser, show how cheap exemption can be when the channel exists. COMPRESSIBLE transforms semantically under keep-lists, with the lists audited rather than assumed. DISCARDABLE never reaches the compactor at all; it left in Chapter 10. EXTERNALIZABLE and REFETCHABLE pass through as references, not as material to transform, and building their machinery stays in later chapters. Source-preserving compaction, a decision with its rationale and source identity attached, is welcome structure inside those rules, not a new storage system. Uncertainty rides alongside as a survival property, not a class. Structured schemas are an experimental condition, not an assumed superior architecture. If any of this sounds like the Context Compiler arriving early, it is not: no admission scoring, no assembly policy, no cross-mechanism optimisation appears here, only per-item transformation contracts the compiler will one day read. Nor is any of it memory: a summary surviving five turns answers which prior context still matters now, not which past information should shape future sessions, and the two questions keep their separate books.

The cliff at the end of compaction

Uniform compaction degrades gracefully in token counts and catastrophically in the wrong classes, and the chapter can now name the shape it has been circling. Raw history jumps in one step to a single lossy summary at an arbitrary threshold: full fidelity, then whatever the summariser kept, with no intermediate state and no return path. That discontinuity is the mechanism Chapter 12 exists to replace. Whether fidelity should instead descend through explicit tiers, what those tiers preserve and discard, and whether deterministic rendering beats generative summarising at each step, are genuinely different questions from everything answered here. They require the cliff first, stated plainly:

raw
 โ†“ abrupt threshold
summary

is a discontinuity, and discontinuities are design choices wearing the mask of necessity.

References

  • Zerhoudi, S., Mitrovic, J., Granitzer, M. “The Compaction Cliff in Long-Running AI Agent Memory.” Preprint, arXiv:2608.22752, August 2026 (page lists CIKM 2026 proceedings, unverified). Type-blind decay 53% to 10% across rounds; Knowledge Triage operators. https://arxiv.org/abs/2608.22752
  • Wang, Z., Zhang, Y., Lee, D., Yang, Y. “Lost in Compaction: Evaluating Side-Constraint Loss under Context Compaction.” Preprint, arXiv:2608.11242, July 2026. COMPINT suite; 17% average constraint retention; extractor defence. https://arxiv.org/abs/2608.11242
  • Chen, S. “Governance Decay: How Context Compaction Silently Erases Safety Constraints in Long-Horizon LLM Agents.” Preprint, arXiv:2606.22528, June 2026. ConstraintRot survived/dropped split; pinning defence. https://arxiv.org/abs/2606.22528
  • Cim, M., Topcu, B., Das, C., Kandemir, M. T. “Parallel Context Compaction for Long-Horizon LLM Agent Serving.” Preprint, arXiv:2605.23296, May 2026. Volume and retention variance across runs. https://arxiv.org/abs/2605.23296
  • Min, G., Wu, L., Darbari, M., Chen, C., Hong, L. “Toward Reliable Context Compression for Long-Horizon Agents.” Preprint, arXiv:2608.06503, August 2026 (self-described preliminary study). Boundary-local paired evaluation; execution instability. https://arxiv.org/abs/2608.06503
  • Chen, Z., Pan, R., Dai, Y., Netravali, R. “Slipstream: Trajectory-Grounded Compaction Validation for Long-Horizon Agents.” Preprint, arXiv:2605.08580, May 2026. Async judge validation of summaries. https://arxiv.org/abs/2605.08580
  • Nguyen, T., Cho, E., Chen, B., Dettmers, T. “CliffCompaction: Cost-Efficient Compaction for Long-Horizon Coding Agents.” Preprint, arXiv:2609.26779, September 2026. Never-compact-a-compaction; precision/recall framing. https://arxiv.org/abs/2609.26779
  • Li, T., Zhang, J., Jurayj, W., et al. “Self-Compacting Language Model Agents.” Preprint, arXiv:2606.23525, July 2026. Compaction tool plus rubric-gated triggering; fixed-interval comparison. https://arxiv.org/abs/2606.23525
  • OpenAI. “Compaction.” Official documentation, verified September 2026. Server-side and standalone opaque compaction; chaining and latency guidance. https://developers.openai.com/api/docs/guides/compaction
  • Anthropic Applied AI team. “Effective context engineering for AI agents.” Published 29 September 2025. Compaction retain/discard practice; recall-first tuning. https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents
  • Anthropic. “Effective harnesses for long-running agents.” Published 26 November 2025. Compaction insufficiency; artifact-based continuity. https://www.anthropic.com/engineering/effective-harnesses-for-long-running-agents
  • Tarquinen. “Dynamic Context Pruning Plugin (DCP).” OpenCode plugin, AGPL-3.0-or-later, re-verified September 2026. Range/message compression; nested summaries; protected outputs. https://github.com/Tarquinen/opencode-dynamic-context-pruning
  • cortexkit. “Magic Context.” Context plugin, MIT at review, verified September 2026. Historian compact representations; tier discussion deferred to Chapter 12. https://github.com/cortexkit/magic-context