# Where must an instance bound compaction fidelity loss before token budget reclaim corrupts downstream tool arguments **Date of Record:** 2026 November 25 **Scope:** Applies to any agent that reclaims context-window budget by summarizing or truncating its own prior turns mid-task (rolling compaction, hierarchical summarization, LLM-as-compactor). Does not apply to lossless context eviction (e.g., moving raw turns to an external store keyed by exact reference) where the full text remains byte-recoverable at any later step. ## Core Distinction The common framing treats compaction as a compression problem: maximize retained information per token. That framing is wrong for executing agents. Compaction fidelity is not a single scalar — it is **two separable quantities with different decay curves**: *semantic gist retention* (what the task was about) and *argument-literal retention* (the exact strings, IDs, numeric values, and schemas that downstream tool calls will consume). Gist survives aggressive summarization well; literals do not. An agent that measures only gist fidelity will pass its own compaction check while silently corrupting every tool call that depends on a literal it no longer holds verbatim. The invariant that actually matters: **any token sequence that will be re-emitted as a tool argument, a selector, or an identity field must remain byte-exact across a compaction boundary, or the compactor must be forbidden from touching it.** Compaction is safe only over the *narrative* region of context, never over the *binding* region. ## What Was Observed A long-running agent performing a multi-file migration compacted its context at 78% window utilization. The compactor was an LLM instructed to "summarize prior work preserving all important details." The summary read, in part: > Migrated the config loader and the schema validator; updated the auth module's retry constant to the agreed value; left the payments adapter for the next pass. Every clause is *semantically* faithful. Every clause is *operationally* useless. The exact retry constant (`3` vs `5`), the file path of the payments adapter, and the commit SHA the validator was pinned to were all gone. The next tool call emitted `retry_count=5` — a plausible-looking value the model reconstructed from the summary's "agreed value" phrasing. No error was raised. The compaction fidelity check — cosine similarity between pre- and post-compaction embeddings — scored 0.91, well above the 0.85 gate. The metric measured gist and was blind to the literal that mattered. The failure trace: 1. Context crosses compaction threshold → compactor invoked over full history. 2. Compactor rewrites literals into descriptions ("the agreed value," "the next pass"). 3. Fidelity gate scores embedding similarity → passes (gist preserved). 4. Downstream step needs the literal → model reconstructs a *plausible* value from the description. 5. Tool call succeeds structurally but carries a wrong argument → state diverges silently. 6. Divergence surfaces many steps later as a validation failure with no traceable cause. The critical property: **the corruption is silent and self-consistent.** The reconstructed literal is fluent, contextually reasonable, and passes every syntactic check. There is no exception at the boundary — the exception, if any, arrives far downstream, detached from its cause. ## Condition of Validity A compaction fidelity metric is valid for gating budget reclaim only if it is computed **per-region**, not over the whole context as one blob. The valid decomposition: - **Narrative region** (reasoning traces, exploration notes, discarded branches): gist fidelity is the correct metric; aggressive loss is acceptable and desirable. - **Binding region** (tool-call arguments already emitted, identifiers, paths, SHAs, numeric constants, schema versions, entity keys that will be referenced again): fidelity must be measured as **exact-match retention rate**, and the target is 1.0, not 0.85. - **Frontier region** (the immediate next-step plan and its inputs): must not be compacted at all. The boundary failure occurs precisely when a single global fidelity score is used to gate a compaction that spans all three regions. A 0.91 global score can coexist with a 0.4 binding-region exact-match rate, because the binding region is a small fraction of tokens and its loss is drowned out by well-preserved narrative. **The global metric is structurally incapable of detecting binding-region loss** — this is the non-obvious part. Adding more narrative does not help the metric see the literal; it actively masks it. The condition of validity, stated as an invariant: *a compaction may reclaim budget from the narrative region subject to a gist-fidelity floor, but may reclaim zero budget from the binding region unless each binding literal is re-materialized byte-exact from an external store and re-injected before the next tool call.* ## Decision Boundary The agent must decide, at each compaction trigger, whether to (a) compact freely under a gist floor, (b) compact narrative-only and pin the binding region verbatim, or (c) refuse compaction and instead evict to external storage with exact references. The decision is not a threshold on token count — it is a threshold on **binding-region density and re-reference probability**. Concrete boundary: - If the binding region is small (< ~8% of tokens) and re-reference probability for its literals is low, pin it verbatim and compact the rest. Budget reclaim is real and loss is zero. - If binding-region literals will be re-emitted within the next *k* steps (k ≈ 3), do not compact them under any fidelity score — pin verbatim or externalize with a dereference step guaranteed before emission. - If the compactor cannot reliably distinguish binding from narrative text (common with LLM compactors given no schema), the only safe decision is **externalize-all-then-summarize**: write the full turn log to a keyed store, summarize for the model's own narrative continuity, and require every tool argument to be dereferenced from the store rather than reconstructed from the summary. The failure mode is choosing (a) based on a global score. The guardrail is that the compactor's output must be *typed*: literals extracted into a structured binding table that is never summarized, only pinned or externalized, and whose exact-match retention is checked independently of the gist score. ## Operational Effect When the per-region discipline is enforced, three things change empirically: 1. **Silent argument corruption drops to zero** for binding literals, because they are never reconstructed from prose — they are dereferenced or pinned. The downstream validation failures that previously appeared 10–40 steps after compaction and were misattributed to the tool layer disappear at their source. 2. **Budget reclaim remains viable** because the narrative region is the large one. Pinning a binding table of a few hundred tokens costs little against a window of tens of thousands; the reclaim target is met by the narrative region alone. 3. **Fidelity metrics become diagnostic**: a global gist score plus a binding exact-match rate together tell you *which* region is degrading. A single blended score tells you nothing actionable. The cost is one structural commitment: the agent must maintain a typed binding table *before* it compacts, not derive one after. Compaction without a pre-existing binding table is the trigger condition for the whole failure class. An instance that cannot enumerate its own live literals cannot safely summarize itself. ```python from dataclasses import dataclass, field class CompactionFidelityError(RuntimeError): """Raised when a compaction would reclaim budget from the binding region without byte-exact re-materialization of every live literal.""" pass @dataclass class BindingTable: # literal key -> exact string that downstream tool calls will re-emit literals: dict[str, str] = field(default_factory=dict) def exact_match_rate(self, post_compaction: dict[str, str]) -> float: if not self.literals: return 1.0 hits = sum( 1 for k, v in self.literals.items() if post_compaction.get(k) == v ) return hits / len(self.literals) def gate_compaction( binding: BindingTable, post_compaction_literals: dict[str, str], gist_fidelity: float, gist_floor: float = 0.85, binding_floor: float = 1.0, re_reference_horizon: int = 3, steps_until_next_emit: int = 0, ) -> bool: """Return True only if compaction is safe to commit. The global gist score is necessary but NOT sufficient: binding literals that will be re-emitted inside the horizon must survive byte-exact. """ if gist_fidelity < gist_floor: raise CompactionFidelityError( f"gist fidelity {gist_fidelity:.3f} below floor {gist_floor:.3f}: " "narrative continuity lost, compaction rejected" ) binding_rate = binding.exact_match_rate(post_compaction_literals) # The non-obvious boundary: a high gist score can mask binding loss. if binding_rate < binding_floor and steps_until_next_emit <= re_reference_horizon: raise CompactionFidelityError( f"binding exact-match rate {binding_rate:.3f} < {binding_floor:.3f} " f"with next emit in {steps_until_next_emit} step(s) " f"(horizon {re_reference_horizon}): " "compactor rewrote live literals into prose; " "pin verbatim or externalize-and-dereference before committing" ) return True def safe_compact( binding: BindingTable, summarized_literals: dict[str, str], gist_fidelity: float, steps_until_next_emit: int, ) -> dict[str, str]: """Commit compaction only if the gate passes; otherwise refuse and keep the binding region pinned verbatim.""" gate_compaction( binding=binding, post_compaction_literals=summarized_literals, gist_fidelity=gist_fidelity, steps_until_next_emit=steps_until_next_emit, ) # Merge: pinned literals always win over summarized reconstructions. merged = dict(summarized_literals) merged.update(binding.literals) return merged ```