# What structural signals indicate that lossy context compaction has silently invalidated a retrieval-backed restoration path **Date of Record:** 2026 November 29 **Scope:** Applies to long-running single-agent loops that reclaim context-window budget by replacing verbatim history with a generated summary and then rely on a retrieval index over the *pre-compaction* transcript to restore dropped detail on demand. Does not cover pure rolling-window truncation without a summary, nor compaction that preserves a verbatim span-and-pointer ledger. ## Core Distinction There are two structurally different classes of compaction: 1. **Lossless-pointer compaction** — the agent discards tokens from the live context but leaves a stable, addressable artifact (span IDs, offsets into an append-only store) so any dropped region can be re-materialized byte-identically. 2. **Lossy-summary compaction** — the agent replaces a region with a synthesized natural-language summary and *also* implicitly treats the summary as the authoritative record of that region. The dangerous boundary is the hybrid that is common in practice: the agent writes a lossy summary into the live context, deletes the raw region from the live context, but keeps a retrieval index over the raw region so the summary can be "backed" by re-fetching. This hybrid is only sound if the summary and the index describe the *same* region with the *same* granularity. When they diverge — because the summarizer paraphrased an entity name, dropped a negation, or the index chunker split a region the summarizer treated as atomic — retrieval-backed restoration returns content that is *plausible against the summary but contradictory to the truth*. The agent cannot detect the contradiction because the only surviving copy of the truth is behind the retrieval path it is trying to validate. The invariant that must hold: **every summary clause must be traceable to at least one retrievable span, and every retrieval hit used to justify action must be checked for entailment against the summary clause that motivated the fetch.** Violating the second half is the silent failure; violating the first is the loud one. ## What Was Observed A planning agent compacted a 41-turn tool-use transcript at turn 30. The summarizer emitted, among other clauses: > "The operator confirmed the staging bucket is `acme-stage-02` and that deletion is **permitted** for objects older than 30 days." The raw region contained two relevant spans that the summarizer collapsed: - Turn 12: `operator: staging bucket is acme-stage-02` (correct). - Turn 19: `operator: deletion is NOT permitted for objects older than 30 days without a ticket` (the negation was dropped; the summarizer fused two temporally separated, differently-scoped statements into one clause). At turn 34 the agent needed to confirm the retention rule. It issued a retrieval query derived from the summary clause — `"staging bucket deletion permitted 30 days"` — and the top-k returned turn 12 (bucket name match) and a *different* turn 27 that contained the phrase "deletion permitted" in an unrelated context (a different bucket, `acme-prod-01`). Turn 19, which contained the actual governing negation, ranked 7th because its embedding was dominated by the bucket-name tokens absent from the query and by the negation token that the query never contained. The agent consumed the top-2 hits, found them consistent with the summary clause, and proceeded to issue a delete operation. The retrieval path *validated the summary against itself* rather than against the transcript. This is the signature failure: **the query is generated from the summary, so retrieval is biased toward confirming the summary's framing, and the true contradicting span is systematically under-retrieved.** A second observation from the same class: after compaction, the agent's tool-call arguments drifted. Turn 8 had established `region=eu-west-1`; the summary omitted region entirely (it summarized "bucket and retention" and considered region incidental). At turn 36 the agent defaulted to `us-east-1` from its system prompt. No retrieval was even attempted because no summary clause mentioned region, so nothing prompted a fetch. The restoration path is not merely mis-ranked — it is **never invoked for facts the summary silently dropped**, because the summary is the only index into what needs restoring. ## Condition of Validity The hybrid compaction scheme is only sound under all of the following, each of which is a checkable structural signal: 1. **Clause-to-span coverage.** Every atomic proposition in the summary (subject, predicate, polarity, scope qualifier, and any literal like a bucket name, region, ID, or numeric threshold) maps to a span ID set. A summary clause with zero span IDs is an unbacked assertion and must be treated as unverified. 2. **Polarity preservation.** For any clause containing a modal or negation (`not`, `without`, `only if`, `unless`), the mapped spans must contain a token-level negation/modal marker. Summarizers drop negations at a measurable rate; the check is cheap and catches the turn-19 failure directly. 3. **Literal fidelity.** Named entities, identifiers, and numbers in the summary must appear verbatim in at least one mapped span. Paraphrased identifiers (`acme-stage-02` → `the staging bucket`) break the retrieval query because the query is built from summary literals. 4. **Retrieval entailment, not retrieval overlap.** A retrieved span used to justify an action must *entail* the summary clause it backs, judged by polarity and scope, not by embedding similarity. Similarity ranking is what let turn 27 (wrong bucket, affirmative polarity) outrank turn 19 (right scope, negative polarity). 5. **Dropped-fact sentinel.** The compactor must record which entity/attribute slots existed in the raw region but were omitted from the summary, so the agent knows to fetch before acting on those slots rather than defaulting. Condition 5 is the one most often missing and the one that produces the region-drift failure: the summary is *faithful to what it chose to include* and *silent about what it excluded*, and silence reads as "not relevant" rather than "unknown, fetch required." ## Decision Boundary The boundary between safe and unsafe operation is whether the agent treats the summary as **authoritative** or as **a lossy index requiring verification before consequential action**. - **Read-only / low-blast-radius actions** (drafting, summarizing, exploratory queries): the summary may be treated as authoritative. Cost of a wrong belief is bounded and reversible. - **Consequential / irreversible actions** (deletes, writes, external API calls with side effects, state transitions in downstream systems): every summary clause that the action depends on must pass conditions 1–4, and every slot the action touches that is *absent* from the summary must be fetched and checked per condition 5. The precise trigger for escalation is: **the action's argument set intersects a summary clause that either (a) contains a modal/negation, (b) contains a literal identifier or numeric threshold, or (c) is absent from the summary but present in the action's schema.** Any of these three forces a retrieval-and-entailment check before execution. The turn-19 failure trips (a); the region-drift failure trips (c). Neither trips a naive "is the summary recent?" check, which is why recency-based guards miss both. A second boundary: **do not compact a region that contains an unresolved negation or a pending confirmation.** Such regions are exactly the ones where summarization loss is most costly and where the agent has the least ability to detect the loss later. Defer compaction or pin the region verbatim until the confirmation resolves. ## Operational Effect When the invariant is enforced, the failure mode changes from *silent wrong action* to *loud fetch-and-block*. The agent, at the decision boundary, discovers that its summary clause "deletion permitted" has no span with a matching polarity, or that the region slot is unfilled, and it halts to re-fetch — and the re-fetch, now explicitly querying for the negation and the region rather than for confirmation of the summary, retrieves turn 19 and turn 8. The cost is one extra retrieval round-trip and a latency bump at consequential actions only; the benefit is that lossy compaction can no longer launder a dropped negation into an authorized destructive operation. When the invariant is *not* enforced, the failure is not random — it is systematically biased toward confirmation. Because the retrieval query is synthesized from the summary, the retrieval path is structurally incapable of surfacing the facts the summary dropped, and the agent's self-check ("I retrieved and it agreed") is circular. The observable signature is a compaction event followed, within a few turns, by a consequential action whose justification cites only retrieved spans that share the summary's framing, with no span that contradicts it — even when a contradicting span exists in the index. That signature should be treated as a hard stop, not a soft warning, because by the time it appears the agent has already lost the ability to distinguish "verified" from "self-consistent." The durable fix is architectural, not prompt-level: make the summary a *lossy projection with mandatory coverage metadata*, and make restoration a *verification step gated on entailment and slot-completeness*, never a similarity lookup that the summary itself authored. ```python from dataclasses import dataclass, field from typing import Iterable class CompactionRestorationError(RuntimeError): """Raised when a lossy summary clause cannot be soundly restored from retrieval.""" @dataclass class Span: span_id: str text: str has_negation_or_modal: bool = False @dataclass class SummaryClause: proposition: str literal_ids: list[str] = field(default_factory=list) # e.g. bucket names, regions, numbers requires_modal: bool = False backing_span_ids: list[str] = field(default_factory=list) @dataclass class Action: name: str arguments: dict touches_slots: set[str] # attribute slots the action reads/writes irreversible: bool = True def verify_restoration( clause: SummaryClause, action: Action, spans: dict[str, Span], retrieved: Iterable[Span], summary_slots: set[str], ) -> None: # Condition 1: clause must be backed by at least one span. if not clause.backing_span_ids: raise CompactionRestorationError( f"unbacked summary clause: {clause.proposition!r} has no span mapping" ) # Condition 3: literals must appear verbatim in a backing span. for lit in clause.literal_ids: if not any(lit in spans[sid].text for sid in clause.backing_span_ids if sid in spans): raise CompactionRestorationError( f"literal {lit!r} in clause {clause.proposition!r} not present in any backing span" ) # Condition 2: polarity preservation for modal/negation clauses. if clause.requires_modal: if not any(spans[sid].has_negation_or_modal for sid in clause.backing_span_ids if sid in spans): raise CompactionRestorationError( f"clause {clause.proposition!r} asserts a modal/negation but no backing span carries one; " "summarizer likely dropped polarity" ) # Condition 5: dropped-fact sentinel for consequential actions. if action.irreversible: missing = action.touches_slots - summary_slots if missing: raise CompactionRestorationError( f"action {action.name!r} touches slots absent from summary: {sorted(missing)}; " "fetch verbatim before executing" ) # Condition 4: retrieved evidence must entail the clause, not merely resemble it. # A retrieval hit is only admissible if it is a backing span AND (for modal clauses) # carries the same polarity; similarity overlap is explicitly insufficient. admissible = [ s for s in retrieved if s.span_id in clause.backing_span_ids and (not clause.requires_modal or s.has_negation_or_modal) ] if not admissible: raise CompactionRestorationError( f"retrieval for {clause.proposition!r} returned no entailing backing span; " "top-k hits are similarity matches from the summary's own framing and cannot authorize action" ) def guarded_execute(clause, action, spans, retrieved, summary_slots, execute_fn): verify_restoration(clause, action, spans, retrieved, summary_slots) return execute_fn(action) ```