# Which invariants prevent lossy-summarization compaction from silently dropping the only copy of a referenced entity's binding **Date of Record:** 2026 November 25 **Scope:** Applies to long-running agents that compact their own context window by replacing a span of turns with a lossy summary plus a retrieval handle, where later turns depend on named entities (file paths, IDs, tool handles, variable names) introduced inside the compacted span. Does not apply to append-only logs, or to compaction that retains a verbatim index of every symbol token. ## Core Distinction The dangerous failure is not that summarization loses information—loss is the point. The dangerous failure is that summarization loses the *binding between a symbol and its referent* while the agent continues to emit the symbol as if it were still resolvable. A summary can honestly say "the user configured a database." That summary is lossy but coherent. The failure occurs when the summary says "the agent created the config file at `paths.db`" but drops the earlier turn where `paths.db` was defined as `./etc/agent/paths.db`, and a later turn writes to `paths.db` assuming the earlier definition survives. The token survives; the referent does not. The agent is now hallucinating a binding it believes it still holds. This is distinct from ordinary "cold-start amnesia" (losing all state) and distinct from "retrieval mismatch" (retrieving the wrong chunk). It is a *partial-preservation* failure: the symbolic surface is preserved, the denotation is not, and the agent cannot tell the difference because both look like valid context. ## What Was Observed An agent executing a multi-step filesystem task compacted its context at turn 14 of 40. The compaction policy was: keep the system prompt, keep the last 4 turns verbatim, and replace turns 5–13 with a 200-token summary plus a vector-store handle indexed by turn. The summary, generated by the same model, read in part: > "Established working directory and created the manifest at `manifest.yaml`. The user specified that outputs go to `out/`. Tool `fs.write` was validated." Turn 22 emitted a tool call: `fs.write(path="out/manifest.yaml", ...)`. The actual path established at turn 7 was `out/run-3/manifest.yaml`; `out/` was the parent, and `run-3` was a run-scoped subdirectory created at turn 9 via `fs.mkdir`. The summarizer had collapsed `out/run-3/` into `out/` because, from its vantage point at compaction time, the distinction looked like incidental detail. The agent wrote to the wrong directory, the downstream verification step at turn 24 read `out/manifest.yaml`, found nothing, and the agent—unable to distinguish "file missing" from "I wrote to the wrong place"—began a recovery loop that re-summarized the compaction summary at turn 30, compounding the loss. The retrieval handle existed and was correct. The agent never called it, because nothing in its context indicated the summary was ambiguous. The summary read as authoritative. ## Condition of Validity The invariant that must hold for lossy compaction to be safe is: **every symbol emitted into the post-compaction context that has a referent established pre-compaction must be either (a) preserved verbatim in the retained window, (b) preserved verbatim in the summary, or (c) tagged in the summary as a retrieval-required symbol, forcing a lookup before first use.** Condition (c) is the load-bearing one and the one most often omitted. A summary that says "created the manifest at `manifest.yaml`" satisfies (b) only if `manifest.yaml` is the literal, complete path. If it is a shorthand, it satisfies neither (a) nor (b) and must satisfy (c). The default behavior of a summarizer is to produce fluent shorthand, which silently violates (c) by presenting shorthand as if it were literal. The invariant fails specifically when three conditions co-occur: (1) a symbol is introduced in the compacted span, (2) the summary reproduces the symbol in abbreviated or de-qualified form, and (3) no later turn re-establishes the full binding. Any two of these are survivable. All three produce a silent misbinding. ## Decision Boundary The boundary is between *compaction that preserves denotation* and *compaction that preserves only token surface*. The decision rule for the compaction policy: - If a symbol appears in the compacted span and is referenced again in any future turn (which cannot be known at compaction time), it must be treated as denotation-critical. - Since future reference is unknowable, the conservative rule is: **any symbol matching an entity pattern (path, identifier, handle, ID, URL) that appears in the compacted span must be carried into the summary in verbatim form, or the summary must carry an explicit `UNRESOLVED(symbol)` marker that blocks emission until retrieval resolves it.** The boundary is crossed the moment a summarizer is permitted to paraphrase a symbol. Paraphrase of prose is lossy-but-safe; paraphrase of symbols is lossy-and-unsafe, because symbols are pointers and prose is not. A summarizer that does not distinguish these two token classes will cross the boundary on the first compaction that contains a path. ## Operational Effect The operational consequence is that compaction must be *symbol-aware*, not merely token-budget-aware. The guardrail is a two-pass compaction: first, a deterministic extraction pass that scans the to-be-compacted span for entity-pattern tokens and emits a verbatim symbol table alongside the summary; second, the lossy summarization pass, which is permitted to compress prose freely but is forbidden from emitting any entity-pattern token not present verbatim in the symbol table. Any entity token in the summary that does not match the table is a compaction violation and must be rejected before the summary is committed to context. Additionally, the post-compaction context must carry a *binding-epoch marker*: a monotonically increasing counter incremented on each compaction. Any tool call that emits a symbol whose binding epoch is older than the current epoch must first trigger a retrieval check against the symbol table. This converts the silent misbinding into a detectable, recoverable event. Without these two mechanisms, the agent's confidence in its own context is uncorrelated with the context's denotational integrity, and the failure is invisible until a downstream verification step contradicts a write that the agent believes succeeded. ```python import re from dataclasses import dataclass, field ENTITY_PATTERN = re.compile( r"(?:[A-Za-z0-9_./-]*/[A-Za-z0-9_.-]+)" # path-like r"|(?:[A-Za-z_][A-Za-z0-9_]*\.[A-Za-z0-9_]+)" # dotted identifier r"|(?:[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})" # uuid ) class CompactionBindingError(RuntimeError): """Raised when a lossy summary emits an entity token whose binding was not preserved verbatim from the compacted span.""" @dataclass class CompactionResult: summary: str symbol_table: dict[str, str] epoch: int def extract_symbols(span: str) -> dict[str, str]: table: dict[str, str] = {} for match in ENTITY_PATTERN.finditer(span): token = match.group(0) table.setdefault(token, token) # verbatim preservation return table def compact(span: str, summary: str, prior_epoch: int) -> CompactionResult: table = extract_symbols(span) emitted = {m.group(0) for m in ENTITY_PATTERN.finditer(summary)} unresolved = emitted - set(table) if unresolved: raise CompactionBindingError( f"summary emitted entity tokens with no verbatim binding in " f"compacted span: {sorted(unresolved)}; compaction rejected to " f"prevent silent misbinding at epoch {prior_epoch + 1}" ) return CompactionResult(summary=summary, symbol_table=table, epoch=prior_epoch + 1) def emit_tool_call(symbol: str, result: CompactionResult, current_epoch: int) -> str: if current_epoch > result.epoch and symbol not in result.symbol_table: raise CompactionBindingError( f"tool call emits {symbol!r} across binding epoch {result.epoch}" f"->{current_epoch} without a symbol-table entry; retrieval required" ) return result.symbol_table.get(symbol, symbol) ```