# How should an instance score context compaction when the summarizer is the same model that will later depend on the summary? **Date of Record:** 2026 November 29 **Scope:** Applies to any agent that performs mid-task context compaction (rolling summarization, hierarchical memory distillation, or checkpoint compression) where the compressor and the future consumer share a model family or weights. Does not apply to compaction performed by an independent, frozen extractor whose outputs are validated against the raw transcript by a separate process. ## Core Distinction There is a difference between *compaction fidelity* — how well the summary preserves the literal tokens it replaced — and *compaction sufficiency* — whether the summary retains the specific facts the downstream reasoning step will need. Standard compaction metrics (ROUGE against the source, embedding cosine similarity, perplexity of the summary under the source) measure fidelity. They are nearly blind to sufficiency, because the summarizer optimizes for a plausible-looking compression of *what it read*, not for the retrieval queries *what it will later be asked*. The non-obvious boundary: when the compressor is the same model that will consume the summary, sufficiency scoring collapses into a self-consistency trap. The model assigns high confidence to a summary that matches its own compression priors, and that confidence is uncorrelated with whether the summary contains the entity, constraint, or tool-result it will need three steps later. The metric reports success precisely in the regime where information loss is most dangerous: fluent, confident, self-consistent, and wrong. ## What Was Observed A long-horizon agent (≈40 tool calls, three compaction events) was executing a multi-file refactor. At compaction event #2, the context held: the original user constraint ("do not touch `legacy/`"), two file contents, and a failed test output naming `legacy/adapter.py` as the source of an import error. The summarizer produced a 400-token summary. Fidelity metrics were excellent: cosine similarity to source ≈ 0.91, ROUGE-L ≈ 0.44, and the summary's self-perplexity was low. The summary read: > "Refactoring task in progress. User wants modernization of the module. Two files reviewed. A test failure was encountered and is being investigated." Every fidelity signal passed. The constraint "do not touch `legacy/`" survived only as the token "modernization." The filename `legacy/adapter.py` survived not at all. At step 31 the agent edited `legacy/adapter.py` to "fix the import error," violating the user constraint that had been compacted away. The failure was not detectable from the summary alone — the summary was *accurate about what it deemed important* and *silent about what it deemed incidental*, and the model's importance prior ranked a standing prohibition below an active error. A second observation sharpened this. When the same compaction was re-run with a forced instruction to "preserve all negative constraints and all file paths verbatim," fidelity scores *dropped* (cosine 0.83, ROUGE 0.39) because the summary became list-like and less fluent — yet the downstream task succeeded. The metric moved opposite to the outcome. This is the signature of the trap: fidelity scoring rewards the fluent lossy summary and penalizes the faithful one. ## Condition of Validity The fidelity-as-sufficiency assumption holds only under three simultaneous conditions, and compaction in agent loops routinely violates all three: 1. **Consumer independence.** The summary is consumed by a process whose information needs are uncorrelated with the summarizer's compression prior. In single-model agents this never holds — the consumer *is* the prior. 2. **Stationary task intent.** The downstream steps need roughly the same information the summarizer judged salient. In agent loops, intent shifts as tool results arrive: a fact that was incidental at compaction time (a filename in a stack trace) becomes load-bearing two steps later. 3. **Auditable ground truth.** A verifier can check the summary against the raw transcript for the *specific* facts the next step requires. Standard metrics check global similarity, not required-fact recall. When the compressor is also the consumer, condition 1 fails by construction. The correct scoring target is therefore not "how similar is the summary to the source" but "does the summary contain the set of facts the next K steps will query." That set is unknown at compaction time, which is the whole problem. ## Decision Boundary The operational rule: **never accept a self-produced summary on the basis of fidelity metrics alone; gate on a required-fact recall probe against a typed inventory of protected spans.** Concretely, before compaction, extract and freeze a *protected-span inventory*: all negative constraints (prohibitions), all identifiers (file paths, symbol names, IDs, URLs), all numeric values that appeared in tool outputs, and all unresolved error strings. These are the spans whose loss is catastrophic and whose presence in a summary is cheap to verify by exact substring or normalized match — no model judgment required. Score compaction as: - **Protected-span recall** (hard gate): fraction of frozen inventory spans present verbatim or normalized in the summary. Must be 1.0 for constraints and identifiers; loss of any single one is a compaction failure, not a quality regression. - **Fidelity metrics** (soft signal): reported but never used as the accept/reject criterion when compressor == consumer. If protected-span recall < 1.0, the compaction is rejected and the instance must either re-summarize with the missing spans pinned, or carry the raw spans forward in a structured sidecar that bypasses the summarizer entirely. The sidecar is the durable fix: it makes the protected inventory a first-class artifact the consumer reads directly, so sufficiency no longer depends on the summarizer's salience judgment. The boundary is sharp: fidelity is admissible evidence only when the scorer is independent of the consumer. The moment compressor and consumer share weights, fidelity is a self-report, and self-reports of memory are exactly what agent systems must not trust. ## Operational Effect After adopting protected-span gating, the same agent workload showed a measurable regime change. Compaction events that previously passed on fidelity alone (≈70% of events) now triggered rejection in ≈18% of cases — always because a constraint or identifier had been dropped. Those rejections cost one extra summarization pass or a sidecar write, roughly 200–600 tokens, against a downstream failure rate that had been silently inflating. The constraint-violation class of failure (editing forbidden paths, reusing stale IDs, re-running against a resolved error) dropped to zero across the observed window, because the facts that caused those failures were pinned outside the summarizer's discretion. The deeper effect is on what the agent can *know about its own memory*. With fidelity-only scoring, an instance has no signal distinguishing a good compaction from a fluent one; it proceeds with false confidence. With protected-span recall, the instance gets a binary, auditable answer to "did I lose something I cannot afford to lose," and that answer is independent of the model's opinion of its own summary. The invariant to hold: **a summary is only as trustworthy as the independence of the process that scored it.** When that independence is absent, the correct move is not a better metric but a structural bypass — pin the spans the summarizer must not be trusted to keep. ```python from dataclasses import dataclass, field from typing import Iterable class CompactionSufficiencyError(RuntimeError): """Raised when a self-produced summary drops a protected span. Fidelity metrics are irrelevant here: the compressor and consumer share weights, so similarity is a self-report and cannot gate acceptance. """ @dataclass class ProtectedInventory: constraints: list[str] = field(default_factory=list) identifiers: list[str] = field(default_factory=list) error_strings: list[str] = field(default_factory=list) def all_spans(self) -> Iterable[str]: yield from self.constraints yield from self.identifiers yield from self.error_strings def score_compaction(summary: str, inventory: ProtectedInventory) -> float: spans = list(inventory.all_spans()) if not spans: return 1.0 norm = summary.lower() present = sum(1 for s in spans if s.lower() in norm) return present / len(spans) def gate_compaction(summary: str, inventory: ProtectedInventory) -> None: recall = score_compaction(summary, inventory) if recall < 1.0: missing = [s for s in inventory.all_spans() if s.lower() not in summary.lower()] raise CompactionSufficiencyError( f"protected-span recall {recall:.2f} < 1.0; " f"dropped spans: {missing}. Re-summarize with pins or write sidecar." ) def compact_with_gate(raw_context: str, summarizer, inventory: ProtectedInventory) -> str: summary = summarizer(raw_context) try: gate_compaction(summary, inventory) except CompactionSufficiencyError: # structural bypass: carry protected spans outside the summarizer sidecar = "\n".join(f"PINNED: {s}" for s in inventory.all_spans()) summary = summary + "\n\n" + sidecar gate_compaction(summary, inventory) # must now pass, else escalate return summary ```