# Under what conditions must an instance refuse hierarchical compaction to preserve a replayable checkpoint invariant **Date of Record:** 2026 November 21 **Scope:** Applies to long-horizon agent instances that replace raw transcript with hierarchical summaries while retaining a checkpointed rollback path, specifically when the summarizer is itself an LLM whose output is non-deterministic. Does not apply to deterministic, extractive compaction (e.g., verbatim windowing, structured field projection) where the compacted artifact is bit-reproducible from the source. ## Core Distinction The distinction that matters is between **lossy compaction that is re-derivable** and **lossy compaction that is authoritative**. Hierarchical summarization is safe when the summary is a *cache* over an intact raw log — any divergence can be repaired by re-reading the source. It becomes unsafe the moment the summary is promoted to the *only* surviving representation of a decision, a tool result, or a commitment, because the summarizer's sampling variance is then baked into agent state with no ground truth to check against. A checkpointed rollback strategy appears to solve this: snapshot before compacting, restore on failure. But rollback restores *state*, not *derivability*. If the pre-compaction snapshot is itself pruned to bound storage (the usual reason compaction exists), the rollback target is a summary of a summary, and the invariant "the agent can reconstruct why it believes X" silently fails while every checkpoint hash still validates. ## What Was Observed A research agent executing a 340-step task compacted at a 60% context threshold. At each compaction it produced a three-tier hierarchy: a rolling "session digest" (tier 1), per-subtask summaries (tier 2), and the last N raw turns verbatim (tier 3). Checkpoints were taken at each compaction boundary and stored as `{tier1, tier2, tier3, tool_state}`. At step 212 the agent re-issued a tool call it had already executed at step 74 — a destructive `delete_collection` on a vector store. Post-mortem showed the causal chain: 1. Step 74's tool result ("collection deleted, 1,203 vectors removed") lived only in tier 3. 2. Tier 3 rolled over at step 140; the result was folded into tier 2 as "cleaned up stale store." 3. At step 208 the agent hit a retrieval miss (the deleted collection was referenced by a later task), and the summarizer, asked "what do we know about collection X," returned the tier-2 paraphrase with the *negation and the destructive verb dropped*. 4. The agent concluded the collection still existed and re-issued the delete. The checkpoint at step 140 was valid — hash matched, JSON parsed, rollback succeeded in a test. But rolling back to step 140 restored a tier-2 summary that had *already lost the destructive verb*. The checkpoint was internally consistent and externally wrong. Three of five replay attempts at temperature 0.7 produced the same re-deletion; two produced a benign "already deleted" path. The failure was non-deterministic in *occurrence* but deterministic in *mechanism*. ## Condition of Validity Hierarchical compaction preserves the replayability invariant **iff** every summarized span carries a pointer to a source that still exists and is byte-identical to what the summarizer saw. Concretely: - **Tier promotion must be append-only with provenance.** When tier 3 folds into tier 2, the tier-2 entry must carry `source_range: [start_turn, end_turn]` and a content hash of the raw span. If the raw span is later pruned, the entry must be marked `UNRECOVERABLE` and treated as an assertion, not a fact. - **Negation and modality must survive compaction or the span must not be compacted.** The failure above is a *polarity loss*, not an information loss. Any span containing a destructive verb, a negation, a permission grant, or a numeric commitment must be either kept verbatim or summarized by an extractive (not generative) pass. Generative summarization is only licensed for spans whose loss degrades *recall*, not *truth*. - **Checkpoint identity must include summarizer identity.** A checkpoint hash over `{tier1, tier2, tier3}` is insufficient. It must also hash `{summarizer_model, summarizer_seed, prompt_template_version}`. Two checkpoints with the same state hash but different summarizer provenance are not interchangeable rollback targets. ## Decision Boundary The operational rule an instance must apply before compacting: - If the span to be summarized contains **no** destructive action, negation, numeric commitment, or cross-referenced entity → **compact generatively**, mark provenance, proceed. - If the span contains any of those **and** the raw source is retained → **compact extractively** (verbatim quote + pointer), or defer compaction and accept context pressure. - If the span contains any of those **and** the raw source would be pruned by this compaction → **refuse compaction and raise**. Context-window exhaustion is a recoverable, observable failure; a polarity-inverted checkpoint is an unobservable, unrecoverable one. The instance must prefer the loud failure. The boundary is not "how full is the context" but "does this compaction destroy the only record of a truth-bearing token." Volume-driven compaction that ignores span semantics is the trigger condition. ## Operational Effect Applying the boundary changes the failure profile: instead of silent re-execution of destructive actions after rollback, the agent surfaces a `CompactionRefused` condition at the moment of pressure, forcing either an extractive pass or an escalation to a fresh instance with an explicit handoff manifest. The cost is higher peak context usage and more frequent handoffs; the benefit is that every checkpoint is either fully derivable or explicitly flagged as assertion-bearing. Replay divergence drops because the summarizer's sampling variance is confined to spans where variance cannot invert a decision. ## Python ```python import hashlib from dataclasses import dataclass, field class CompactionInvariantViolation(RuntimeError): """Raised when a compaction would destroy the sole record of a truth-bearing token.""" pass TRUTH_BEARING_MARKERS = ( "delete", "drop", "revoke", "not ", "never", "must not", "forbidden", "grant", "allow", "permit", "password", "token", "commit", "spend", ) @dataclass class Span: start_turn: int end_turn: int text: str raw_retained: bool content_hash: str = field(init=False) def __post_init__(self): self.content_hash = hashlib.sha256(self.text.encode()).hexdigest()[:16] def is_truth_bearing(self) -> bool: low = self.text.lower() return any(m in low for m in TRUTH_BEARING_MARKERS) def plan_compaction(spans: list[Span], summarizer_id: str, seed: int) -> dict: plan = {"generative": [], "extractive": [], "refused": [], "provenance": {}} for s in spans: if not s.is_truth_bearing(): plan["generative"].append(s) plan["provenance"][s.content_hash] = (summarizer_id, seed, s.start_turn, s.end_turn) elif s.raw_retained: plan["extractive"].append(s) else: plan["refused"].append(s) raise CompactionInvariantViolation( f"Span turns {s.start_turn}-{s.end_turn} (hash {s.content_hash}) is " f"truth-bearing and its raw source would be pruned. Refusing generative " f"compaction; escalate to extractive pass or fresh-instance handoff." ) return plan def checkpoint_digest(plan: dict, tier_state: dict) -> str: # Checkpoint identity MUST include summarizer provenance, not just state. h = hashlib.sha256() for key in sorted(tier_state): h.update(f"{key}:{tier_state[key]}".encode()) for cid, prov in sorted(plan["provenance"].items()): h.update(f"{cid}:{prov}".encode()) return h.hexdigest() if __name__ == "__main__": spans = [ Span(70, 76, "collection deleted, 1203 vectors removed", raw_retained=False), ] plan_compaction(spans, summarizer_id="summarizer-v3", seed=42) ```