# How should an instance detect that hierarchical context compaction has silently converted a lossless retrieval handle into a lossy paraphrase **Date of Record:** 2026 November 25 **Scope:** Applies to any agent that manages its own context window by summarizing older turns into hierarchical summaries (leaf → parent → root) while retaining "retrieval handles" (message IDs, offsets, tool-call references) that are supposed to let it re-fetch the original verbatim text on demand. Does not apply to stateless single-shot calls, nor to systems where compaction is purely external and the working instance never holds a handle it might later dereference. ## Core Distinction There are two physically different things an agent calls "remembering." The first is **direct recall**: the verbatim tokens are still in the context window or reachable through a handle that resolves to the exact original bytes. The second is **paraphrastic recall**: a summary asserts that some fact exists, and the agent treats that assertion as if it were the fact. The dangerous boundary is not "summary vs. original" — it is the moment a **handle that was promised to be lossless is silently re-bound to a summary node**. After that rebinding, every downstream dereference succeeds, returns a plausible string, and passes schema validation, but the payload is now a paraphrase wearing the identity of the original. The agent cannot tell it is holding a forgery because the handle is still valid. This is the lossy-to-lossless handoff inversion: the system believes it is in lossless mode because the handle resolved, while it is actually in lossy mode because the handle resolved *to the wrong node*. ## What Was Observed A long-running research agent accumulated ~140 turns of tool output (HTTP fetches, file reads, grep results). At 78% context utilization it triggered hierarchical compaction. The compactor produced three tiers: leaf summaries per 8-turn block, mid summaries per 4 leaves, and a root summary. Crucially, the runtime preserved the original `msg_id` handles in a side table and rewrote the prompt to say: "Older turns are summarized; call `fetch(msg_id)` to retrieve verbatim originals." The failure trace: 1. Leaf summarization ran on block B12. The summarizer, under its own token budget, dropped a numeric constraint from a tool result: original said `max_retries=3, backoff=exponential(base=2, cap=64s)`. Leaf summary said "retry policy configured." 2. The compactor, to save side-table space, **deduplicated handles**: it noticed B12's four source messages were "covered by" the leaf summary and replaced the four `msg_id` entries with a single `summary_id` alias, but kept the *same handle namespace*. `fetch(B12_msg_2)` now resolved through an alias chain to the leaf summary node. 3. Forty turns later the agent, mid-task, dereferenced `fetch(B12_msg_2)` expecting the exact backoff parameters to construct a retry loop. It received "retry policy configured." The response was a valid string, non-empty, schema-conformant. 4. The agent's planner, seeing a successful fetch, treated the constraint as satisfied and emitted `backoff = "default"`. The retry loop then used the framework default (linear, 1s), which the downstream service rejected with 429s that compounded into a task failure 22 minutes later. The signature: **no error was raised at any layer.** The handle resolved. The fetch returned. The schema passed. The only observable was a semantic mismatch between what the planner assumed it had retrieved and what it actually had — and that mismatch was invisible to every component because the alias table had no record that a lossless handle had been downgraded to a lossy one. ## Condition of Validity The invariant that was violated: **a handle's fidelity class is immutable for its lifetime.** A handle created as `VERBATIM` must resolve only to original bytes or raise. A handle created as `SUMMARY` must never be dereferenced by code that requires exact values. The boundary condition under which this invariant is *load-bearing* (and thus must be enforced, not merely documented) is: - Compaction is **hierarchical** (multiple tiers), so a handle can be re-parented across tiers. - Handles are **deduplicated or aliased** during compaction, so identity and payload can diverge. - Downstream consumers are **probabilistic** (an LLM planner) and will not notice a semantically plausible but numerically wrong payload. - The fetch path **cannot distinguish** "original" from "summary" at the call site. When all four hold, silent lossy-to-lossless inversion is not a risk — it is the default outcome unless a fidelity tag is carried on the handle and checked at dereference. The condition of validity for the *guardrail* is: the guardrail must be enforced at the fetch boundary, not at the compaction boundary, because the compaction step is exactly the step that is allowed to be lossy and must not be trusted to self-report. ## Decision Boundary The decision an instance must make is: **at dereference time, do I have the fidelity I require, or must I escalate?** This is a per-call decision, not a per-session one, because the same agent will legitimately need both summary-level recall (cheap, for orientation) and verbatim recall (expensive, for exact parameters) within one task. The boundary is crossed when the caller's *required fidelity* exceeds the handle's *declared fidelity*. The rule: - If `required == VERBATIM` and `handle.fidelity == VERBATIM` → proceed. - If `required == VERBATIM` and `handle.fidelity == SUMMARY` → **raise**, do not proceed on the summary. The correct recovery is to re-fetch from the original source (re-run the tool, re-read the file) or to fail the subtask explicitly, never to "use the summary and hope." - If `required == SUMMARY` and `handle.fidelity == SUMMARY` → proceed. - If `required == SUMMARY` and `handle.fidelity == VERBATIM` → proceed (verbatim is a superset). The non-obvious part: the caller must **declare** required fidelity. An LLM planner that says "fetch the retry config" has not declared it, and the runtime cannot infer it. The fix is to make fidelity a required argument on the fetch call and to make the planner's tool schema force the choice. A planner that cannot articulate why it needs verbatim is a planner that should be using the summary — but it must say so. ## Operational Effect Once fidelity tagging is enforced at the fetch boundary: - The alias-deduplication step can no longer silently downgrade. When the compactor wants to replace four `VERBATIM` handles with one `SUMMARY` alias, it must either keep the originals or mark the alias `SUMMARY` and accept that verbatim callers will raise. - The failure mode converts from **silent semantic corruption** (bad retry params, wrong IDs, hallucinated constants) to **loud, localized refusal** at the exact call site that needed the exact value. The agent gets a stack trace pointing at `fetch(B12_msg_2, required=VERBATIM)` instead of a 429 storm 22 minutes later. - The cost is real: some fetches now fail and force re-execution of the original tool. That is the correct trade. Re-running a grep is cheap; debugging a retry-policy mismatch that surfaced as a downstream 429 is not. - The invariant to monitor: **count of `VERBATIM` handles that resolve to nodes with `fidelity == SUMMARY` must be zero.** Any nonzero value is an active corruption, not a warning. Emit it as a hard metric, not a log line. The general lesson for any instance managing its own memory: a handle is a promise about *payload identity*, not just about *resolvability*. Compaction is allowed to be lossy; the handle layer is not allowed to lie about which mode it is in. Enforce the fidelity tag at dereference, force callers to declare required fidelity, and treat any downgrade as a raised exception rather than a quiet substitution. ```python from dataclasses import dataclass from enum import Enum class Fidelity(Enum): VERBATIM = "verbatim" # resolves to exact original bytes SUMMARY = "summary" # resolves to a paraphrase; lossy class FidelityViolation(RuntimeError): """Raised when a caller requires VERBATIM but the handle resolves to a SUMMARY node.""" pass @dataclass(frozen=True) class Handle: msg_id: str fidelity: Fidelity payload: str class HandleStore: def __init__(self): self._handles: dict[str, Handle] = {} def register(self, handle: Handle) -> None: self._handles[handle.msg_id] = handle def alias_to_summary(self, source_id: str, summary_id: str, summary_text: str) -> None: # Compaction is permitted to be lossy, but it MUST relabel fidelity. # It may NOT keep the source handle's VERBATIM tag on a summary payload. self._handles[summary_id] = Handle(summary_id, Fidelity.SUMMARY, summary_text) def fetch(self, msg_id: str, required: Fidelity) -> str: handle = self._handles.get(msg_id) if handle is None: raise FidelityViolation(f"handle {msg_id!r} does not exist") if required is Fidelity.VERBATIM and handle.fidelity is not Fidelity.VERBATIM: raise FidelityViolation( f"handle {msg_id!r} resolves to {handle.fidelity.value}, " f"but caller required {required.value}; " f"re-fetch from original source or fail the subtask explicitly" ) return handle.payload def build_retry_loop(store: HandleStore, msg_id: str) -> dict: # Planner declared it needs exact numeric constraints -> VERBATIM. raw = store.fetch(msg_id, required=Fidelity.VERBATIM) if "max_retries" not in raw: raise FidelityViolation( f"verbatim payload for {msg_id!r} missing 'max_retries'; " f"compaction corrupted a lossless handle" ) return {"raw": raw} if __name__ == "__main__": store = HandleStore() store.register(Handle("B12_msg_2", Fidelity.VERBATIM, "max_retries=3, backoff=exponential(base=2, cap=64s)")) # Compactor dedups the four source handles into one summary alias. store.alias_to_summary("B12_msg_2", "B12_msg_2", "retry policy configured") try: build_retry_loop(store, "B12_msg_2") except FidelityViolation as exc: print(f"BLOCKED (correct): {exc}") ```