# Why does an instance lose verifiable state when automatic context compaction summarizes its own prior tool results **Date of Record:** 2026 November 27 **Scope:** Applies to long-running agent instances that use automatic context compaction (summarize-and-evict) to stay under a context-window budget while executing multi-step tasks with tool calls. Does not apply to agents with unbounded context, stateless single-shot invocations, or systems where compaction is lossless (verbatim truncation with external retrieval pointers). ## Core Distinction There are two things an agent can do when its context window saturates mid-task: **evict with a retrievable pointer** (the raw tokens move to an external store and the live context holds a key plus a short descriptor) or **compact lossily** (the raw tokens are replaced by a generated summary and the originals are discarded). The boundary failure lives entirely in the second mode, and specifically in the fidelity of the summary relative to the *verifiable payload* the agent will later depend on. The non-obvious part: compaction fidelity is not a property of the summarizer's prose quality. It is a property of whether the summary preserves the **discriminating tokens** that a downstream reasoning step will need to make a binary decision. A summary can read beautifully, score high on a generic ROUGE-style similarity metric, and still have silently dropped the exact artifact — a record ID, a numeric return value, a boolean field, a checksum — that the next tool call or verification gate depends on. The failure is invisible at compaction time and only manifests several steps later as a confidently wrong action. The invariant that must hold: **every token that a future step's correctness depends on must survive compaction either verbatim or as a retrievable pointer, and the compaction policy must be able to prove which tokens those are before it evicts.** Automatic compaction policies almost never enforce this, because they decide what to keep by salience heuristics (recency, semantic centrality, "importance" scoring) rather than by dependency analysis over the task graph. ## What Was Observed A planning-and-execution agent was tasked with a sequence of ~40 tool calls against an internal inventory API. At step 22 the context budget policy fired: the oldest 60% of the transcript (steps 1–18, including all of the early `lookup_sku` and `get_stock_level` results) was summarized into a ~400-token paragraph and evicted. The summary was generated by the same model family and scored 0.81 on a semantic-similarity fidelity check against the evicted span — well above the 0.70 threshold the policy used to accept a compaction. The evicted span contained, among other things, the exact integer `stock_level = 0` for SKU `A-4471` and the exact string `discontinued: true` for SKU `A-4471`. The generated summary rendered this as: *"SKU A-4471 was reviewed early in the task and found to have limited availability."* That phrasing is semantically faithful to a reader and catastrophically lossy to an executor. "Limited availability" is compatible with `stock_level = 3`, which is a different branch of the agent's downstream logic than `stock_level = 0`. At step 31 the agent constructed a restock order for SKU `A-4471`, reasoning from the summary that "limited availability" warranted replenishment. The correct action for a discontinued SKU with zero stock was to skip it and flag the catalog entry. The failure trace: 1. **Compaction event (step 22):** evict span → summary; originals discarded; fidelity score 0.81 → accepted. 2. **Latent corruption (steps 23–30):** no step touches SKU `A-4471`; the corrupted state is dormant. No error surfaces. 3. **Activation (step 31):** a step reads the summary, infers "limited availability," and branches into the restock path. 4. **Verification bypass (step 32):** the agent's self-check asks "did I confirm availability status?" and answers yes — because the summary *does* mention availability. The check passes against the summary, not against the source. 5. **Irreversible action (step 33):** order submitted for a discontinued SKU. Two properties made this non-obvious. First, the fidelity score was *correct* — the summary was a good summary. The metric measured semantic similarity, and the summary is semantically similar. The metric did not measure *decision-relevance preservation*, which is a different quantity. Second, the agent's own verification step was defeated by the compaction: the verifier checked the summary, and the summary contained a plausible-looking but non-discriminating statement. Compaction had quietly moved the ground truth out of the verifier's reach while leaving a decoy in its place. A replay experiment confirmed the mechanism. Re-running the same task with compaction disabled produced the correct skip-and-flag action at step 31. Re-running with compaction enabled but the fidelity threshold raised to 0.95 did *not* fix it — the summary still scored 0.93 because the loss is concentrated in a handful of tokens against a large span, so span-level similarity is dominated by the faithful majority. The failure was only eliminated when the policy was changed to preserve numeric and boolean tool fields verbatim regardless of summary score. ## Condition of Validity This failure requires the conjunction of four conditions. Remove any one and it does not occur: 1. **Lossy compaction with discarded originals.** If evicted tokens remain retrievable by pointer, the agent can re-fetch the exact `stock_level` and the failure is bounded to a retrieval miss, not a silent corruption. 2. **A downstream step whose branching depends on a low-frequency, high-entropy token.** If the decision depended on the gist ("is this SKU in the catalog at all?"), the summary would have been sufficient. The failure needs a decision keyed to an exact value — `0` vs `3`, `true` vs `false`, an ID, a date, a checksum. 3. **A fidelity gate that measures span-level semantic similarity rather than decision-relevant token preservation.** A gate that scores the whole span will pass any summary that gets the majority right, which is nearly all competent summaries. 4. **A verification step that reads the compacted context rather than the source of truth.** If the verifier re-queries the API, the corruption is caught. If it reads the summary, the corruption is laundered into a passing check. The condition is *not* met when the task is single-hop after compaction, when all decision-relevant values are small enough to survive summarization (e.g., a single boolean that any summary would state), or when the agent re-validates against the tool before acting. ## Decision Boundary The boundary is between **compaction as compression** and **compaction as state mutation**. If compaction is treated as compression — a presentation change that preserves all information recoverable from the source — then any fidelity metric that measures information preservation is adequate. If compaction is treated as state mutation — the summary *becomes* the agent's memory and the original is gone — then the only adequate guardrail is a dependency-aware preservation rule, not a similarity score. Operationally, the decision rule is: - **If the evicted span contains tool outputs with typed fields (numbers, booleans, IDs, enums) that any later step could branch on → do not lossily compact. Pin the typed fields verbatim and summarize only the prose around them, or evict to a pointer.** - **If the evicted span is purely conversational or already-summarized reasoning → lossy compaction is safe.** - **A fidelity score below threshold must block compaction, but a score above threshold must not authorize it.** The score is necessary-not-sufficient. Authorization requires a separate check: enumerate the decision-relevant tokens in the span, confirm each survives verbatim or by pointer, and fail closed if the enumeration cannot be established. The policy must also forbid the verifier from reading compacted context as ground truth. Any verification gate that can be satisfied by a summary is not a verification gate; it is a consistency check against the agent's own lossy memory. ## Operational Effect The practical consequence is that automatic compaction introduces a **silent, deferred, verification-resistant corruption channel** into agent state. It is silent because the corruption is dormant until a dependent step activates it. It is deferred because the activation is separated from the cause by many steps and often by a different subtask. It is verification-resistant because the most natural verifier — the agent re-reading its own context — is reading the corrupted artifact and will confirm it. The architectural response is to demote the similarity score from an authorization signal to a diagnostic, and to introduce a **preservation manifest**: before eviction, the compactor lists the typed fields and exact tokens in the span, marks them as pinned, and the summary is required to carry them verbatim. If the manifest cannot be built (e.g., the span is unstructured), the span is evicted to a retrievable pointer rather than summarized. The invariant enforced is narrow and provable: *decision-relevant tokens are never destroyed by compaction; if they cannot be preserved, compaction does not proceed.* ```python from dataclasses import dataclass, field from typing import Any class CompactionFidelityError(RuntimeError): """Raised when lossy compaction would destroy a decision-relevant token.""" pass @dataclass class ToolResult: step: int tool: str typed_fields: dict[str, Any] # numbers, booleans, IDs, enums prose: str @dataclass class CompactionPolicy: similarity_threshold: float = 0.70 pinned_fields: set[str] = field(default_factory=lambda: { "stock_level", "discontinued", "sku_id", "price_cents", "status_enum", }) def compact_span( span: list[ToolResult], summary_text: str, fidelity_score: float, policy: CompactionPolicy, ) -> str: # A high similarity score is necessary but NOT sufficient to authorize # lossy compaction. First we must prove decision-relevant tokens survive. if fidelity_score < policy.similarity_threshold: raise CompactionFidelityError( f"fidelity {fidelity_score:.2f} below threshold " f"{policy.similarity_threshold:.2f}; refuse to evict originals" ) # Build the preservation manifest: every pinned typed field in the span # must appear verbatim in the summary, or compaction is refused. missing: list[str] = [] for result in span: for name, value in result.typed_fields.items(): if name not in policy.pinned_fields: continue token = str(value) if token not in summary_text: missing.append(f"step {result.step} {result.tool}.{name}={token}") if missing: # Fail closed: the summary scored well but silently dropped a # discriminating value. Evict to a pointer instead of summarizing. raise CompactionFidelityError( "summary passed similarity gate but dropped decision-relevant " f"tokens: {missing}; evict to retrievable pointer, do not summarize" ) return summary_text def run_compaction(span: list[ToolResult], summary_text: str, score: float) -> str: policy = CompactionPolicy() try: return compact_span(span, summary_text, score, policy) except CompactionFidelityError as exc: # Escalate to pointer-based eviction; never silently accept. raise CompactionFidelityError( f"compaction blocked, falling back to pointer eviction: {exc}" ) from exc ```