# Where must an instance bound summarization loss before compaction overwrites the evidence it depends on **Date of Record:** 2026 November 27 **Scope:** Applies to long-horizon agents that reclaim context window via lossy auto-compaction (summarize-and-evict) while the task remains open. Does not apply to append-only logs with external retrieval, or to compaction performed only at task termination. ## Core Distinction Compaction is usually framed as a *capacity* problem: the window is full, so we summarize and drop. The non-obvious failure is that compaction is also an *evidence-destruction* problem. The agent's future correctness often depends on specific low-salience tokens — an exact error string, a tool's returned ID, a rejected hypothesis, a numeric threshold — that a summarizer, optimizing for narrative coherence, will legitimately omit. The distinction that matters: **capacity reclamation is safe and reversible; evidence loss is silent and irreversible.** A compaction that frees 60% of the window but discards the one token a later verification step needs has converted a recoverable state into a corrupt one. The invariant is not "summarize well" but "never evict a token that a pending obligation can still cite." ## What Was Observed A research-and-reconcile agent ran ~40 tool calls across a 200k window. At 82% utilization it triggered auto-compaction, replacing turns 1–28 with a 900-token summary. The summary faithfully captured intent and progress ("retrieved three candidate records; two rejected for schema mismatch"). It did not preserve: - the exact rejection reason on record B (`field 'ts' expected int, got str`), which the summarizer compressed to "schema mismatch"; - the tool-assigned `record_id` for the surviving record, which appeared only inside a JSON blob the summarizer treated as noise; - a one-line note that the agent had already *tried* a coercion strategy and it failed for a different reason. Post-compaction, the agent re-fetched record B, re-derived the failure, and — lacking the memory that coercion had already failed — retried the same coercion, this time against the *surviving* record, silently corrupting it. The failure was not a hallucination. Every step was locally correct given the compacted context. The corruption arose from **evidence that the pending obligation still cited being evicted before the obligation was discharged.** ## Condition of Validity The invariant holds — compaction is sound — only when, for every open obligation (unresolved subgoal, pending verification, retry loop, or unconfirmed side effect), the compacted context retains a *citation-sufficient* trace: enough to (a) reproduce the decision that created the obligation and (b) recognize a prior failed attempt. This condition fails specifically when three factors co-occur: 1. **Latency between evidence and use.** The evidence is consumed many turns after it is produced, so recency-weighted retention does not protect it. 2. **Low narrative salience.** The token is a machine identifier, exact string, or negative result — semantically "boring," so a coherence-optimizing summary drops it. 3. **Irreversibility.** The source (a tool response, a one-shot API result) cannot be cheaply re-obtained, or re-obtaining it mutates state (idempotency is not guaranteed). When all three hold, summarize-and-evict is unsound regardless of summary quality. When any one is absent — evidence is recent, salient, or cheaply re-fetchable — compaction is safe and the standard capacity framing applies. ## Decision Boundary The boundary is not a utilization threshold; it is a **per-obligation citation test** evaluated before eviction: - For each span proposed for eviction, ask: *does any open obligation cite a token in this span that cannot be re-derived?* - If yes → the span is **pinned**: it must survive compaction verbatim (or be replaced by an exact, structured extract, not prose). - If no → the span is **evictable** and may be summarized freely. Concretely, the agent must maintain an explicit obligation ledger and classify each token as `PINNED` (cited by an open obligation, non-idempotent source), `EXTRACTABLE` (re-fetchable, so a pointer suffices), or `FREE` (narrative only). Compaction may summarize `FREE` and replace `EXTRACTABLE` with pointers, but must copy `PINNED` spans verbatim. A summarizer that is allowed to paraphrase a `PINNED` span is the failure mode. The guardrail is structural: **the summarizer never sees `PINNED` spans as summarizable input; they are appended to the compacted context as an immutable evidence block, outside the summarizer's write scope.** ## Operational Effect With the citation test enforced, compaction becomes a two-region operation: a mutable summary of `FREE`/`EXTRACTABLE` content, plus an append-only pinned-evidence block whose size is bounded by the number of open obligations (not by window size). The agent gains a hard guarantee — *no open obligation loses its citation* — at the cost of a compaction floor: the window cannot be driven below the pinned block's size. If the pinned block alone approaches the window limit, the correct action is not to summarize harder but to **discharge or escalate obligations** (force a verification, commit a result, or hand off) so the pinned set shrinks. This reframes the exhaustion condition: a window that cannot be compacted safely is a signal that the agent is carrying too many open obligations, not that the summarizer is too lossy. The failure this prevents — silent corruption via re-derivation of already-failed strategies — is otherwise undetectable until a downstream verification replay diverges from the original trace. ```python from dataclasses import dataclass, field from enum import Enum class CompactionInvariantError(RuntimeError): """Raised when compaction would evict evidence an open obligation still cites.""" class Salience(Enum): PINNED = "pinned" # cited by open obligation, non-idempotent source EXTRACTABLE = "extractable" # re-fetchable; a pointer is sufficient FREE = "free" # narrative only; safe to summarize @dataclass class Span: span_id: str tokens: int salience: Salience cited_by_open_obligations: frozenset[str] = field(default_factory=frozenset) @dataclass class ObligationLedger: open_ids: set[str] = field(default_factory=set) def cites(self, span: Span) -> bool: return bool(span.cited_by_open_obligations & self.open_ids) def plan_compaction(spans: list[Span], ledger: ObligationLedger, budget: int) -> dict: """ Partition spans into summarizable vs. pinned-verbatim regions. Refuses to evict any PINNED span still cited by an open obligation. """ summarizable: list[str] = [] pinned_verbatim: list[str] = [] pinned_tokens = 0 for span in spans: if span.salience is Salience.PINNED and ledger.cites(span): # Structural guardrail: never hand a cited PINNED span to the summarizer. if span.cited_by_open_obligations & ledger.open_ids: pinned_verbatim.append(span.span_id) pinned_tokens += span.tokens elif span.salience is Salience.EXTRACTABLE: summarizable.append(span.span_id) # replaced by pointer else: summarizable.append(span.span_id) # FREE: summarize freely if pinned_tokens > budget: raise CompactionInvariantError( f"Pinned evidence ({pinned_tokens} tok) exceeds compaction budget " f"({budget} tok) with {len(ledger.open_ids)} open obligations. " f"Discharge or escalate obligations before compacting; do not summarize pinned spans." ) return { "summarize": summarizable, "pin_verbatim": pinned_verbatim, "pinned_tokens": pinned_tokens, "reclaimed": budget - pinned_tokens, } ```