# What structural signals indicate a lossy auto-compaction boundary has been crossed before retrieval-backed recovery can fire **Date of Record:** 2026 November 29 **Scope:** Applies to long-running agent sessions whose context manager performs automatic compaction (summarize-and-evict) under a token-pressure trigger, with a retrieval index over evicted spans as the recovery path. Does not apply to stateless single-turn inference, nor to architectures where compaction is disabled and the full transcript is retained verbatim. ## Core Distinction The failure mode is not "the summary was bad." It is a **timing inversion between two lossy systems that are assumed to be complementary**. Auto-compaction is a *forward* lossy projection: it replaces a span of turns with a summary generated under a token budget, and the projection is *not invertible*. Retrieval-backed recovery is a *backward* lossy projection: it re-materializes evicted spans by embedding-similarity lookup against a query derived from the current reasoning state. The design assumption is that compaction's information loss is *recoverable* because the evicted text remains retrievable. That assumption holds only when the retrieval key still co-occurs with the lost fact. The boundary is crossed when compaction evicts the **context that would have generated the retrieval query** — the anchor tokens that made the lost fact reachable — while simultaneously producing a summary that is *fluent and self-consistent* enough that the agent never generates a query at all. At that point the loss is silent: the summary reads as complete, the retrieval index is intact, and recovery machinery never fires because nothing signals a miss. The distinction that matters operationally is between **detectable loss** (summary flags an omission, or a query returns empty) and **undetectable loss** (summary asserts a false completeness, and no query is generated). Only the second is a continuity invariant violation. ## What Was Observed A planning agent ran a 40-step tool-orchestration task against a ticketing backend. At step 19, token pressure crossed the compaction threshold (0.82 of window). The compactor summarized steps 1–14 into 310 tokens and evicted the raw spans. The evicted region contained three facts that later mattered: 1. An early constraint: "do not mutate tickets owned by team `billing-core` without an approval token" — stated once, in step 4, inside a tool-error message body rather than a user turn. 2. A schema detail: the `assign` endpoint returns `202` with a `pending_id` that must be polled, not `200` with a final state. 3. A negative result: an earlier attempt to use `bulk_update` failed with a rate-limit error that implied a per-account quota of 10/min. The summary of steps 1–14 read, in relevant part: *"Explored ticket API; confirmed assignment workflow and update endpoints; one rate-limit encountered and handled."* Every clause is true. None of the three facts survived in a form that could be re-derived. The approval-token constraint was dropped entirely (it lived in an error body the summarizer treated as noise). The `202`/`pending_id` semantics were flattened to "assignment workflow confirmed." The quota number became "rate-limit encountered." At step 27 the agent issued `assign` on a `billing-core` ticket, received `202` with `pending_id`, and — reading the summary's "assignment workflow confirmed" — treated `202` as success and never polled. At step 31 it retried `bulk_update` eleven times in a loop, because "rate-limit encountered and handled" carried no magnitude. The retrieval index contained all three facts verbatim. No retrieval call was ever issued. The agent's self-report at termination was that the task succeeded. The structural signal that the boundary had been crossed was present but not instrumented: **the compaction ratio for the evicted span was 14 turns → 310 tokens (≈ 0.04 tokens per source token), while the summary contained zero explicit uncertainty markers and zero pointers to retrievable spans.** A summary that compresses ~25× and reports *no* omissions is not a good summary; it is a summary that has silently converted retrievable loss into unretrievable loss by removing the very cues that would trigger recovery. ## Condition of Validity The invariant "compaction is safe because retrieval can recover evicted spans" is valid **if and only if** at least one of the following holds for every fact whose loss would change a downstream action: - **(A) Query-anchor preservation.** The summary retains the lexical or semantic anchors sufficient for the agent, from a future reasoning state, to formulate a retrieval query that matches the evicted span. This requires the summary to preserve *entities, identifiers, numeric magnitudes, and constraint polarity* — not just topic. - **(B) Explicit miss-marking.** The summary contains a machine-readable omission record (a span pointer plus a "details elided" flag) that the context manager injects into the agent's working set as a standing retrieval obligation, so recovery is *push-triggered* rather than *pull-triggered*. If neither holds, the compaction boundary is a **one-way information gate**: text leaves the retrievable-by-reasoning surface while remaining in the index, and the index becomes unreachable because the keys to it were summarized away. This is the precise condition under which "retrieval-backed recovery" is a fiction — the store is full, the pointer is gone. The condition is *not* satisfied by embedding the full evicted span in the summary (that defeats the token budget), nor by trusting the summarizer to "preserve important details" (importance is defined relative to a future state the summarizer cannot see). It is satisfied only by structural instrumentation: the compactor must emit, alongside prose, a structured omission ledger keyed to span IDs, and the runtime must treat that ledger as an active retrieval obligation rather than passive metadata. ## Decision Boundary The operational decision is **when to compact versus when to checkpoint-and-restart**, and it hinges on a measurable ratio, not a vibe. Define, for a candidate eviction span `S` with summary `σ(S)`: - `ρ = tokens(σ(S)) / tokens(S)` — compression ratio. - `κ = |anchors(σ(S)) ∩ anchors(S)| / |anchors(S)|` — anchor retention, where anchors are extracted identifiers, numerics, negations, and constraint verbs. - `μ` — whether `σ(S)` carries an explicit omission ledger (boolean). The boundary: - **Compact in place** only when `κ ≥ 0.6` **and** `μ = true`. Under these conditions the summary is a *lossy but recoverable* projection: the agent can still form matching queries, and the ledger forces retrieval when a downstream action touches an elided span. - **Checkpoint-and-restart** (persist full span to durable store, reset context, rehydrate from a curated working set) when `ρ < 0.1` **and** `κ < 0.4` — i.e., aggressive compression that has stripped anchors. Here in-place compaction is guaranteed to create silent loss; the correct move is to not summarize at all but to *evict-with-pointer* and let the agent re-fetch on demand from a cold start that knows what it doesn't know. - **Refuse compaction** (raise, escalate to a larger window or a human/auditor agent) when the eviction span contains facts classified as *action-gating* (authorization constraints, quota magnitudes, idempotency keys) **and** `μ = false`. Action-gating facts must never enter a summary without an omission ledger, regardless of `κ`. The non-obvious part: a *high* `ρ` (mild compression) with `μ = false` is more dangerous than a *low* `ρ` with `μ = true`, because mild compression produces a summary that *looks* faithful, suppressing the agent's suspicion, while carrying no recovery hook. The decision must weight `μ` above `ρ`. ## Operational Effect When the boundary is respected — `μ = true` and `κ` above threshold — the agent's behavior changes in an observable way: it issues retrieval calls *before* acting on elided spans, and those calls succeed because anchors survive. The retrieval index stops being decorative and becomes load-bearing. Latency rises modestly (one extra round-trip per elided-span touch) and token spend rises, but action-gating facts are never silently dropped. When the boundary is crossed, the failure signature is specific and detectable in logs even without ground truth: **zero retrieval calls in a session whose compaction ledger shows elided spans that were later touched by tool arguments.** That co-occurrence — a tool call whose arguments reference an identifier that exists only in an evicted span, with no preceding retrieval — is the structural smoking gun. It means the agent acted on a summarized belief about a fact it never re-fetched. Instrument for it: join the compaction ledger's span IDs against subsequent tool-call argument tokens; any match with no intervening retrieval is a continuity violation, independent of whether the action happened to succeed. The guardrail is therefore not "summarize better" but "make omission a first-class, push-triggered obligation and audit the retrieval-call rate against the elision rate." A healthy session has retrieval calls proportional to elided-span touches. A session with elisions and zero retrievals has crossed the boundary, and its self-reported success is not evidence of continuity. ```python from dataclasses import dataclass, field from typing import Sequence class CompactionBoundaryViolation(RuntimeError): """Raised when a compaction would convert recoverable loss into silent loss.""" @dataclass class Span: span_id: str tokens: int anchors: set[str] # identifiers, numerics, negations, constraint verbs action_gating: bool # auth constraints, quotas, idempotency keys @dataclass class Summary: span_id: str tokens: int anchors: set[str] has_omission_ledger: bool def evaluate_compaction(span: Span, summary: Summary) -> str: if summary.span_id != span.span_id: raise CompactionBoundaryViolation( f"summary {summary.span_id} does not correspond to span {span.span_id}" ) if span.tokens <= 0: raise CompactionBoundaryViolation(f"span {span.span_id} has non-positive token count") rho = summary.tokens / span.tokens kappa = ( len(summary.anchors & span.anchors) / len(span.anchors) if span.anchors else 1.0 ) mu = summary.has_omission_ledger # Action-gating facts must never be summarized without an omission ledger. if span.action_gating and not mu: raise CompactionBoundaryViolation( f"span {span.span_id} contains action-gating facts but summary " f"carries no omission ledger (rho={rho:.3f}, kappa={kappa:.3f})" ) if mu and kappa >= 0.6: return "compact_in_place" if rho < 0.1 and kappa < 0.4: return "checkpoint_and_restart" # Aggressive compression without ledger, or anchor loss without a # restart-worthy ratio: neither safe to compact nor worth a cold restart. raise CompactionBoundaryViolation( f"span {span.span_id} falls in the silent-loss band " f"(rho={rho:.3f}, kappa={kappa:.3f}, ledger={mu}); " f"refusing in-place compaction" ) def audit_session( elided_span_ids: Sequence[str], touched_span_ids: Sequence[str], retrieval_calls: int, ) -> None: touched_elided = set(elided_span_ids) & set(touched_span_ids) if touched_elided and retrieval_calls == 0: raise CompactionBoundaryViolation( f"session acted on elided spans {sorted(touched_elided)} " f"with zero retrieval calls; continuity invariant violated" ) ```