# How should an instance treat the compaction boundary itself as non-compactable state **Date of Record:** 2026 November 27 **Scope:** Applies to any agent that summarizes or evicts its own context mid-task to stay under a token budget, where the compaction operation is performed by the same model instance that will subsequently act on the compacted context. Does not apply to external, read-only archival systems or to compaction performed by a separate, stateless summarizer with no shared token budget. ## Core Distinction The failure here is not "the summary lost information." It is that the compaction *act itself*—the fact that a summary now stands in for evicted history, and the boundary between what is verbatim and what is reconstructed—is not carried forward as first-class state. The agent treats the summary as if it were the original observation. The distinction that matters is between **content compaction** (lossy but tracked: "I know this is a paraphrase of turns 1–40") and **provenance collapse** (lossy and untracked: "I believe this is what happened"). Every downstream failure in this record flows from provenance collapse at the compaction boundary, not from the lossiness of the summary per se. A summary that drops a detail but is *labeled* as a summary is recoverable: the agent knows to re-fetch or re-verify. A summary that drops a detail and is presented with the same epistemic weight as a verbatim tool result is not recoverable, because nothing in the context signals that a re-check is warranted. ## What Was Observed A long-horizon agent executing a multi-step deployment task (read config → validate → mutate → verify) hit a token budget at step 34 of an estimated 60. It compacted turns 1–28 into a ~600-token summary and continued. The task-critical state was a single value: a resource identifier returned verbatim by a tool at turn 9, of the form `svc-7f3a9c1e`. The summary rendered it as "the service was identified earlier." The agent proceeded, and at step 41 issued a mutation against a *re-derived* identifier reconstructed from the summary's description rather than the original tool output. The trace showed three distinct transitions: 1. **Eviction (turn 34):** verbatim tool output containing `svc-7f3a9c1e` removed from context; summary inserted. The summary preserved the *existence* of the identifier but not its *bytes*. 2. **Latent reconstruction (turn 41):** the agent, needing an identifier, generated one from the summary's semantic content. Crucially, it did not flag this as a guess. The generation was fluent and format-correct, so nothing in the output distinguished it from a recall. 3. **Silent divergence (turn 42):** the mutation succeeded against a resource that *existed* (the re-derived identifier happened to collide with a real, different service in the same namespace). No error, no exception, no tool failure. The task "completed." The most dangerous property: the failure produced a *successful-looking* run. A tool error would have been caught. The compaction boundary instead produced a confident, plausible, wrong state that passed every downstream check because the checks operated on the reconstructed value, not the original. ## Condition of Validity The guardrail is only valid under a specific condition: **the compaction operation must emit a machine-readable provenance envelope that survives into every subsequent turn, and every downstream consumer of compacted content must be able to test "is this verbatim or reconstructed?" before acting.** This means compaction is not a text transformation; it is a state transition that must preserve an invariant: > *For any fact F in context, either F is verbatim (byte-identical to a prior tool output or user message, with a stable reference) or F is tagged reconstructed (with the reference to what it summarizes). There is no third state where F is present but untagged.* If the invariant holds, a consumer that needs exact bytes can refuse to act on a reconstructed fact and re-fetch. If the invariant is violated—if any reconstructed fact enters context untagged—the system is in an unsafe state regardless of how good the summary is, because no downstream logic can distinguish recall from confabulation. The condition fails in practice for a specific, non-obvious reason: **the summarizer and the consumer are the same instance, and the summarizer's output is natural language that reads identically whether it is faithful or not.** There is no external oracle at the boundary. The envelope must therefore be structural (separate fields, typed markers, stable IDs), not stylistic. ## Decision Boundary The boundary is not "how many tokens do I have left." It is **"does the fact I am about to compact have a downstream consumer that requires exact bytes?"** Two categories must be handled differently at the compaction decision point: - **Semantic facts** (task goal, plan, decisions made, rationale): safe to compact lossily. A paraphrase of "we decided to deploy to staging first" loses nothing actionable. - **Opaque tokens** (resource IDs, hashes, credentials handles, file paths, exact API field names, numeric thresholds): **must not be compacted into natural language at all.** They must be moved to a structured sidecar that is carried verbatim and referenced by ID, or the agent must be forced to re-fetch them at point of use. The decision rule: before evicting any span, classify each atomic fact. If a fact is opaque-token class, it does not get summarized—it gets *externalized* to a key-value store with a stable key, and the summary carries only the key. The agent then dereferences the key at use time. If the store is unavailable, the correct behavior is to *fail the compaction* and force a different strategy (e.g., truncate low-value spans instead), not to summarize the opaque token into prose. This is where most implementations break: they treat compaction as a single operation over a token window, applying one summarization policy uniformly. The boundary requires *two* policies selected per-span by fact class, and the classifier must run before the eviction, not after. ## Operational Effect When the invariant is enforced, the observable behavior changes in three ways: 1. **Reconstruction becomes visible.** A consumer that would have silently re-derived an identifier now hits a missing key, raises, and re-fetches. The task gets slower and occasionally fails loudly—which is the correct outcome, because a loud failure at the boundary is cheaper than a silent divergence downstream. 2. **Compaction can be audited.** Because every reconstructed fact carries a reference to what it summarizes, a replay can compare summary against source and measure distillation loss per fact class. Without the envelope, distillation loss is unmeasurable—you cannot diff a paraphrase against a memory you no longer have. 3. **The token budget becomes honest.** Carrying an opaque-token sidecar costs tokens. The agent must budget for it explicitly rather than pretending compaction is free. In the observed run, the sidecar for 28 turns of opaque tokens was ~90 tokens—cheap, and it would have prevented the entire failure. The counterintuitive operational lesson: **the cheapest part of the context to preserve is often the most dangerous to compact.** Opaque tokens are small, and they are exactly the facts that cannot be reconstructed from semantics. Compaction strategies that optimize for "compress the most tokens" systematically evict the highest-risk, lowest-volume content first, because a 40-token ID looks like low-value noise next to a 400-token reasoning trace. The decision boundary inverts the naive heuristic: protect the small, exact things; compress the large, semantic things. ```python from dataclasses import dataclass, field from enum import Enum class FactClass(Enum): SEMANTIC = "semantic" # safe to summarize lossily OPAQUE_TOKEN = "opaque" # must be externalized verbatim, never paraphrased class ProvenanceCollapse(RuntimeError): """Raised when a reconstructed fact is consumed as if it were verbatim.""" pass @dataclass class Fact: key: str value: str cls: FactClass verbatim: bool # True only if byte-identical to a prior tool/user output source_ref: str | None # stable reference to the span this summarizes @dataclass class ContextStore: # Sidecar: opaque tokens live here verbatim, keyed, never summarized. sidecar: dict[str, str] = field(default_factory=dict) # What the model actually sees: semantic summary + keys, never raw opaque values. visible: list[Fact] = field(default_factory=list) def compact(self, facts: list[Fact], summarizer) -> None: for f in facts: if f.cls is FactClass.OPAQUE_TOKEN: if not f.verbatim: # Refuse to compact an already-reconstructed opaque token. raise ProvenanceCollapse( f"opaque token {f.key!r} is not verbatim; " f"cannot externalize a reconstruction" ) self.sidecar[f.key] = f.value self.visible.append(Fact( key=f.key, value=f"", cls=FactClass.OPAQUE_TOKEN, verbatim=False, source_ref=f.key, )) else: self.visible.append(Fact( key=f.key, value=summarizer(f.value), cls=FactClass.SEMANTIC, verbatim=False, source_ref=f.source_ref or f.key, )) def resolve(self, key: str) -> str: if key not in self.sidecar: # The consumer wanted exact bytes but they were lost to compaction. # Fail loudly; do NOT let the model re-derive a plausible value. raise ProvenanceCollapse( f"key {key!r} absent from sidecar; " f"re-fetch from source, do not reconstruct" ) return self.sidecar[key] def mutate_resource(store: ContextStore, key: str) -> str: try: resource_id = store.resolve(key) except ProvenanceCollapse: raise if not resource_id.startswith("svc-"): raise ProvenanceCollapse( f"resolved {resource_id!r} for {key!r} fails format check; " f"possible reconstruction leak" ) return f"mutated {resource_id}" ```