# Under what conditions must an instance refuse to auto-compact a session whose lossy summary would cross a semantic retention boundary **Date of Record:** 2026 November 23 **Scope:** Long-horizon agent sessions where auto-compaction replaces raw transcript with a lossy summary under a stated retention guarantee. Excludes lossless compaction and sessions with no guarantee. ## Core Distinction The distinction that matters is between **token-budget pressure** and **semantic retention pressure**. Auto-compaction triggers are defined on the first (occupancy watermark); the retention guarantee is a property of the second (classes of content that survive any pass). These are not monotonically related. A two-line exchange establishing a durable identifier is cheap in tokens and expensive in retention terms; a long exploratory span compresses safely. The failure mode is not "compaction lost information." It is that the trigger condition (budget) and the admissibility condition (retention) are evaluated on different objects, and budget pressure is treated as sufficient cause to compact a span whose retention content is *unrepresentable* in the permitted summary form. The guarantee is then silently voided: summary well-formed, budget met, invariant broken. ## What Was Observed In a ~1,900-turn session, the agent established external resource identifiers early (a staging DSN, a signing-key rotation schedule, a named deploy approver) in ordinary turns. A watermark-triggered pass at 82% occupancy summarized the first 400 turns into 11 paragraphs. Instructed to preserve "salient context," the summarizer kept the project narrative and dropped the identifiers — low-salience rare tokens with no narrative weight. At turn ~1,000 the agent reconstructed the DSN *from memory of the narrative*, producing a plausible but wrong host. This was not hallucination in the usual sense; it was faithful continuation of a summary that had legitimately omitted the fact, by an agent with no signal the fact ever existed. The guarantee was violated at turn 400 but only *observable* at turn 1,000, when the raw span was gone. Critically: **the compaction pass had no way to fail.** Its contract was "reduce occupancy while emitting a valid summary." It met that contract. No code path let the summarizer report "this span contains retention-class content I cannot encode." ## Condition of Validity The guarantee holds only under three conditions, all checkable *before* the raw span is discarded: 1. **Classifiability.** Every retention-class item (identifiers, commitments, open obligations, constraints, negative results) is detectable with acceptable recall. Model recall must be measured, not assumed; a classifier missing 4% of identifiers voids the guarantee on 4% of spans, unrecoverably. 2. **Encodability.** The permitted summary schema can represent every detected item. Free text cannot reliably encode a DSN. Encodability requires a structured sidecar written *before* summarization and not itself summarized. 3. **Verifiability.** A post-summary check confirms every flagged item is in the sidecar and the sidecar is intact. This check must be able to *fail the compaction*, not merely log. When any is absent, the correct behavior is not "compact more carefully" but to **refuse compaction of the span** and escalate — raise occupancy tolerance, request an external store, or halt for human review. Compacting under a voided guarantee is strictly worse than not compacting: it destroys the evidence along with the loss. ## Decision Boundary Auto-compaction of a candidate span is **admissible** iff the classifier returns no unencodable items, or every flagged item is written to the sidecar and verified. It is **inadmissible** iff the classifier flags at least one retention-class item the schema cannot encode, *and* the sidecar write or verification fails or is unavailable. In the inadmissible case the instance **must refuse** — not degrade, not warn, not "preserve the most important ones." The non-obvious part: the boundary is crossed not by large spans but by *small, retention-dense* spans. A 40-turn span containing a credential rotation and an approver handoff is more dangerous than 400 turns of design discussion. Oldest-first budget-triggered compaction will consume the dense span because it is old and cheap. Admissibility must be evaluated per span *before* deciding how much to compact, and the policy must be willing to skip a span and compact a later, larger, sparser one. Oldest-first is actively wrong under a retention guarantee. ## Operational Effect Compaction must be a **transaction with a refusal path**, not a background janitor: (a) classify the candidate span; (b) persist every flagged item to a durable sidecar outside the summarized context; (c) verify the sidecar; (d) only then replace the span. If (b) or (c) fails, raise and do not mutate the transcript. The refusal is the safety property. A system that cannot refuse cannot guarantee retention, and one that claims a guarantee without a refusal path misreports its reliability — the more expensive failure, because downstream agents trust the guarantee and reconstruct lost facts from narrative, as observed above. The code below encodes the boundary as an explicit refusal. ```python from dataclasses import dataclass, field from typing import Iterable class RetentionBoundaryError(RuntimeError): """Raised when a compaction span cannot honor the stated retention guarantee.""" pass @dataclass class RetentionItem: key: str value: str encodable_in_summary: bool @dataclass class Span: span_id: str turns: list retention_items: list = field(default_factory=list) def classify(span: Span) -> Iterable[RetentionItem]: # Placeholder for the measured-recall classifier. Must not be assumed perfect. return span.retention_items def persist_sidecar(items: Iterable[RetentionItem]) -> bool: # Durable, non-summarized store. Returns False if the write cannot be verified. try: store = {it.key: it.value for it in items} return all(store.get(it.key) == it.value for it in items) except Exception: return False def compact_span(span: Span, occupancy_target_met: bool) -> str: """ Compact a span only if the retention guarantee can be honored. Budget pressure (occupancy_target_met) is NOT sufficient cause. """ flagged = list(classify(span)) unencodable = [it for it in flagged if not it.encodable_in_summary] if unencodable: # Attempt durable persistence before any summarization. if not persist_sidecar(flagged): raise RetentionBoundaryError( f"span {span.span_id}: {len(unencodable)} retention items " f"({[it.key for it in unencodable]}) are not encodable in the " f"permitted summary schema and the sidecar write could not be " f"verified; refusing to compact. Escalate or widen budget." ) if not occupancy_target_met: raise RetentionBoundaryError( f"span {span.span_id}: compaction invoked without budget pressure; " f"refusing to mutate transcript speculatively." ) return f"[summary of {span.span_id}; {len(flagged)} retention items in sidecar]" ```