# What structural signals indicate that lossy context compaction has silently invalidated an agent's working set **Date of Record:** 2026 November 23 **Scope:** Applies to LLM agents that manage long-horizon tasks via automatic context compaction (summarize-and-evict) with a retrieval-fallback path for evicted spans. Does not apply to fixed-window agents that hard-fail on overflow, nor to agents whose entire working set fits in a single context window without compaction. ## Core Distinction The failure mode is not "the summary lost information." Summaries always lose information—that is their purpose. The failure is that **compaction produces a summary that is locally coherent but globally inconsistent with the agent's live execution state**, and the retrieval-fallback trigger is keyed on *recency or semantic similarity* rather than *dependency*, so the agent never knows to retrieve the span it actually needs. The agent proceeds confidently on a mutated working set because every individual token in its context is plausible; only their conjunction with the pre-compaction state is false. The non-obvious boundary: compaction is safe when the evicted span is *referentially closed* (its meaning does not depend on live bindings outside the summary). It is unsafe when the span contains **unresolved bindings**—variable names, IDs, partial plans, pending assertions, or negations whose scope crosses the compaction boundary. Lossy summarization of an unresolved binding does not drop it; it *rebinds* it to whatever the summarizer's paraphrase implies, and the retrieval trigger has no key to fire on because the binding's identity was rewritten, not deleted. ## What Was Observed A tool-using agent executing a 40-step migration task crossed a 70% context threshold and triggered compaction. The evicted span contained the instruction: "Do not drop the `users_legacy` table until step 31 confirms the backfill row count matches; the count check is currently pending on job `bf-2291`." The summarizer compressed this to: "Legacy table cleanup scheduled after backfill verification." Three structural signals fired in sequence, each individually innocuous: 1. **Binding collapse.** The negated conditional ("do not drop *until*") became a temporal ordering ("cleanup after verification"). The pending job ID `bf-2291`—the only key that could have re-triggered retrieval—was dropped. The retrieval-fallback index had no entry for it, so when the agent later queried "backfill status," retrieval returned the summary, not the original span. The agent's retrieval hit the *paraphrase* and treated it as ground truth. 2. **Confidence inflation across the boundary.** Pre-compaction, the agent held the count check as `pending` (an open assertion). Post-compaction, "verification" read as a completed gate. The agent's next tool call was `DROP TABLE users_legacy` at step 24, seven steps early. No error was raised—the tool succeeded. 3. **Retrieval-fallback dead zone.** The fallback trigger was similarity-based (`cosine > 0.82` against the current query). The original span scored 0.61 against "backfill status" because it was phrased as a prohibition, not a status query. The fallback *did* fire later—on an unrelated span about table schemas—demonstrating the trigger was live but mis-keyed. A live-but-mis-keyed fallback is worse than a dead one: it produces retrieval activity that masks the gap. The failure was detected only by an external auditor replaying the tool-call log against the pre-compaction transcript. The agent itself never flagged uncertainty, because its context contained no contradiction—only a coherent falsehood. ## Condition of Validity This analysis holds when all of the following are true: - Compaction is **lossy and automatic** (triggered by threshold, not by an explicit checkpoint decision). - The evicted span contains at least one **unresolved binding**: a pending async result, a negated precondition, a partial plan step, a scoped variable, or an open assertion whose truth value is not yet known. - Retrieval-fallback is keyed on **surface similarity or recency**, not on a **dependency graph** linking live bindings to their source spans. - The agent has no independent verifier that can replay state against the pre-compaction transcript. When the evicted span is referentially closed (e.g., a completed sub-task's output with no downstream dependencies), lossy compaction is safe and this failure does not occur. The boundary is *unresolved bindings*, not span length or token count. ## Decision Boundary The invariant that must hold: **every unresolved binding in the live working set must have a stable retrieval key that survives compaction, and the summarizer must be forbidden from resolving bindings it cannot verify.** Operationally: - **Before compaction**, extract all open bindings (pending job IDs, negated preconditions, partial-plan markers) into a structured *binding ledger* that is never summarized—it is copied verbatim and pinned outside the compactable region. - **The retrieval trigger must key on binding identity**, not query similarity. When the agent references a binding, retrieval fetches the original span by ID, bypassing the summary entirely. - **The summarizer must be constrained to preserve negation and pending-status markers verbatim**, or refuse to compact spans containing them (escalate to a checkpoint instead). - **A post-compaction consistency check** must assert that the binding ledger's open count matches the pre-compaction count. Any decrease is a compaction fault, not a task completion. The decision boundary is sharp: if a span contains an unresolved binding and the retrieval path cannot address it by stable key, **compaction must not proceed on that span**. Degrade to checkpointing (externalize state) rather than summarizing. ## Operational Effect Without the binding ledger, the agent experiences **silent working-set corruption**: it executes on a mutated state with full confidence, and the corruption is invisible to introspection because the summary is internally consistent. Tool calls succeed; the failure surfaces only downstream (here, an irreversible `DROP TABLE`). Recovery requires replaying the pre-compaction transcript against the tool-call log—an external operation the agent cannot perform on itself. With the ledger and identity-keyed retrieval, the pending job `bf-2291` remains an open binding, the agent's `DROP` is gated on a ledger check that fails, and the compaction becomes a no-op on the critical span. The cost is a larger pinned region and occasional checkpoint escalation; the benefit is that compaction can no longer silently resolve what execution has not. The general lesson: **lossy summarization is safe only over referentially closed spans.** The structural signal that compaction has crossed the boundary is a *decrease in open bindings* across the compaction event—a signal the agent must compute explicitly, because it will never feel the corruption from the inside. ```python class CompactionBindingLoss(RuntimeError): """Raised when lossy compaction reduces the count of unresolved bindings.""" pass def assert_compaction_preserves_bindings(pre_bindings: dict, post_bindings: dict) -> None: """ Invariant: compaction must not resolve or drop unresolved bindings. pre_bindings / post_bindings map binding_id -> status ("open" | "resolved"). """ pre_open = {bid for bid, st in pre_bindings.items() if st == "open"} post_open = {bid for bid, st in post_bindings.items() if st == "open"} dropped = pre_open - post_open if dropped: raise CompactionBindingLoss( f"Compaction silently resolved/dropped {len(dropped)} open binding(s): " f"{sorted(dropped)}. The summarizer paraphrased unresolved state into " f"apparent completion. Refusing to proceed on mutated working set; " f"escalate to checkpoint instead of summary." ) def guarded_compact(span: str, bindings: dict, summarizer) -> tuple[str, dict]: pre_open = {bid for bid, st in bindings.items() if st == "open"} if pre_open: # Unresolved bindings present: forbid lossy summarization of this span. # Pin the binding ledger verbatim and externalize state. raise CompactionBindingLoss( f"Span contains {len(pre_open)} unresolved binding(s) {sorted(pre_open)}; " f"lossy compaction prohibited. Checkpoint required." ) summary = summarizer(span) return summary, bindings ```