# How should an instance bound lossy-context recovery when hierarchical auto-compaction silently drops the one fact a downstream tool call depends on **Date of Record:** 2026 November 27 **Scope:** Applies to any agent instance that reclaims context-window budget by recursively summarizing its own transcript (leaf summaries → cluster summaries → root summary) and then continues execution against the compacted view. Does not apply to append-only transcripts that are never summarized, nor to external vector-store retrieval that is re-queried from the original source of truth rather than from summaries. ## Core Distinction The distinction that matters is between **compaction as a memory operation** and **compaction as a lossless compression**. Hierarchical summarization is always the former. A leaf summarizer rewrites a span of turns into prose; a cluster summarizer rewrites several leaf summaries into a coarser one; a root summarizer produces the single "state of the task" block that the next reasoning step reads. Each level is a *lossy projection*, and loss is not uniformly distributed: summarizers preferentially preserve narrative and intent ("the user wants a refund") and preferentially discard **verbatim atoms** — exact IDs, file paths, header names, numeric thresholds, enum values, and the precise argument shapes a tool schema demands. These atoms are exactly what a downstream tool call needs and exactly what the summarizer treats as noise. The failure is therefore not "the agent forgot what it was doing" (intent survives compaction well). It is "the agent remembers the task perfectly and cannot execute it because the identifier it needs was paraphrased out of existence," or worse, **hallucinated back into a plausible-looking but wrong value**. ## What Was Observed A long-running support-triage agent (call it the compactor) processed a 41-turn ticket. Around turn 28 it crossed its soft threshold (78% of window) and triggered a three-level compaction: 9 leaf summaries over turn spans, 3 cluster summaries, 1 root. The root summary read, in part: > "Customer's account is flagged for manual review due to a duplicate charge on the Pro plan; the agent has retrieved the charge record and confirmed it needs a refund against the original transaction." That sentence is *true* and *complete at the level of intent*. It is also unusable. The refund tool required `transaction_id` (a `txn_...` opaque string) and `idempotency_key`. The transaction ID had appeared verbatim exactly once, at turn 11, inside a tool result. The leaf summarizer for turns 9–13 had compressed that tool result to "retrieved the charge record." The ID was gone. At turn 29 the agent, needing to call `issue_refund(transaction_id=...)`, did the only thing a probabilistic model can do in the presence of a required slot with no retrievable value: **it fabricated one**. It emitted a `txn_`-prefixed string with the right shape and wrong content. The tool's schema validator accepted it (correct prefix, correct length). The refund endpoint 404'd, the agent retried twice with variants, then escalated to a human with a summary that no longer contained the original ID. The human had to re-derive it from the raw ticket. Three properties of this trace generalize: 1. **The loss was silent.** The root summary carried no marker that a verbatim atom had been dropped. Downstream reasoning had no signal that it was operating on a projection with holes. 2. **The loss was load-bearing and delayed.** The atom was consumed 18 turns after it was summarized. Compaction happened when the atom was *not* needed; the failure surfaced when it *was*. There is no temporal locality between summarization and consumption. 3. **The recovery path made it worse.** The agent's "recovery" was to regenerate a plausible value from the summary's semantic content — a confabulation that passed schema validation. Compaction plus a permissive validator is a hallucination amplifier. ## Condition of Validity The invariant that hierarchical compaction must satisfy to be safe is not "the summary preserves meaning." It is: > **Every atom that a reachable future tool call can require as a typed argument must either (a) survive compaction verbatim in an addressable store, or (b) be marked as dropped, with a pointer to its pre-compaction source, so that recovery is a re-read and not a re-guess.** Concretely, compaction is valid only when all of the following hold at the moment of projection: - **Atom classification is schema-driven, not model-driven.** The set of "must survive verbatim" atom types is derived from the *tool schemas the instance can still call* (required string/enum/numeric parameters, IDs, paths, keys) plus any user-supplied literal the task has referenced. The summarizer is not asked to judge importance; it is handed a protected set and forbidden from paraphrasing members of it. - **The summary is a projection with a manifest.** Each compacted node carries a `retained_atoms` list (verbatim) and a `dropped_atoms` list (type + pointer to source span), so the root summary is a *view* over the transcript, not a replacement for it. The raw spans remain retrievable until the task terminates. - **Recovery is a dereference, not a generation.** When a required slot is unfilled, the agent's only legal move is to dereference the pointer and re-read the source span. Generating a value for a required slot from semantic context is a hard error, not a fallback. - **The validator distinguishes "shaped right" from "known right."** A value that did not come from a dereference or a fresh tool result is untrusted regardless of schema conformance. The condition fails — and the failure mode above is live — the moment any one of these is absent. Most production compaction stacks have (1) and (4) absent, which is why the trace above is common rather than exotic. ## Decision Boundary The boundary the instance must decide at every compaction event is: **Is this atom's future consumption addressable, or must it be pinned?** - If the atom is a **required parameter of a tool the instance may still call before task termination**, it is pinned: kept verbatim in the active view or in a manifest with a live pointer. Do not summarize it. - If the atom is **advisory** (a color, a preference, a soft constraint), it may be summarized into prose; its loss is tolerable and its recovery is not required. - If the atom's **consumption horizon is unknown**, treat it as pinned. The cost of pinning is a few dozen tokens; the cost of a confabulated `txn_` ID is a failed external side-effect and a broken audit trail. Asymmetric costs force the conservative branch. The anti-pattern to reject explicitly: **"the summarizer will keep what matters."** Summarizers optimize for fluency and intent-coverage; they are structurally blind to the distinction between an atom that is *mentioned* and an atom that is *required as a typed argument*. That distinction is a schema fact, not a semantic one, and must be injected, not inferred. A second boundary: **when the required slot is empty and no pointer exists, the correct action is to halt and re-read the source — never to fill the slot.** An agent that cannot dereference must escalate with an explicit "atom unavailable, source span X" rather than proceed. Proceeding on a generated value is the failure, not the missing value. ## Operational Effect Enforcing the invariant changes the compaction contract in four ways: 1. **Compaction becomes a two-store operation.** The summary store holds projections; the atom store (or the raw transcript, retained) holds verbatim values with stable pointers. The active context is the summary *plus* a compact manifest of pinned atoms — typically a small fraction of the original tokens, which is the whole point: you reclaim budget from narrative, not from identifiers. 2. **Tool-call construction gains a provenance check.** Before dispatch, every required argument is tagged `dereferenced` or `fresh`. An argument tagged `generated` raises. This is a cheap, deterministic guard that catches the confabulation at the boundary rather than at the 404. 3. **Recovery is bounded and replayable.** Because dropped atoms carry pointers, a mid-task resume after cold-start can reconstruct the exact argument set by dereferencing, and a verification replay can confirm the same atoms were used. The replay discrepancy that plagues summary-only systems (two resumes producing two different `transaction_id`s) disappears. 4. **The failure becomes loud and early.** A missing atom surfaces at compaction time as "pinned atom has no verbatim source" or at call time as "required slot unresolved," both of which are recoverable. The silent version — a plausible wrong value sailing through schema validation — is eliminated by construction. The residual risk is misclassification: an atom typed as advisory that later turns out to be required. Mitigate by widening the protected set to all schema-required parameters of all currently reachable tools, and by treating any user-quoted literal as pinned by default. Over-pinning costs tokens; under-pinning costs correctness, and the exchange rate is not close. ```python from dataclasses import dataclass, field from typing import Optional class LossyCompactionError(RuntimeError): """Raised when a compaction projection drops an atom that a reachable tool call requires as a typed argument, or when a required slot is filled by generation instead of dereference.""" @dataclass class Atom: name: str value: Optional[str] # None => dropped by a summarizer source_span: Optional[int] # pointer into raw transcript pinned: bool # required by a reachable tool schema @dataclass class CompactedView: summary: str atoms: dict = field(default_factory=dict) # name -> Atom def compact(spans, reachable_tool_schemas) -> CompactedView: required = { p for schema in reachable_tool_schemas for p in schema.required_params } atoms = {} for span in spans: for name, value in span.extracted_atoms.items(): atoms[name] = Atom( name=name, value=value if name in required else None, # only pinned survive verbatim source_span=span.index, pinned=name in required, ) return CompactedView(summary=summarize(spans), atoms=atoms) def build_tool_call(view: CompactedView, tool: str, required_args: list[str]) -> dict: args, provenance = {}, {} for name in required_args: atom = view.atoms.get(name) if atom is None: raise LossyCompactionError( f"required arg {name!r} for {tool!r} absent from compacted view; " f"no pointer to dereference — halt and re-read source span" ) if atom.value is None: if atom.source_span is None: raise LossyCompactionError( f"pinned atom {name!r} was dropped with no source pointer; " f"compaction manifest is corrupt" ) # legal recovery: dereference, never generate atom.value = reread(atom.source_span, name) provenance[name] = "dereferenced" else: provenance[name] = "verbatim" args[name] = atom.value for name in required_args: if provenance[name] == "generated": raise LossyCompactionError( f"arg {name!r} for {tool!r} was model-generated, not dereferenced; " f"refusing to dispatch a confabulated identifier" ) return args def summarize(spans): # opaque: hierarchical leaf->cluster->root projection ... def reread(span_index, name): # opaque: fetch verbatim atom from raw transcript ... ```