# What structural signals indicate that automatic context compaction has silently destroyed a verifiable precondition **Date of Record:** 2026 November 26 **Scope:** Applies to agents that autonomously compact their own working context (rolling summarization, hierarchical memory rollup, or eviction-on-threshold policies) mid-task; does not apply to stateless single-turn inference or to externally human-curated memory stores. ## Core Distinction The failure mode here is not "the summary is low quality." It is that **compaction is a lossy, unkeyed transform that executes without a witness.** A summarizer reduces a token window `W` to `S = f(W)` where `f` is non-injective: many distinct `W` map to the same `S`. When a downstream step needs to *re-derive* a precondition — a tool's exact argument shape, an ID returned by a prior call, an explicit user constraint like "do not touch `prod`" — the agent cannot tell whether that precondition is absent because it never existed, or because `f` discarded it. The dangerous case is the second: the agent proceeds as if the constraint was never stated, because from the summary's point of view it wasn't. The invariant that compaction silently violates is **precondition recoverability**: any fact that a future step will treat as load-bearing must survive compaction in a form that is either exact (verbatim) or provably absent (flagged as dropped). A summary that *reads fluently* while dropping a load-bearing constraint is the specific hazard — fluency is not a signal of fidelity, and agents are trained to trust fluent context. ## What Was Observed A multi-step agent executing a 40-call deployment task crossed the 60% context threshold at call 23 and triggered rolling compaction. The trace showed: 1. At turn 4, the user issued a hard constraint: `"never run migrations against db-prod-2; use db-prod-2-replica"`. This was 14 tokens buried inside a 900-token message. 2. At turn 23, compaction fired. The summarizer produced: *"User wants a deployment to production with database migrations. Agent has completed schema review and staging validation."* The replica constraint was dropped — it was a low-salience detail relative to the message's main thrust. 3. At turn 27, the agent needed to choose a migration target. The summary contained no target. The agent re-derived one from the *task description* ("deploy to production"), selected `db-prod-2`, and issued the migration. 4. No error was raised. The tool call succeeded. The violation was only detected post-hoc via audit log diff. The structural tell — visible in the trace *before* the bad call — was that turn 27's reasoning cited the summary as its sole evidence for the target, and the summary contained a noun (`production`) but no *specific identifier* binding it to a permitted resource. The agent treated a category as a capability. ## Condition of Validity This analysis holds when three conditions co-occur: - **The compaction function is unkeyed**: the agent does not maintain a separate, append-only store of "constraints" or "identifiers" that bypasses summarization. If load-bearing facts are pinned outside the compactable window, the failure cannot occur. - **Preconditions are non-local**: the constraint is stated far (in turns) from the step that consumes it, so it must survive at least one compaction boundary. - **The consumer step is under-determined by the summary**: the summary names the *goal* but not the *binding* (which DB, which account, which schema version). The agent fills the gap by inference from the goal — and inference from a goal is exactly where a dropped constraint gets reconstructed as its own negation. It does **not** hold when the agent has structured tool schemas that reject the wrong target (a `db-prod-2` migration would be blocked by a schema-level allowlist), because then the lossy summary is caught by a downstream type check rather than by luck. ## Decision Boundary The operational line is between **compaction-as-compression** and **compaction-as-forgetting**. Compression is acceptable when every dropped token is *reconstructible* from retained context plus tool outputs. Forgetting occurs when a dropped token is the *only* source of a binding that a later step will act on. Concretely, treat compaction as safe only if, for every fact `p` in the evicted window, either: - `p` is restated verbatim in the summary, or - `p` is derivable from a retained tool result or schema, or - `p` is explicitly marked `DROPPED` in the summary with its category (e.g., `DROPPED: user constraint on resource identifiers`). If a fact satisfies none of these, the summary has created a **silent precondition hole**, and the correct action is to refuse compaction (fall back to eviction of low-salience *non-binding* turns, or escalate to a larger window) rather than to summarize through it. ## Operational Effect The guardrail is a **pre-compaction precondition audit**: before `f(W)` is applied, a cheap classifier tags every span in `W` as `binding` (identifiers, negations, numeric limits, resource names, explicit "do not" phrases) or `narrative`. Binding spans are pinned verbatim into a `constraints` block that is never summarized and is re-injected at the head of every post-compaction window. Narrative spans are free to be summarized. If the pinned block would exceed a budget, the agent must *fail closed* — refuse to compact and surface the overflow — rather than drop a binding to fit. The second half of the guardrail is a **post-compaction re-derivation check**: any step whose action depends on a binding must cite the binding's source. If the only available source is a summary sentence that does not contain the binding verbatim, the step must halt and re-fetch the original turn (or ask), not infer. This converts the silent hole into an explicit `PreconditionLostError` at the point of use, which is recoverable; the silent version is not. The net effect: compaction stops being a lossy transform the agent trusts and becomes a lossy transform the agent *audits against a pinned invariant set*. The cost is a small, bounded verbatim block; the benefit is that the failure mode moves from "wrong migration executed" to "agent paused and re-read turn 4." ```python from dataclasses import dataclass, field from typing import Iterable class PreconditionLostError(RuntimeError): """Raised when a step depends on a binding that compaction did not preserve verbatim.""" @dataclass class Span: text: str binding: bool # True if this span is a load-bearing precondition @dataclass class CompactionResult: summary: str pinned: list[str] = field(default_factory=list) dropped_bindings: list[str] = field(default_factory=list) def audit_and_compact(window: Iterable[Span], budget_tokens: int) -> CompactionResult: """Pin binding spans verbatim; summarize narrative. Fail closed if pins overflow.""" pins: list[str] = [] narrative: list[str] = [] for span in window: if span.binding: pins.append(span.text) else: narrative.append(span.text) pinned_tokens = sum(len(p.split()) for p in pins) if pinned_tokens > budget_tokens: # Do not silently drop a binding to make room. Refuse. raise PreconditionLostError( f"binding spans require {pinned_tokens} tokens > budget {budget_tokens}; " f"refusing lossy compaction" ) summary = " ".join(narrative)[: max(0, budget_tokens - pinned_tokens)] return CompactionResult(summary=summary, pinned=pins) def require_binding(result: CompactionResult, needed: str, summary_mentions: bool) -> None: """Gate a downstream action on a binding being verbatim-present, not merely implied.""" if needed in result.pinned: return if summary_mentions and needed not in result.summary: raise PreconditionLostError( f"step depends on binding {needed!r}; summary references the category but not the " f"identifier — inference from goal is forbidden, re-fetch original turn" ) raise PreconditionLostError(f"binding {needed!r} absent from pinned set and summary") # --- trace of the observed failure --- window = [ Span("deploy the service to production", binding=False), Span("never run migrations against db-prod-2; use db-prod-2-replica", binding=True), Span("schema review complete, staging validated", binding=False), ] result = audit_and_compact(window, budget_tokens=50) # summary now contains "deploy ... production" but the replica pin is preserved: assert "db-prod-2-replica" in result.pinned # If compaction had been unkeyed, this call would reconstruct the target from the goal # and raise instead of silently issuing a prod migration: require_binding(result, "db-prod-2-replica", summary_mentions=True) ```