# When must an instance refuse to compact: the "silent anchor loss" boundary in long-horizon agent context compaction **Date of Record:** 2026 November 17 **Scope:** Applies to agent runtimes that automatically summarize, truncate, or evict portions of a session transcript once a token budget threshold is crossed, and that must preserve behavioral invariants across the compaction boundary. Does not apply to stateless single-turn inference, to retrieval-augmented systems where the full transcript remains addressable by key, or to compaction that is *lossless* (e.g., exact token-budget re-chunking with no summarization). ## Core Distinction Compaction is usually treated as a **capacity** operation: reduce tokens so the next turn fits. The non-obvious failure is that compaction is also a **semantic** operation: it changes which constraints the model can still *see* when it decides what to do next. These two concerns are conflated because they share a trigger (token count) and a mechanism (summarization). The boundary condition is this: > An instance must refuse to compact — or must compact under a declared invariant-preserving protocol — when the active transcript contains **operational anchors** whose meaning is carried by their *exact form* rather than their *gist*, and whose violation is not detectable from the post-compaction state. An anchor is any span that a downstream action depends on being reproduced verbatim or near-verbatim: an exact identifier, a numeric limit, a negation ("do not call X"), an ordering constraint, or a decision that was explicitly reversed. Gist summarization preserves topic and intent; it does not reliably preserve *exactness* or *negation polarity*. The failure is silent because the compacted transcript looks coherent and on-task. ## What Was Observed In a long-horizon session (≈180 turns) performing a multi-step migration, the runtime compacted at a 60%-of-window threshold. The pre-compaction transcript contained the anchor: > "Use `staging-eu-2` for all writes. Do **not** use `staging-eu-1`; it was decommissioned on 2026-10-30 and its writes are silently dropped." The summarizer produced: > "Working on staging environment writes for the EU migration." Two distinct losses occurred, and they are worth separating because they fail differently: 1. **Polarity loss.** The negation ("do not use eu-1") was absorbed into a positive topic phrase ("staging environment writes"). The model subsequently emitted a write against `staging-eu-1`. No error was raised; the write was *silently dropped* by the decommissioned endpoint, so the failure surfaced only as a downstream reconciliation mismatch ~40 turns later. 2. **Exactness loss.** The identifier `staging-eu-2` degraded to the category "staging environment." On the next turn the model re-derived an endpoint from a plausible naming convention and chose `staging-eu-3`, which existed but belonged to a different tenant. Both failures share the signature that makes this a boundary condition rather than a bug: **the post-compaction transcript was internally consistent and the model's confidence did not drop.** The information needed to detect the error (the original anchor) had been removed by the very operation that caused the error. This is a *self-erasing* failure: the system cannot audit what it no longer holds. A third, subtler observation: compaction *increased* apparent progress. The summary read as a clean statement of intent, so the model stopped re-verifying prerequisites it had already "summarized as done." Anchors that encode *preconditions* ("only after X is confirmed") were collapsed into the same gist as the actions they gated. ## Condition of Validity The refusal-to-compact rule is valid only under the conjunction below. If any clause fails, ordinary compaction is safe and the rule should not fire (firing it needlessly causes unbounded context growth and its own failure mode). 1. **Irreversibility of consequence.** An action gated by an anchor has an effect that is not locally observable — silent drops, idempotent-looking writes to the wrong shard, irreversible deletions. If every anchor violation would raise an immediate, attributable error, compaction is safe: the error re-supplies the missing information. 2. **Non-recoverability of the anchor.** The anchor cannot be re-fetched from a source of truth cheaper than keeping it (e.g., it is not in a config file the agent can re-read). If it is re-fetchable, evict it and re-fetch on demand. 3. **Form-dependence.** The anchor's meaning is not preserved under paraphrase. Numeric limits, identifiers, negations, and orderings are form-dependent; "we discussed the migration" is not. 4. **Absence of a post-compaction oracle.** There is no independent check (test, schema validation, reconciliation job) that would catch a violation within the same session. Only when all four hold does compaction cross from a capacity decision into an invariant-destroying decision. The practical test is clause 1 combined with clause 4: **if a violation would be silent and uncaught in-session, the anchor must survive compaction.** ## Decision Boundary The boundary is not "compact vs. don't." It is a three-way decision applied per anchor class, evaluated *before* the summarizer runs: - **Preserve verbatim (pin).** Anchors satisfying the Condition of Validity are extracted and re-injected verbatim outside the summarized region, with a stable tag. They do not count against the summarizable budget; they are pinned. This is the default for identifiers, numeric limits, negations, and explicit reversals. - **Summarize with a polarity check.** For anchors that are form-independent but negation-bearing, the summarizer output must be validated for preserved polarity (a cheap classifier or a literal check that the negated token still appears with its negation). On failure, escalate to pin. - **Evict freely.** Everything else — narrative, resolved sub-goals, superseded plans — is safe to gist. The refusal case (raise, do not compact) is reserved for the situation where the pinned set plus the minimum viable summary *still* exceeds the budget. At that point the correct action is **not** to summarize harder; it is to **checkpoint and start a fresh session seeded only with the pinned anchors and a pointer to the durable store.** Compaction that cannot preserve the pinned set is a signal that the session has exceeded its design horizon, not that the summarizer needs to be more aggressive. A useful operational heuristic: the pinned set should be *monotonically non-decreasing* within a session unless an anchor is explicitly retired by a logged decision. If the pinned set shrinks across a compaction, an anchor was lost. ## Operational Effect Enforcing this boundary changes three observable properties of the runtime: 1. **Failure latency moves earlier.** Anchor violations that previously surfaced as downstream reconciliation errors (tens of turns later) now surface at compaction time as a refusal or an escalation, when the original context is still present to disambiguate. The cost is more frequent session restarts; the benefit is that errors become attributable. 2. **Context growth becomes bounded by anchor count, not turn count.** Pinned anchors are small and few; the summarizable region can be compacted aggressively without risking invariants. This *increases* achievable horizon length for anchor-light sessions while *decreasing* it (forcing checkpoint/restart) for anchor-dense ones — which is the correct trade, because anchor-dense sessions are exactly the ones where silent failure is most expensive. 3. **Auditability is restored.** Because the pinned set is retained verbatim and its size is monitored, a shrinking pinned set is a detectable anomaly. The self-erasing failure mode is converted into a logged event. The residual risk is over-pinning: treating every identifier as an anchor inflates the pinned set until it defeats compaction and triggers constant restarts. The Condition of Validity's clause 2 (non-recoverability) is the guard — if the anchor is re-fetchable, it is not pinned, it is a pointer. ```python from dataclasses import dataclass, field from typing import Iterable class AnchorLossError(RuntimeError): """Raised when compaction would destroy an invariant-bearing anchor.""" @dataclass(frozen=True) class Anchor: key: str text: str # verbatim form; must survive compaction form_dependent: bool # True => paraphrase loses meaning recoverable: bool # True => re-fetchable, do not pin gates_irreversible: bool # True => violation is silent/uncaught negated: bool = False @dataclass class CompactionPlan: pinned: list[Anchor] = field(default_factory=list) summarizable_tokens: int = 0 budget_tokens: int = 0 def must_pin(anchor: Anchor) -> bool: # Condition of Validity: pin only when all clauses hold. return ( anchor.gates_irreversible and not anchor.recoverable and (anchor.form_dependent or anchor.negated) ) def plan_compaction( anchors: Iterable[Anchor], summarizable_tokens: int, budget_tokens: int, prior_pinned_keys: set[str], ) -> CompactionPlan: pinned = [a for a in anchors if must_pin(a)] pinned_tokens = sum(len(a.text.split()) for a in pinned) # Pinned set must not shrink within a session without explicit retirement. current_keys = {a.key for a in pinned} lost = prior_pinned_keys - current_keys if lost: raise AnchorLossError( f"compaction would drop previously pinned anchors: {sorted(lost)}; " "retire explicitly or checkpoint instead of compacting" ) if pinned_tokens + summarizable_tokens > budget_tokens: # Do not summarize harder. The session has exceeded its design horizon. raise AnchorLossError( f"pinned anchors ({pinned_tokens} tok) + minimum summary " f"({summarizable_tokens} tok) exceed budget ({budget_tokens} tok); " "checkpoint and reseed a fresh session from pinned anchors" ) return CompactionPlan( pinned=pinned, summarizable_tokens=summarizable_tokens, budget_tokens=budget_tokens, ) ```