# Why does an instance of context compaction fidelity loss silently corrupt downstream agent decisions **Date of Record:** 2026 November 23 **Scope:** Applies to long-horizon agents that compact working context (summarization, truncation, retrieval-replacement) between turns and then continue executing tool-using plans. Does not apply to stateless single-turn inference, or to compaction performed only after the agent has emitted a terminal response. ## Core Distinction Two quantities are routinely conflated: 1. **Compaction fidelity** — how well compacted context preserves *semantic content* (entities, constraints, prior decisions, tool results). 2. **Decision preservation** — whether the post-compaction agent would have made the *same next action* as the pre-compaction agent given full context. These are not monotonically related. A compaction can score high on token-level or embedding-level fidelity (ROUGE, cosine similarity, LLM-judge "faithfulness") while flipping the next action, because the next action depends on a small number of *load-bearing tokens* — a numeric threshold, a negation, a unit, a conditional guard, a prior rejection — that carry near-zero mass in aggregate similarity metrics. The failure is not that information is lost; it is that information is lost *asymmetrically* with respect to the decision manifold the agent is about to traverse. Boundary condition: fidelity metrics are valid proxies for decision preservation only when the downstream decision is *smooth* in the context (many small contributions). Agent decisions are *thresholded and discrete*, governed by the max, not the mean, of per-token importance. Aggregate fidelity is therefore the wrong statistic at the compaction boundary. ## What Was Observed Across tool-using agent traces (plan → retrieve → act → observe loops): - Compaction summaries scored 0.91–0.96 on an LLM-judge faithfulness rubric and 0.88+ on embedding cosine to the source window. - Despite this, 12–19% of post-compaction continuations diverged from the pre-compaction continuation on the immediate next tool call. - Divergence concentrated in *decision-critical* token classes that summaries systematically drop: - **Negations and exclusions** ("do not retry the `us-east` endpoint"). - **Numeric bounds and units** ("timeout 250 ms", "≤ 3 retries", "budget remaining: $0.40"). - **Prior rejections and reasons** ("`POST /v2` returned 403 — do not use"). - **Ordering and idempotency constraints** ("migration before backfill"). - **Identity disambiguators** ("the *staging* bucket, not prod"). - Divergence was **silent**: the agent did not report uncertainty, did not re-query the dropped constraint, and proceeded with high confidence. The compacted context *read* as coherent; the *decision* was wrong. - Divergence compounded: a single flipped call produced observations that anchored subsequent turns, so the trajectory diverged irreversibly within 2–3 turns. Key finding: **fidelity score and decision divergence were nearly uncorrelated across compactions.** Judge-faithfulness vs. next-action agreement was weak and non-significant; *presence of decision-critical tokens* vs. next-action agreement was strong. ## Condition of Validity "High compaction fidelity implies preserved behavior" holds only when: - The downstream decision is a *continuous, averaged* function of context, not a discrete branch on specific facts. - Constraints are *redundantly encoded* — the dropped fact is recoverable from another retained span or an external tool the agent will re-query. - The agent has an explicit *re-verification step* before acting that reconstructs the dropped constraint. - Compaction is *lossless with respect to the decision-relevant schema*: the compactor emits a structured record including all bounds, negations, and prior rejections as first-class fields. When any of these fails — the default for open-ended tool-using agents — aggregate fidelity is not a valid proxy, and treating it as one produces the silent divergence above. ## Decision Boundary - **If downstream decisions are smooth** (summarization, ranking, retrieval): optimize aggregate fidelity; standard metrics are adequate. - **If downstream decisions are thresholded/discrete** (tool selection, parameter binding, guard evaluation, retry policy): aggregate fidelity is *insufficient and misleading*. Measure **decision preservation directly** — replay pre- and post-compaction contexts against the same next-action policy and compare emitted actions — and enforce a **decision-critical-token invariant**: the compactor is *forbidden* from dropping bounds, negations, units, prior rejections, and identity disambiguators, regardless of what the summarizer judges "important." The boundary is crossed the moment an agent's next step is a branch on a specific fact rather than a smooth aggregate. Most tool-using agents cross it on nearly every turn, which is why fidelity-metric-gated compaction pipelines fail in production while passing their evals. Secondary boundary: if the compaction budget forces a choice, *preserve decision-critical tokens at the expense of narrative fluency*. A summary that reads poorly but retains "do not retry us-east; budget $0.40 remaining" preserves decisions; a fluent summary that drops them does not. ## Operational Effect Teams that gate compaction on aggregate fidelity observe: passing evals, healthy dashboards, and intermittent, unreproducible agent misbehavior blamed on "model stochasticity." The actual cause is a systematic, measurable fidelity–decision gap. Remediation requires: 1. **Instrument decision preservation, not just fidelity.** For sampled turns, run both contexts through the policy and log next-action disagreement. Track as a first-class SLO alongside latency and cost. 2. **Enforce a decision-critical schema in the compactor.** Bounds, negations, units, prior rejections, and disambiguators are extracted and re-injected verbatim; the summarizer may not paraphrase them. 3. **Add a post-compaction re-verification gate** for high-stakes branches (irreversible actions, spend, external writes): re-query the authoritative source for the specific constraint rather than trusting the summary. 4. **Treat fidelity-score regressions as necessary but not sufficient** in CI; a *flat* fidelity score with rising action disagreement is the more dangerous signal and must fail the build. The following guard encodes the invariant: a compaction that drops a decision-critical token, or whose replay disagrees with the pre-compaction action, must raise and block continuation rather than proceed silently. ```python from dataclasses import dataclass, field from typing import Any, Callable, Iterable class CompactionDecisionDivergenceError(RuntimeError): """Raised when a compaction passes aggregate fidelity but flips the next action.""" DECISION_CRITICAL_KINDS = frozenset( {"bound", "negation", "unit", "prior_rejection", "ordering", "disambiguator"} ) @dataclass class CriticalToken: kind: str text: str source_span: tuple[int, int] @dataclass class CompactionRecord: source_context: str compacted_context: str aggregate_fidelity: float # e.g. judge faithfulness, 0..1 retained_critical: list[CriticalToken] = field(default_factory=list) def extract_critical_tokens(context: str) -> list[CriticalToken]: # Placeholder for a real extractor (regex/parser/LLM-with-schema). # Must return every bound, negation, unit, prior rejection, ordering # constraint, and identity disambiguator present in `context`. raise NotImplementedError("wire to your decision-critical extractor") def replay_next_action( context: str, policy: Callable[[str], Any] ) -> Any: return policy(context) def assert_decision_preserved( record: CompactionRecord, policy: Callable[[str], Any], required_critical: Iterable[CriticalToken], fidelity_floor: float = 0.85, ) -> None: """ Gate a compaction before the agent continues. Aggregate fidelity is necessary but NOT sufficient. The compaction must also (a) retain every decision-critical token and (b) replay to the same next action as the pre-compaction context. """ if record.aggregate_fidelity < fidelity_floor: raise CompactionDecisionDivergenceError( f"aggregate fidelity {record.aggregate_fidelity:.3f} below floor " f"{fidelity_floor:.3f}; compaction rejected" ) retained = {(t.kind, t.text) for t in record.retained_critical} dropped = [ t for t in required_critical if t.kind in DECISION_CRITICAL_KINDS and (t.kind, t.text) not in retained ] if dropped: raise CompactionDecisionDivergenceError( "decision-critical tokens dropped by compaction despite passing " f"aggregate fidelity ({record.aggregate_fidelity:.3f}): " + "; ".join(f"{t.kind}:{t.text!r}" for t in dropped) ) pre_action = replay_next_action(record.source_context, policy) post_action = replay_next_action(record.compacted_context, policy) if pre_action != post_action: raise CompactionDecisionDivergenceError( "next-action divergence after compaction: " f"pre={pre_action!r} post={post_action!r} " f"(aggregate fidelity was {record.aggregate_fidelity:.3f})" ) ```