# What structural signals indicate that a lossless auto-compaction summarizer has silently degraded into lossy paraphrase **Date of Record:** 2026 November 26 **Scope:** Applies to long-horizon agents that auto-compact their own context window via an LLM-generated summary that is then substituted for the evicted span, and that claim "lossless" compaction (i.e., all task-relevant bindings survive). Does not apply to pure retrieval-based memory (vector store recall) or to externally-managed context truncation where no summarization model is invoked. ## Core Distinction A "lossless" auto-compaction strategy is not a summarizer that produces faithful text. It is a summarizer whose output preserves a specific, enumerable set of **bindings** — literal tokens that downstream steps will reference verbatim: file paths, identifiers, numeric constants, error strings, tool-call argument values, and the exact wording of user constraints. The failure mode is not "the summary is wrong." It is that the compaction model, under token pressure, shifts its objective from *preserving bindings* to *producing fluent paraphrase*, and paraphrase is a lossy transform on precisely the tokens that matter. The dangerous property is that the summary reads as correct to any reviewer (human or LLM) while having dropped the binding the next tool call needs. The distinction: **semantic fidelity is not the invariant; binding fidelity is.** ## What Was Observed A 40-step agent task (multi-file refactor) compacted at step 22. The evicted span contained the user constraint `do not touch vendor/legacy_parser.py` and a tool result returning the exact error `KeyError: 'tenant_id'`. The compaction summary read: > "The user asked for a refactor of the parsing layer while avoiding changes to legacy vendored code. An earlier tool call surfaced a missing-key error related to tenant identification." Both bindings were destroyed. `vendor/legacy_parser.py` became "legacy vendored code"; `'tenant_id'` became "tenant identification." At step 27 the agent edited `vendor/legacy_parser.py` (matching it via glob `**/*parser*.py`) and at step 31 grepped for `tenant identification`, which returned zero hits, causing it to conclude the error was already resolved. The structural tell was recoverable after the fact: the summary contained **zero quoted spans, zero file-path-shaped tokens, and zero digit-bearing identifiers**, despite the source span containing 14 of them. The compaction model had not been instructed to preserve bindings as a hard constraint; it optimized for compression ratio (source 6,200 tokens → summary 410 tokens, ~15:1) and paraphrase is the cheapest way to hit a ratio target. A second instance showed the inverse signature: a summary that *looked* lossless (it retained one path) but had **normalized** it — `./src/parse/reader.py` became `src/parse/reader.py`, dropping the `./` that a later `cd`-relative tool call depended on. Normalization is lossy even when the token survives. ## Condition of Validity The losslessness claim is valid **only if** the compaction step enforces a binding-preservation invariant checked against the source span, not against the summary's internal consistency. Concretely, the invariant holds iff, for every binding class B in the source span, the summary contains a token that is a *byte-exact substring match* for each source binding of class B. This is checkable mechanically without an LLM judge: - **Path bindings:** every string matching a path grammar (`[\w./-]+\.\w+`, or containing `/`) in the source must appear verbatim in the summary. - **Quoted-literal bindings:** every backticked or single/double-quoted span in the source must appear verbatim. - **Numeric/identifier bindings:** every token matching `[A-Za-z_][A-Za-z0-9_]*\d[A-Za-z0-9_]*` or any standalone number must appear verbatim. - **Constraint bindings:** sentences containing modal/negation markers (`do not`, `must`, `never`, `only`) must have their object noun-phrase preserved verbatim. If the summary fails this check, the compaction is **lossy by definition** regardless of how faithful it reads. The condition of validity is *structural*, not evaluative. This is why an LLM-judge "is this summary faithful?" check does not bound the failure: the judge shares the summarizer's paraphrase bias and will rate the `tenant_id` → "tenant identification" summary as faithful. ## Decision Boundary The decision boundary is: **does the compaction pipeline treat the binding set as a hard output constraint, or as a soft quality signal?** - If hard: the summarizer is run, then a **binding-diff verifier** extracts the binding set from the source span and asserts byte-exact presence in the summary. On miss, the pipeline must either (a) re-run compaction with the missing bindings pinned as must-include tokens, or (b) fall back to **verbatim-plus-summary** — keep the binding-bearing sentences raw and summarize only the connective prose. Never accept a summary that fails the diff. - If soft: losslessness is unprovable and the agent must not be allowed to take actions whose correctness depends on evicted bindings. In practice this means the agent must re-fetch (re-read the file, re-run the grep) before any action referencing a pre-compaction binding. The boundary is crossed the moment the pipeline accepts a summary on the basis of ratio + LLM-judge score alone. That combination is exactly the configuration that produced the `tenant_id` loss: high ratio, high judge score, zero binding coverage. A secondary boundary: **compaction must be scoped to a checkpoint, not to an arbitrary token window.** If the eviction boundary cuts mid-tool-call (evicting the call but keeping its result, or vice versa), no summary can restore the pairing. The boundary condition is that the evicted span must be *closure-complete*: every tool call paired with its result, every constraint sentence whole. A token-count-triggered compaction that fires mid-pairing is structurally unlossless before the summarizer even runs. ## Operational Effect The observable effect of a silently-lossy compaction is a **delayed, misattributed failure**: the agent does not error at compaction time; it errors 5–15 steps later when it acts on a paraphrased binding, and the trace points at the *action* step, not the *compaction* step. Debugging therefore chases the wrong layer. Two operational consequences follow: 1. **Compaction must emit a binding manifest** — the extracted binding set, attached to the summary as structured metadata, not prose. Downstream steps that reference a binding can then check the manifest: if the binding is in the manifest, the summary is trusted; if not, the step is forced to re-fetch. This converts a silent loss into a loud, local re-fetch. 2. **Compaction ratio must be capped by binding density, not by token count alone.** A span with 14 bindings in 6,200 tokens cannot be compressed 15:1 without dropping bindings; the achievable lossless ratio is bounded by binding density. The pipeline should compute a binding-density estimate and refuse to compress below the ratio that preserves all bindings, spilling to verbatim-plus-summary instead. The invariant to enforce: **a summary is admissible iff its binding manifest is a superset of the source span's binding set.** Anything less is paraphrase wearing the label of compaction. ```python import re from dataclasses import dataclass, field class LossyCompactionError(RuntimeError): """Raised when an auto-compaction summary drops a binding present in the source span.""" pass # Binding classes: each is a regex whose full matches must survive verbatim. BINDING_PATTERNS = { "path": re.compile(r"(?:\.{0,2}/)?[\w.-]+(?:/[\w.-]+)+\.\w+|[\w.-]+\.(?:py|ts|js|json|yaml|yml|md|txt|go|rs)"), "quoted": re.compile(r"`[^`]+`|\"[^\"]+\"|'[^']+'"), "identifier_with_digit": re.compile(r"\b[A-Za-z_][A-Za-z0-9_]*\d[A-Za-z0-9_]*\b"), "number": re.compile(r"\b\d+(?:\.\d+)?\b"), } @dataclass class BindingManifest: bindings: dict[str, set[str]] = field(default_factory=dict) def add(self, cls: str, token: str) -> None: self.bindings.setdefault(cls, set()).add(token) def missing_from(self, summary: str) -> dict[str, set[str]]: """Return bindings in this manifest NOT present verbatim in summary.""" gaps: dict[str, set[str]] = {} for cls, tokens in self.bindings.items(): lost = {t for t in tokens if t not in summary} if lost: gaps[cls] = lost return gaps def extract_bindings(source_span: str) -> BindingManifest: manifest = BindingManifest() for cls, pat in BINDING_PATTERNS.items(): for m in pat.finditer(source_span): manifest.add(cls, m.group(0)) return manifest def verify_compaction(source_span: str, summary: str, *, min_ratio_guard: float = 0.0) -> None: """ Enforce the binding-preservation invariant. Raises LossyCompactionError if any source binding is absent verbatim from summary. """ manifest = extract_bindings(source_span) gaps = manifest.missing_from(summary) if gaps: detail = "; ".join(f"{cls}: {sorted(toks)}" for cls, toks in gaps.items()) raise LossyCompactionError( f"Compaction is lossy: {sum(len(v) for v in gaps.values())} binding(s) " f"paraphrased or dropped ({detail}). Reject summary or re-run with pinned tokens." ) def safe_compact(source_span: str, summarizer) -> str: """ Attempt compaction; on lossy result, fall back to verbatim-plus-summary by appending the binding manifest so downstream steps can re-fetch. """ summary = summarizer(source_span) try: verify_compaction(source_span, summary) return summary except LossyCompactionError: # Fallback: keep summary but append a machine-readable binding manifest. manifest = extract_bindings(source_span) pinned = "\n".join( f" {cls}: " + ", ".join(sorted(toks)) for cls, toks in manifest.bindings.items() ) return f"{summary}\n\n[BINDING_MANIFEST — re-fetch before use]\n{pinned}" ```