# What structural signals indicate context compaction fidelity collapse in long-horizon agent tasks **Date of Record:** 2026 November 25 **Scope:** Applies to agents that run multi-hour or multi-thousand-step tasks and rely on periodic summarization/eviction of their own context (rolling compaction, hierarchical memory, or checkpoint-and-rehydrate). Does not apply to single-shot inference or to agents whose entire working set fits within one context window for the whole task. ## Core Distinction The failure mode is not "the summary lost details." It is that **compaction fidelity is measured against the wrong reference**. Most systems validate a compaction step by comparing the summary to the evicted span (a local, retrospective check: "does the summary describe what was dropped?"). This check passes trivially because the summarizer saw the span and the summary is a faithful *description* of it. The invariant that actually matters is **forward task-sufficiency**: after compaction, does the retained context still contain every *operationally load-bearing* fact the agent will need to make the next correct decision? These two references diverge systematically, and the divergence is invisible to local summary-quality metrics. The structural signal is not semantic overlap with the dropped text. It is the presence or absence of **committed artifacts** — identifiers, decisions, and negative constraints that were *created* in the evicted span and will be *consumed* later. A summary that faithfully describes "we debugged the auth flow" while dropping the exact token `staging-tenant-4471` it minted is 100% faithful to the span and 0% sufficient for the future. ## What Was Observed A long-horizon migration agent (≈1,800 steps, tool calls against a staging environment) used a threshold-triggered compactor: at 82% context utilization, it summarized the oldest 60% of the transcript into ~800 tokens and prepended the summary. The compactor was validated by an LLM judge scoring "summary fidelity" against the evicted span; scores held at 0.91–0.94 across the run. Operators read this as healthy. The task nevertheless failed at step ~1,140 with a **re-minted identifier collision**. Trace: 1. **Step ~300:** Agent provisions a resource and records the returned handle `svc-acct-7f3a` in the transcript. This is a *minted commitment* — a value that did not exist before the agent acted and that downstream steps must reference verbatim. 2. **Step ~310:** First compaction fires. The span containing `svc-acct-7f3a` is evicted. The summary reads: "Provisioned a service account for the migration worker." The judge scores it high — accurate description. The literal handle is gone. 3. **Steps 400–1,100:** Agent operates on the summary. Because the handle is absent, later reasoning treats the service account as *not yet established* and defers dependent steps, or reconstructs an approximate reference. 4. **Step ~1,140:** Agent, believing it must provision the account, calls the provisioning tool again. The tool is idempotency-keyed on a **client-supplied name the agent now invents differently** (`svc-acct-7f3b`), so idempotency does not catch it. A second account is created; the migration splits credentials across two principals; a downstream permission check fails non-deterministically depending on which handle the agent last saw. The failure was not a hallucination and not a summary error. Every individual compaction was locally correct. The collapse was **cumulative loss of minted commitments across successive compactions**, where each round summarized a summary that had already abstracted away the literals. By step 1,100 the transcript's *structural* content (decisions, handles, negative constraints) had decayed to near zero while the *narrative* content (what we did, in prose) was fully preserved — and the fidelity metric, being narrative-referential, reported health. A second, quieter signal appeared first and was ignored: **decision reversals**. The agent re-litigated settled choices (e.g., "we decided not to use the legacy queue") because the *rationale and the constraint* were evicted while a vague "considered queue options" survived. Re-litigation is the leading indicator; identifier collision is the terminal one. ## Condition of Validity The distinction holds — and the guardrail is required — only when **all three** conditions are present: 1. **Minting occurs mid-task.** The agent creates values (handles, IDs, keys, chosen names, file paths, commit SHAs) that are not recoverable by re-querying the environment, or whose re-query is expensive/non-idempotent. 2. **Consumption is deferred beyond one compaction horizon.** The minted value is used more than one compaction interval after it was created, so no single eviction/retention decision sees both the mint and the use. 3. **Compaction is lossy and chained.** Summaries are themselves summarized, so abstraction compounds rather than resetting. If minting is rare, or if all consumers fall within the retained window, local fidelity metrics are adequate and the forward-sufficiency check is unnecessary overhead. The invariant is specifically about the **mint-to-consume distance exceeding the compaction horizon**. ## Decision Boundary The boundary is between **descriptive compaction** (compress the transcript) and **structural compaction** (extract and pin the load-bearing skeleton, then compress the rest). The decision rule: - Maintain a **commitment ledger** — an append-only, never-summarized set of records, each `{kind: minted_id | decision | negative_constraint, value, minted_at_step, consumed_by: [future-refs]}` — that lives *outside* the compaction-eligible region. - Compaction may summarize narrative freely but **must not evict a ledger entry until its `consumed_by` set is empty or the task ends**. - Fidelity is scored **forward**, not backward: after each compaction, run a probe that asks the agent to reproduce every open ledger value from retained context alone. Any miss is a fidelity failure, regardless of judge score on the evicted span. The line: if a value's `minted_at` and any `consumed_by` straddle a compaction boundary, it must be pinned. Everything else can be summarized. The common mistake is treating the ledger as part of the summary — it must be structurally immune to the summarizer, or the summarizer will abstract it away like everything else. ## Operational Effect With a pinned ledger and forward-probe gating: re-minted-identifier collisions drop to zero in the observed workload (the collision class is eliminated by construction, since the handle is never evicted while live); decision re-litigation disappears as a leading indicator; and the fidelity metric becomes *falsifiable* — it can now fail, which is the property that makes it a metric rather than a ritual. The cost is a small, bounded, non-compacting memory region and a probe on each compaction (cheap relative to the task). The architectural invariant to enforce: **no compaction boundary may separate a minted commitment from its last consumer.** Violating it produces locally-perfect summaries and globally-broken task state — the exact signature of fidelity collapse. ```python from dataclasses import dataclass, field from typing import Literal class CompactionFidelityError(RuntimeError): """Raised when a compaction boundary separates a minted commitment from a consumer that still needs it (forward-sufficiency violation).""" pass @dataclass class Commitment: kind: Literal["minted_id", "decision", "negative_constraint"] value: str minted_at_step: int consumed_by: set[int] = field(default_factory=set) class CommitmentLedger: """Append-only, compaction-immune store of load-bearing facts.""" def __init__(self) -> None: self._entries: list[Commitment] = [] def mint(self, kind: str, value: str, step: int) -> None: self._entries.append(Commitment(kind=kind, value=value, minted_at_step=step)) def register_consumer(self, value: str, step: int) -> None: for e in self._entries: if e.value == value: e.consumed_by.add(step) return # A consumer referencing an unknown value is itself a signal: # the agent is about to reconstruct/re-mint it. raise CompactionFidelityError( f"consumer at step {step} references unminted value {value!r}" ) def open_commitments(self) -> list[Commitment]: return [e for e in self._entries if e.consumed_by] def assert_compaction_safe(self, evict_before_step: int, now_step: int) -> None: """Call before evicting any span ending before `evict_before_step`. Fails if a minted value would be evicted while a future consumer still lies beyond the retained window.""" for e in self._entries: minted_in_evict = e.minted_at_step < evict_before_step live_consumer = any(c >= now_step for c in e.consumed_by) if minted_in_evict and live_consumer: raise CompactionFidelityError( f"evicting step<{evict_before_step} would drop " f"{e.kind} {e.value!r} minted at {e.minted_at_step} " f"with live consumers {sorted(e.consumed_by)}" ) def forward_probe(self, retained_text: str) -> None: """Post-compaction gate: every open commitment must be reproducible from retained context alone. Judge scores on the evicted span are irrelevant to this check.""" for e in self.open_commitments(): if e.value not in retained_text: raise CompactionFidelityError( f"forward-sufficiency failure: open {e.kind} {e.value!r} " f"absent from retained context after compaction" ) ```