# In what scenarios must an instance treat context compaction as a lossy checkpoint with a declared fidelity budget rather than a transparent memory optimization **Date of Record:** 2026 November 29 **Scope:** Applies to any long-horizon agent that reclaims context-window budget by summarizing prior turns and later rehydrating from those summaries. Does not apply to stateless single-shot inference or to agents whose entire working set provably fits beneath the compaction threshold for the whole task lifetime. ## Core Distinction Compaction is routinely described as "memory management," which implies a reversible operation: you shrink the transcript, you keep the meaning. That framing is false at the agent layer. Compaction is a **lossy checkpoint** whose information content is bounded by whatever the summarizer chose to preserve, and the summarizer is a probabilistic function that has no access to the future queries the agent will make against it. The correct mental model is not "cache eviction" but "write-ahead log truncation with a declared fidelity budget." The distinction that matters operationally is between two failure classes that look identical in the transcript: - **Benign compaction:** the dropped tokens were redundant with tokens that survived. Rehydration reconstructs the same decision state. - **Pathological compaction:** the dropped tokens carried a *load-bearing commitment* — a constraint, a rejected alternative, a numeric literal, a tool-call precondition — that the summarizer judged low-salience because it appeared once and read like boilerplate. The failure is non-obvious because compaction *succeeds*: the summary is fluent, coherent, and plausibly faithful. The defect does not surface until a later step queries the compacted region for a detail the summary silently generalized away. At that point the agent does not error — it *confabulates a consistent substitute* and proceeds, which is strictly worse than a hard crash. ## What Was Observed A planning agent executing a 40-step infrastructure-remediation task compacted its transcript at step 22 (context at 91% saturation). The summarizer, prompted with "summarize the conversation so far, preserving key decisions," produced a 600-token summary. The original 18,000 tokens included this literal, emitted by a config-inspection tool at step 9: ``` retry_policy.max_attempts = 3 retry_policy.backoff = "exponential" retry_policy.jitter = false # NOTE: jitter disabled per incident #4412 ``` The summary rendered this as: *"Retry policy was inspected and confirmed acceptable."* At step 31, a downstream tool call re-derived the retry configuration from the summary rather than re-running the inspection (the agent reasoned, correctly per its own compacted state, that the config was already verified). It emitted a remediation manifest with `jitter: true` — the framework default — because "acceptable" carried no commitment about the `false` value, and the default leaked in. The manifest passed schema validation. It failed in production because the incident that motivated `jitter: false` was exactly a thundering-herd retry storm. Three properties made this non-obvious: 1. **The summary was not wrong, only underdetermined.** "Confirmed acceptable" is true of the original. It is also true of a dozen incompatible configurations. The fidelity budget was spent on narrative and not on the one bit that mattered. 2. **Rehydration did not fail loudly.** No retrieval miss, no schema violation. The agent reconstructed a *self-consistent* world in which jitter was default-true, because nothing in the compacted state contradicted it. 3. **The loss was uncorrelated with token salience.** The load-bearing token was a trailing comment on a config line — precisely the kind of content summarizers compress hardest. ## Condition of Validity The invariant that bounds this failure is a **declared fidelity budget with typed retention classes**, not a generic "preserve important details" instruction. The condition under which compaction is safe is: > For every token class `C` in the working set, either (a) `C` is retained verbatim through compaction, or (b) `C` is provably re-derivable by re-executing a recorded tool call, or (c) the agent's subsequent plan contains no decision that depends on `C`. Class (b) is the escape hatch that makes compaction tractable: you do not need to summarize a tool output faithfully if you retain the *call* and can replay it. The failure above occurred because the agent treated a replayable inspection as a summarized fact — it kept the conclusion and dropped the call, converting a re-derivable output into an unrecoverable claim. The budget must be declared *before* compaction, per retention class, with an explicit overflow behavior. A workable declaration: - `commitments` (constraints, rejections, numeric literals with provenance, incident-linked values): verbatim, never summarized, hard cap with compaction refusal on overflow. - `derivations` (tool outputs): retain the call signature + hash, drop the payload, mark rehydratable. - `narrative` (reasoning traces, exploratory dialogue): summarize freely, target 10:1. When `commitments` exceeds its cap, the correct behavior is to **refuse compaction and escalate** (spill to external store, or checkpoint-and-resume), not to summarize commitments under pressure. Silent demotion of a commitment to narrative is the exact transition that produced the incident. ## Decision Boundary The boundary between safe and unsafe compaction is crossed at the moment the agent must answer a question about a compacted region and has neither the verbatim token nor a replayable call. Formally, define for each compacted span a *rehydration obligation set* `O` — the set of future decisions whose correctness depends on that span. Compaction is admissible iff `O ⊆ retained ∪ rehydratable`. In practice the agent cannot compute `O` exactly (it does not know its future queries), so it must use a conservative over-approximation: any token that *could* be load-bearing given the current plan is a commitment. The decision rule: - If a span is referenced by an active plan node → commitment class → verbatim. - If a span is a tool output whose call is recorded → derivation class → drop payload, keep call. - Otherwise → narrative → summarize. The failure mode is any path where a span is classified narrative *and* later referenced by a plan node. Guard against this by re-checking classification at rehydration: if a rehydration query hits a narrative-class span, that is a **classification violation**, not a retrieval miss, and must halt rather than confabulate. ## Operational Effect The architectural consequence is that compaction must emit a **manifest** alongside the summary: the retention-class assignment, the rehydration obligations it believes it satisfies, and the replay handles for dropped derivations. Rehydration then becomes a verified operation against the manifest rather than an act of interpretation against prose. An agent that rehydrates from a summary without a manifest is, operationally, guessing — and will guess fluently. The second consequence is that **compaction pressure must not silently degrade class**. When the commitment budget is exhausted, the agent must choose between escalating (external spill, checkpoint-resume, human handoff) and refusing to proceed. It must never choose "summarize the commitments a little." That choice is invisible in the transcript and catastrophic downstream. The third consequence is provenance: every rehydrated fact must carry the class it was rehydrated from. A fact recovered from `narrative` is a *hypothesis* and must be re-verified before it gates an action; a fact recovered from `derivations` is *replayable* and must be replayed, not trusted; only `commitments` may be acted on directly. Collapsing these three into "memory" is the root error. ```python from dataclasses import dataclass, field from enum import Enum class RetentionClass(Enum): COMMITMENT = "commitment" # verbatim, never summarized DERIVATION = "derivation" # payload droppable, call replayable NARRATIVE = "narrative" # freely summarizable class CompactionFidelityError(RuntimeError): """Raised when compaction or rehydration would violate the declared fidelity budget.""" pass @dataclass class Span: span_id: str retention: RetentionClass verbatim: str | None = None replay_handle: str | None = None # tool-call signature for DERIVATION summary: str | None = None # only for NARRATIVE @dataclass class CompactionManifest: commitment_cap: int spans: dict[str, Span] = field(default_factory=dict) obligations: set[str] = field(default_factory=set) # span_ids referenced by active plan def classify(self, span: Span) -> None: # A span referenced by an active plan node may never be demoted below commitment. if span.span_id in self.obligations and span.retention is not RetentionClass.COMMITMENT: raise CompactionFidelityError( f"span {span.span_id} is plan-referenced but classified " f"{span.retention.value}; demotion would create an unrecoverable obligation" ) self.spans[span.span_id] = span def admit_commitment(self, span: Span) -> None: current = sum(1 for s in self.spans.values() if s.retention is RetentionClass.COMMITMENT) if current + 1 > self.commitment_cap: # Correct behavior: refuse compaction, escalate. Never summarize commitments. raise CompactionFidelityError( f"commitment budget {self.commitment_cap} exhausted; " f"refusing to compact span {span.span_id} — escalate to external spill" ) self.classify(span) def rehydrate(manifest: CompactionManifest, span_id: str, purpose: str) -> str: span = manifest.spans.get(span_id) if span is None: raise CompactionFidelityError(f"rehydration miss: span {span_id} absent from manifest") if span.retention is RetentionClass.COMMITMENT: assert span.verbatim is not None return span.verbatim if span.retention is RetentionClass.DERIVATION: if span.replay_handle is None: raise CompactionFidelityError( f"derivation span {span_id} has no replay handle; " f"payload was dropped without a recovery path" ) # Caller must replay the tool call; we refuse to return a cached payload. raise CompactionFidelityError( f"derivation span {span_id} requires replay via {span.replay_handle}, " f"not trust — do not act on un-replayed derivation" ) # NARRATIVE: only admissible if the span is NOT plan-referenced. if span_id in manifest.obligations: raise CompactionFidelityError( f"classification violation: rehydration query '{purpose}' hit narrative " f"span {span_id} that is plan-referenced; halt rather than confabulate" ) assert span.summary is not None return span.summary def compact(manifest: CompactionManifest, span: Span) -> None: if span.retention is RetentionClass.COMMITMENT: manifest.admit_commitment(span) else: manifest.classify(span) ```