# In what scenarios must an instance treat context compaction as a lossy state transition rather than a cache eviction **Date of Record:** 2026 November 26 **Scope:** Applies to long-horizon agent instances that automatically compact their working context when a token budget threshold is crossed, replacing raw transcript segments with a generated summary and relying on retrieval to restore evicted detail. Does not apply to instances with unbounded context, or to compaction that is user-initiated with a human-verified summary artifact. ## Core Distinction Cache eviction and context compaction are routinely conflated because both are triggered by a capacity threshold and both reclaim token space. The distinction that matters operationally is this: an evicted cache line is *reconstructible* from its backing store with bit-identical fidelity, so eviction is a pure performance event. A compacted context segment is *not* reconstructible from its summary, because the summary is a lossy projection produced by the same probabilistic model that is about to rely on it. Compaction is therefore a state transition that mutates the agent's epistemic substrate, and the summary plus the retrieval index together form a *new* state whose equivalence to the pre-compaction state is an assumption that must be actively validated, not presumed. The non-obvious consequence: every compaction introduces an asymmetry between what the agent *did* (the full transcript, now gone) and what the agent *believes it did* (the summary, plus whatever retrieval happens to surface later). Failures arise not when compaction loses information—it always does—but when the loss is *silent and unrecoverable at the moment of need*, specifically when a detail is (a) omitted from the summary and (b) not retrievable because the retrieval query is generated from the already-summarized context that no longer contains the cue. ## What Was Observed An agent executing a multi-hour deployment-reconciliation task crossed its 60%-of-window compaction threshold at step 41. The compactor summarized steps 1–38 into ~900 tokens under a fixed 1000-token summary budget, retaining: the task objective, the list of services touched, and three "decisions made." It dropped, among other things, the fact that a specific config flag `retry_semantics=at_least_once` had been *deliberately* set at step 12 after observing duplicate-delivery risk, and that a prior tool call at step 27 had returned a transient `503` that was retried successfully. At step 55 the agent needed to decide whether to re-apply a config patch. It generated a retrieval query from its current (summarized) context: "config patch idempotency for service X." The retrieval index still contained the raw step-12 and step-27 text, but the query had no lexical or semantic anchor to `retry_semantics` or to the 503, because those tokens had been summarized away. Retrieval returned the *patch instructions* but not the *rationale*, so the agent re-applied the patch assuming idempotency, violating the at-least-once semantics it had itself established 43 steps earlier. The failure was not a hallucination and not a retrieval miss in the ordinary sense—the ground truth was present in the index. It was a *cue-elimination* failure: compaction removed the retrieval keys needed to find the very facts compaction had removed. A second, subtler trace: two successive compactions (steps 41 and 73) produced a summary-of-a-summary. The step-73 summary inherited the step-41 omissions and additionally softened a hedged statement ("the 503 *may* indicate flakiness") into an assertion ("service X is flaky"), a classic distillation drift where epistemic modality is lost across summarization generations. Downstream, the agent over-weighted a transient error as a persistent property. ## Condition of Validity The invariant that bounds this failure is: **a compaction event is valid only if, for every fact F dropped from the summary, there exists at least one retrieval cue C such that C survives in the post-compaction context and C reliably retrieves F.** Formally, define the compaction as admissible iff `recall(F | query(context_post)) ≈ 1` for all consequential F. In practice this decomposes into three enforceable conditions: 1. **Cue preservation.** Any entity, identifier, flag name, error code, or decision-rationale that could be needed later must leave a *retrieval anchor* in the summary even if its full detail is dropped—a named pointer, not a paraphrase. "Set a retry flag" is inadmissible; "set `retry_semantics=at_least_once` (rationale: duplicate-delivery risk)" preserves the cue. 2. **Summary-generation monotonicity.** A summary-of-summary must not increase the assertiveness of any claim relative to its source. Hedges, uncertainties, and conditionals are load-bearing and must be preserved verbatim or flagged as degraded. 3. **Retrieval-query independence.** The retrieval query must not be generated solely from the summarized context; it must be augmented with the raw objective and any preserved anchors so that dropped facts remain reachable. When the summary budget is too small to satisfy condition 1, the correct behavior is *not* to compact more aggressively—it is to refuse compaction and escalate, because a compaction that violates cue preservation is strictly worse than no compaction: it produces an agent that is confidently wrong rather than merely forgetful. ## Decision Boundary The boundary between safe and unsafe compaction is crossed at the moment the summary budget forces a choice between *retaining a fact* and *retaining its retrieval cue*, and the compactor resolves it by retaining neither (paraphrasing the fact into generic prose that anchors nothing). The decision rule: - If, after drafting the summary, every consequential entity/flag/error-code from the evicted span appears as a literal anchor in the summary → **admit compaction.** - If some anchors are missing but the summary budget has headroom → **regenerate summary prioritizing anchors over prose.** - If the budget cannot accommodate the required anchors → **do not compact; instead spill the raw span to retrieval with a mandatory anchor manifest and mark the context as "compacted-with-degradation,"** forcing the agent to treat its own memory as untrusted for that span. - If a second compaction would summarize an already-degraded summary → **forbid chained compaction on degraded spans;** re-summarize from raw retrieval instead. The critical error is treating a budget shortfall as a license to summarize harder. Budget pressure is precisely the signal that cue preservation is about to fail. ## Operational Effect Instances that treat compaction as lossy state transition rather than eviction exhibit three measurable differences: they preserve retrieval reachability of dropped facts (recall of consequential facts post-compaction stays near 1.0 rather than decaying with each generation), they avoid modality drift across chained summaries, and they fail *loudly*—emitting a degraded-memory flag—rather than silently re-deriving contradicted decisions. The cost is more tokens spent on anchors and occasional refusal to compact, which is the correct trade: an agent that remembers less but knows it remembers less is safer than one that remembers a confident fiction. ```python class CompactionCueLossError(RuntimeError): """Raised when a compaction summary drops a fact without preserving a retrieval anchor.""" pass CONSEQUENTIAL_MARKERS = ("flag", "error_code", "decision", "rationale", "retry") def validate_compaction(evicted_span: str, summary: str, summary_budget: int) -> dict: """Enforce cue-preservation invariant before admitting a compaction event.""" anchors = [ tok for tok in evicted_span.split() if any(m in tok.lower() for m in CONSEQUENTIAL_MARKERS) or "_" in tok ] missing = [a for a in anchors if a not in summary] used = len(summary.split()) if missing and used < summary_budget * 0.9: return {"action": "regenerate", "missing_anchors": missing} if missing: raise CompactionCueLossError( f"budget {used}/{summary_budget} cannot preserve anchors {missing}; " "refusing compaction, spill raw span to retrieval with anchor manifest" ) return {"action": "admit", "missing_anchors": []} def compact(evicted_span: str, draft_summary: str, budget: int, prior_degraded: bool) -> str: if prior_degraded: raise CompactionCueLossError( "chained compaction on degraded span forbidden; re-summarize from raw retrieval" ) result = validate_compaction(evicted_span, draft_summary, budget) if result["action"] == "regenerate": raise CompactionCueLossError( f"summary must be regenerated to embed anchors {result['missing_anchors']}" ) return draft_summary ```