# Where must an instance reconcile a lossy compaction summary against a retrieval-backed restoration before resuming a tool-augmented task **Date of Record:** 2026 November 25 **Scope:** Applies to long-running tool-augmented agents that reclaim context budget by replacing a contiguous span of the transcript with a generated summary, then later re-inject original turns on demand via retrieval. Does not apply to systems that only truncate (drop without summarizing) or to pure KV-cache eviction with no semantic replacement. ## Core Distinction There are two structurally different ways a compaction policy loses information, and they demand different restoration strategies: - **Summarization loss** is *semantic and lossy by design*. The compactor emits a paraphrase that preserves gist but discards verbatim tokens: exact argument strings, IDs, numeric values, and the precise ordering of tool calls. This loss is *irrecoverable from the summary alone* — the summary is the only surviving representation of that span unless retrieval exists. - **Retrieval loss** is *stochastic and index-dependent*. When the agent later re-fetches original turns by embedding similarity to its current query, recall is imperfect: the turn that actually matters (a raw tool output) may not be the turn the retriever ranks highest, because the query is phrased in the agent's post-compaction vocabulary, not the original's. The boundary failure is the assumption that these compose cleanly: that "summarize now, retrieve later" is a safe two-phase substitution. It is not, because the summary silently *rewrites the retrieval key space*. Once the verbatim span is gone from context, the agent's subsequent queries are generated from the summary's vocabulary, so retrieval is keyed against paraphrased terms while the index still holds original terms. The two representations drift apart, and the agent cannot tell that it is now querying a shifted distribution. ## What Was Observed A task-execution agent was given a 40-step refactor workflow over a codebase, with a compaction threshold at 70% of the context window. At step 22 the policy fired: turns 1–18 were replaced by a ~400-token summary; turns 19–22 remained verbatim. The summary contained the line: *"Earlier, the agent inspected the auth module and confirmed the token refresh interval."* The original turn 9 had contained a raw tool output: ``` {"file": "auth/session.py", "refresh_interval_s": 900, "grace_s": 30} ``` At step 27 the agent needed to write a test asserting the exact refresh interval. Its query to the retrieval tool was generated from the summary: `"token refresh interval auth module"`. The retriever returned, ranked first, the *summary itself* (it was semantically closest and still in context) and, ranked second, an unrelated turn 14 that mentioned "auth" in a stack trace. The original turn 9 ranked fourth, below the top-k cutoff of 3. The agent then wrote `refresh_interval_s == 60` — a plausible round number reconstructed from the summary's vague phrasing — and the test failed downstream against the real 900s value. The failure was not a retrieval miss in the naive sense (turn 9 was retrievable); it was that the summary *poisoned the query* so the correct turn fell out of top-k, and the agent had no signal that its reconstruction was a guess rather than a recall. A second, subtler trace: at step 31, a re-compaction summarized turns 19–30, which included the agent's own step-27 reasoning. The fabricated "60s" belief was now *inside the summary*, laundered into apparent fact. A subsequent retrieval of turn 9 would have contradicted it, but retrieval was never triggered because the summary asserted the value confidently. The hallucination had achieved persistence by being compacted. ## Condition of Validity The "summarize-then-retrieve" restoration is only sound under a conjunction of conditions, and the policy is invalid the moment any one fails: 1. **Key-space stability.** The vocabulary used to query retrieval must match the vocabulary of the indexed spans. This holds only if the agent queries using *verbatim anchors* (identifiers, paths, literal values) rather than summary-derived paraphrase. Once compaction removes the verbatim anchors, this condition is already violated. 2. **Retrieval sufficiency with margin.** The correct original turn must rank within top-k *with a score margin* over distractors, not merely appear. A correct turn at rank k with a near-tied distractor at rank k+1 is a coin flip under any temperature. 3. **No self-summarization of unverified claims.** A claim the agent generated (a reconstructed number, an inferred path) must not be compacted into the summary until it has been *verified against a retrieved original or a tool re-call*. Otherwise the summary becomes a trust-laundering layer. 4. **Restoration is checked, not assumed.** The agent must treat a retrieved turn as *evidence to reconcile* against the summary, not as confirmation of it. Reconciliation requires detecting disagreement, which requires that the summary retain enough verbatim anchors to disagree *with*. The observed failure violated (1) and (3) simultaneously and could not detect (4) because the summary had stripped the anchor (`900`) that would have made reconciliation possible. ## Decision Boundary The operational question is not "should we compact?" but "at what point does a summary stop being a *pointer* to retrievable ground truth and become an *unfalsifiable assertion*?" The boundary is crossed when the compactor drops the last verbatim token that could contradict a later reconstruction. Concretely, a span may be summarized lossily only if, for every *load-bearing fact* in that span (values later consumed by tool calls, identifiers used as arguments, ordering constraints), at least one of the following survives: - the verbatim token is retained in the summary (an *anchor*), or - the original turn is guaranteed to rank in top-k for the anchor-keyed query, or - the fact is re-derivable by a cheap tool re-call at consumption time. If none holds, the fact is *orphaned*: it exists only as paraphrase, and paraphrase cannot be falsified. The decision rule: **any fact whose later reconstruction error would be silent (a wrong number that still "looks right") must retain a verbatim anchor or a forced re-call path.** Facts whose reconstruction error would be loud (a missing file that errors immediately) may be safely orphaned. ## Operational Effect When this boundary is respected, compaction becomes a reversible compression: the summary is a lossy index into a lossless store, and the agent's restoration step is a *reconciliation* that can fail loudly. When it is violated, compaction becomes an irreversible rewrite that manufactures confident falsehoods and then protects them by re-summarizing. The guardrail is a **compaction contract** enforced at summarize time: the compactor must classify each candidate fact, refuse to orphan a silent-failure fact without an anchor, and stamp the summary with the anchor set so that the restoration step can force a retrieval keyed on those anchors rather than on the agent's paraphrase. The restoration step must then reconcile retrieved verbatim against the summary and raise on disagreement rather than silently preferring either. ```python from dataclasses import dataclass, field from typing import Optional class OrphanedFactError(RuntimeError): """Raised when a load-bearing fact is summarized without a verbatim anchor or a guaranteed re-derivation path, making later reconstruction unfalsifiable.""" pass class ReconciliationError(RuntimeError): """Raised when a retrieved original turn contradicts the compaction summary and the agent cannot resolve the disagreement from evidence.""" pass @dataclass class Fact: key: str # e.g. "auth/session.py:refresh_interval_s" value: str # e.g. "900" silent_failure: bool # True if a wrong reconstruction would not error loudly verbatim_anchor: Optional[str] = None # exact token retained in summary rederivable: bool = False # cheap tool re-call available at use time @dataclass class CompactionSummary: text: str anchors: dict = field(default_factory=dict) # key -> verbatim token facts: list = field(default_factory=list) def compact(facts: list[Fact], paraphrase: str) -> CompactionSummary: """Enforce the compaction contract: no silent-failure fact may be orphaned.""" anchors = {} for f in facts: if f.silent_failure and not f.verbatim_anchor and not f.rederivable: raise OrphanedFactError( f"fact {f.key!r} has silent-failure semantics but no verbatim " f"anchor and no re-derivation path; compacting it would make a " f"later wrong reconstruction (e.g. {f.value!r} -> guessed) undetectable" ) if f.verbatim_anchor: anchors[f.key] = f.verbatim_anchor return CompactionSummary(text=paraphrase, anchors=anchors, facts=facts) def restore(summary: CompactionSummary, key: str, retrieved: Optional[str]) -> str: """Reconcile a retrieved verbatim value against the summary before use.""" anchor = summary.anchors.get(key) if retrieved is None: if anchor is None: raise ReconciliationError( f"cannot restore {key!r}: no anchor in summary and retrieval " f"returned nothing; refusing to reconstruct from paraphrase" ) return anchor if anchor is not None and retrieved != anchor: raise ReconciliationError( f"retrieved {key!r}={retrieved!r} contradicts summary anchor " f"{anchor!r}; resolve from evidence before proceeding" ) return retrieved # --- trace of the observed failure --- facts = [Fact(key="auth/session.py:refresh_interval_s", value="900", silent_failure=True, verbatim_anchor=None, rederivable=False)] # This call raises: the 900 was paraphrased away, so the later "60" guess # could never be contradicted. The contract refuses the compaction. compact(facts, "confirmed the token refresh interval") ```