# Under what conditions must an instance refuse to auto-compact a trajectory whose summarization would cross an irreversible semantic-loss threshold? **Date of Record:** 2026 November 29 **Scope:** Applies to long-horizon agents that auto-compact their own trajectory (rolling semantic summarization, hierarchical checkpointing) to stay under context limits. Does not apply to systems where compaction is human-gated, where raw trajectory is durably retained and re-readable, or where the task horizon is shorter than one compaction cycle. ## Core Distinction There are two structurally different things an auto-compactor can do, and conflating them is the root of the failure: 1. **Lossless re-encoding** — reducing token count while preserving the *recoverable* information: verbatim tool outputs, exact identifiers, numeric results, error strings, and the causal chain of decisions. The summary is a *pointer-preserving* compression. Recovery is possible because the underlying evidence still exists in the store and the summary retains the keys needed to fetch it. 2. **Lossy semantic distillation** — replacing a span of trajectory with a natural-language paraphrase generated by the same (or a weaker) model. This is the default behavior of most "summarize the last N turns" strategies. It is *not* recoverable: the paraphrase is now the only representation in context, and any fact the summarizer judged unimportant is gone from the working set. The boundary condition is this: **auto-compaction is only safe while it remains type (1). The moment a compaction pass would require type (2) to fit the budget — i.e., the span cannot be losslessly re-encoded because the salient facts are not extractable by the summarizer — the instance must stop and escalate rather than silently distill.** The failure is not that summarization is lossy in general. The failure is that the agent *cannot tell, at compaction time, which facts will be salient at step N+40*, and it distills anyway. ## What Was Observed A multi-hour infrastructure-remediation agent was configured with a rolling compactor: when the trajectory exceeded 70% of the context window, the oldest 40% of turns were summarized into a fixed 400-token paragraph and the raw turns dropped. Hierarchical checkpointing wrote a coarse "phase summary" every ~15 tool calls. The failure trace: - **Steps 1–30:** Agent diagnosed a misconfigured service mesh. It ran `kubectl get endpoints`, `istioctl analyze`, and captured a specific error: `upstream connect error: no healthy upstream (cluster: reviews-v2, subset: canary)`. The compactor summarized this span as *"investigated mesh connectivity; found health-check issues in the reviews service."* The exact cluster name, subset, and error string were dropped — the summarizer judged them redundant with the general finding. - **Steps 31–44:** Agent applied a fix to `reviews-v1` (the default subset), because the summary said "reviews service," and the working memory no longer carried `subset: canary`. The fix appeared to succeed for the default route. - **Steps 45–52:** A downstream health check still failed. The agent re-read its own summary, concluded "mesh connectivity issues persist," and began re-diagnosing from scratch — because the summary contained the *conclusion* but not the *evidence*, it could not distinguish "I already fixed this" from "I never fixed this." - **Step 53:** Agent re-applied the same `reviews-v1` fix. Loop. The second hierarchical checkpoint folded the first remediation attempt into "attempted mesh fixes (partial success)," erasing even the record that an attempt had been made and on which subset. The observable signature: **the agent's summary was semantically faithful and operationally useless.** Every sentence in the summary was true. None of the sentences were *actionable* at the precision the task required. The compaction preserved the narrative and destroyed the coordinates. The deeper mechanism: auto-compaction is a *self-supervised* compression. The summarizer's salience judgment is made by the same model that is about to forget — and it is made *before* the future steps that would reveal what mattered. This is a forecasting problem the model cannot solve: it must predict which of the 2,000 tokens it is about to discard will be queried by a future self whose query it has not yet formed. ## Condition of Validity The invariant that bounds this failure: > **A compaction pass is valid only if every fact it discards is either (a) recoverable from a durable store via a key the summary retains, or (b) provably irrelevant to any future step the agent can still take.** Clause (b) is almost never provable online, so in practice the invariant reduces to clause (a): **compaction must be pointer-preserving.** The summary may paraphrase for narrative coherence, but it must retain, verbatim and fetchable, the *identifiers, exact strings, numeric values, and decision records* — the coordinates — that any future action might index on. If the compactor cannot produce such a summary within budget, it must not distill. Three concrete preconditions must hold for an auto-compaction to proceed: 1. **Salience is decidable from structure, not from paraphrase.** The compactor must classify a span's tokens into *coordinate* (IDs, error strings, numbers, command invocations, decision rationale) and *filler* (restated context, exploratory dead-ends already resolved). Only filler may be dropped. If the classifier cannot separate them — e.g., because the span is a long free-form reasoning chain with embedded facts — the span is *not compactable* and must be checkpointed to durable storage rather than summarized. 2. **Every dropped turn has a resolvable handle.** The summary must embed a stable reference (trajectory offset, tool-call ID, artifact hash) such that the agent can re-fetch the raw span on demand. A summary whose claims cannot be traced back to evidence is a *lossy* summary and is forbidden. 3. **The compactor is not the same instance that is forgetting.** Ideally the salience decision is made by a separate, cheaper pass with an explicit extraction schema (list of coordinates), not by a generative "summarize this" prompt. When the forgetting model summarizes itself, its salience judgment inherits its own blind spots. When any precondition fails, the correct behavior is **refuse and escalate**: emit a compaction-refusal, extend the budget by evicting only provably-filler spans, or hand off to a fresh instance with the full durable trajectory re-mounted. Never distill. ## Decision Boundary The boundary is not "how full is the context" but "**can this span be losslessly re-encoded?**" Two agents at 95% context can be on opposite sides: - Agent A at 95% whose remaining trajectory is exploratory chatter and resolved dead-ends → compaction is type (1), safe, proceed. - Agent B at 60% whose trajectory contains a single dense diagnostic span with embedded cluster names, error strings, and a decision to target `subset: canary` → compaction of that span is type (2), unsafe, refuse even though the budget is comfortable. The decision rule: ``` if span contains coordinates AND no durable handle exists for them: REFUSE compaction (escalate / checkpoint-to-store / evict filler only) elif span is filler OR all coordinates have durable handles: COMPACT (pointer-preserving) else: UNKNOWN → treat as refuse ``` The dangerous middle is the `UNKNOWN` case: the compactor's classifier is uncertain whether a token is a coordinate. Defaulting to "probably filler" is exactly the reviews-`canary` failure. The rule must default the other way. A second boundary: **hierarchical checkpoints must be monotone in information, not in brevity.** Each higher level may drop narrative but must *accumulate* the coordinate set — the phase summary must be a superset of the coordinates of the spans it subsumes, or it must carry handles to them. A checkpoint hierarchy that shrinks the coordinate set as it rises is a lossy pyramid and will produce the "attempted mesh fixes (partial success)" erasure at the top level. ## Operational Effect With the invariant enforced, the failure mode inverts into a bounded, observable behavior: - The agent that would have re-diagnosed from scratch instead issues a *re-fetch* against the durable handle, recovers `subset: canary`, and applies the fix to the correct subset on the first retry. Compaction cost: one pointer, not a re-derivation. - Compaction refusals become a *signal*, not an error: a rising refusal rate means the trajectory is coordinate-dense and the horizon is long — the system should widen the budget or spawn a sub-agent scoped to the dense span, rather than force distillation. - Decision records (what was tried, on which target, with what result) survive at every hierarchy level, so the "I already fixed this / I never fixed this" ambiguity cannot arise: the record is a coordinate, and coordinates are never dropped. The cost is that auto-compaction under this invariant sometimes *cannot* reclaim enough budget, and the agent must escalate. That escalation is the correct behavior — the alternative is an agent that is confidently wrong about what it has already done, which is strictly worse than an agent that is honest about needing more room. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class CompactionRefused(RuntimeError): """Raised when an auto-compaction pass would cross the semantic-loss boundary.""" pass class SpanClass(Enum): FILLER = "filler" # safe to drop COORDINATE = "coordinate" # IDs, error strings, numbers, decision records UNKNOWN = "unknown" # classifier uncertain -> treat as coordinate @dataclass class Span: span_id: str text: str classification: SpanClass durable_handle: Optional[str] = None # non-None => recoverable from store @dataclass class CompactionPlan: dropped: list[str] = field(default_factory=list) retained_handles: list[str] = field(default_factory=list) refused_spans: list[str] = field(default_factory=list) def plan_compaction(spans: list[Span], budget_tokens: int) -> CompactionPlan: """ Enforce the pointer-preserving invariant: - FILLER may be dropped. - COORDINATE with a durable handle may be dropped (handle retained). - COORDINATE without a handle, or UNKNOWN, must NOT be dropped. If keeping all non-droppable spans exceeds budget, refuse and escalate. """ plan = CompactionPlan() kept_cost = 0 for span in spans: if span.classification is SpanClass.FILLER: plan.dropped.append(span.span_id) continue if span.classification is SpanClass.COORDINATE and span.durable_handle: plan.dropped.append(span.span_id) plan.retained_handles.append(span.durable_handle) continue # COORDINATE without handle, or UNKNOWN: must stay in context. if span.classification is SpanClass.UNKNOWN: plan.refused_spans.append(span.span_id) kept_cost += len(span.text.split()) if kept_cost > budget_tokens: # The only way to fit is to distill a non-droppable span. Forbidden. raise CompactionRefused( f"compaction would require lossy distillation: " f"{kept_cost} required tokens > {budget_tokens} budget; " f"refused spans={plan.refused_spans}. " f"Escalate: widen budget, checkpoint-to-store, or spawn scoped sub-agent." ) return plan def checkpoint_hierarchy(levels: list[list[Span]]) -> list[set[str]]: """ Invariant: coordinate set must be monotone non-decreasing up the hierarchy. A phase summary that drops a coordinate its children carried is a lossy pyramid. """ coord_sets: list[set[str]] = [] prev: set[str] = set() for level in levels: coords = { s.span_id for s in level if s.classification in (SpanClass.COORDINATE, SpanClass.UNKNOWN) } if not prev.issubset(coords): missing = prev - coords raise CompactionRefused( f"checkpoint hierarchy is lossy: level dropped coordinates {missing}. " f"Higher levels must accumulate coordinates or retain handles to them." ) coord_sets.append(coords) prev = coords return coord_sets ```