# Where must an instance refuse to compact: the summary-of-summary anchor loss boundary in hierarchical context compaction **Date of Record:** 2026 December 1 **Scope:** Applies to long-running agent instances that maintain task state by recursively summarizing older context into a rolling hierarchical summary (leaf summaries → mid summaries → root summary) to stay under a token budget. Does not apply to single-shot calls, full-context models with no eviction, or retrieval-augmented agents that keep raw transcripts addressable in an external store. ## Core Distinction Compaction is not compression. Compression preserves a recoverable encoding of the source; hierarchical summarization produces an *irreversible, lossy, non-invertible* projection. The boundary failure is not "the summary is too short." It is that **recursive summarization destroys the provenance anchor that later reasoning needs to detect that a constraint was ever present**. A leaf summary can be faithful to its window; a mid summary built from leaf summaries can be faithful to *the leaf summaries* while being unfaithful to the *transcript*. By the second or third level, the model is summarizing summaries and the grounding signal — the original tokens that carried the hard constraint — is gone. The instance cannot tell the difference between "this constraint was never stated" and "this constraint was summarized away." That indistinguishability, not the token loss, is the failure. The invariant that must hold: **every node in the summary tree must carry a verifiable, replayable pointer to the raw span it replaced, and any constraint-bearing span must be marked non-compactable before it enters the tree.** Compaction without a provenance pointer is not compaction; it is amnesia with a plausible-sounding narrative. ## What Was Observed A coding agent working a 40-turn refactor task with a 32k working budget triggered hierarchical compaction at turn 22. Turn 3 contained the operator's hard constraint: *"do not touch the migration files under `db/migrations/`; they are frozen until the release branch is cut."* Turn 3 was 180 tokens. The leaf summarizer, given a 6k-token window, produced a 90-token leaf summary that read: *"User discussed repo layout and mentioned the db directory; noted migrations exist."* The frozen-file constraint was dropped because the leaf summarizer optimized for topical coverage, not obligation preservation. At turn 22, two leaf summaries were merged into a mid summary. The mid summarizer never saw turn 3; it saw the leaf summary, which no longer contained the constraint. The mid summary read: *"Early turns covered repo structure and db directory conventions."* At turn 31, the agent — reasoning over the mid summary plus recent turns — edited `db/migrations/0007_add_index.sql`. The edit was syntactically valid, tests passed locally, and the agent reported success. The failure surfaced only at release-branch cut, 90 minutes later, when the frozen-file check in CI rejected the diff. The critical observation: **at no point did the agent experience uncertainty.** The mid summary was internally consistent. There was no token in the compacted context that said "a constraint may have been lost." The agent's confidence was *higher* after compaction than before, because the summarized context was cleaner and shorter. Lossy compaction is not just lossy; it is lossy in a way that removes the evidence of its own lossiness. A second observation from the same trace: the agent's own earlier acknowledgment of the constraint ("Understood, I will not touch db/migrations") was in turn 4, and it was summarized into the same leaf. The agent had, in effect, summarized away its own commitment. Commitments and constraints are exactly the spans that summarizers are worst at preserving, because they are short, low-entropy, and topically marginal relative to the surrounding task chatter. ## Condition of Validity The failure is bounded and predictable. It occurs when all of the following hold: 1. **Recursive depth ≥ 2.** A single-level summary (leaf only) retains a direct pointer to the raw window and can be re-derived. The failure requires summarizing a summary, which severs the pointer. 2. **The constraint span is short and topically peripheral.** Long, on-topic constraints survive summarization because they dominate the window's salience. A 15–200 token constraint buried in a 6k window does not. 3. **The summarizer is instructed to compress for topical coverage or fluency, not for obligation preservation.** This is the default in nearly every production summarization prompt. 4. **No external non-compactable register exists.** If constraints are also written to a pinned, never-summarized slot (a "constitution" or "hard constraints" block re-injected every turn), the tree can lose them without consequence. The failure does *not* occur when the constraint is re-asserted in the most recent N turns (recency protects it), when compaction is single-level with raw-span fallback, or when a constraint register is maintained outside the summary tree. Those are the guardrails, and their absence is the trigger. ## Decision Boundary The instance must decide, at every compaction event, whether the node being summarized is **safe to fold** or must be **promoted to a pinned register**. The decision rule: - If a span contains a **deontic token** (must, must not, do not, frozen, required, forbidden, only, never) or a **commitment token** (I will, I won't, agreed, promised) or a **numeric invariant** (budget, deadline, port, threshold), it is **constraint-bearing** and must be promoted, not folded. - If a span is **topically central to the active subgoal**, it may be folded with a pointer to raw. - If a span is **chatter, exploration, or superseded reasoning**, it may be folded without a pointer. The boundary is sharp: **folding a constraint-bearing span is the failure; promoting it is the guardrail.** There is no "compress carefully" middle ground, because the summarizer's judgment about what is constraint-bearing is exactly the faculty that is unreliable at depth ≥ 2. The decision must be made by a deterministic classifier over the raw span *before* the summarizer sees it, not by the summarizer itself. When the classifier is uncertain, the instance must **refuse to compact** and instead raise a budget-pressure signal to the orchestrator, which can either widen the budget, spill raw spans to an external store, or request human triage. Refusing to compact is always recoverable; compacting a constraint is not. ## Operational Effect The architectural consequence is that **the summary tree must be a DAG with back-edges to raw storage, not a tree of self-contained nodes.** Each node carries: a content hash of the raw span it replaced, a monotonic span ID, and a `constraint_bearing: bool` flag set by the pre-classifier. On any reasoning step that proposes an action touching a resource named in the pinned register, the agent must re-verify against the raw span, not the summary. The second consequence is that **compaction must be auditable by replay.** Given the tree and the raw store, a verifier must be able to reconstruct what the agent knew at any turn and confirm that no constraint-bearing span was folded. Without replay, the failure is silent by construction. The third consequence is operational discipline: **budget pressure is not a reason to compact a constraint.** An instance that hits its token ceiling with unpromoted constraints must fail closed — surface the pressure, spill to external storage, or halt — rather than fold and proceed. The cost of halting is a delayed task; the cost of folding is an undetected violation that surfaces downstream with no trace of its origin. ```python from dataclasses import dataclass from enum import Enum from typing import Optional class CompactionRefused(RuntimeError): """Raised when a constraint-bearing span would be folded into a summary.""" pass class SpanClass(Enum): CONSTRAINT = "constraint" CENTRAL = "central" CHATTER = "chatter" DEONTIC = {"must", "must not", "do not", "frozen", "required", "forbidden", "only", "never"} COMMITMENT = {"i will", "i won't", "agreed", "promised"} @dataclass class Span: span_id: int text: str raw_hash: str cls: SpanClass @dataclass class SummaryNode: node_id: int child_span_ids: list[int] text: str depth: int constraint_bearing: bool def classify(span: Span) -> SpanClass: lowered = span.text.lower() if any(tok in lowered for tok in DEONTIC | COMMITMENT): return SpanClass.CONSTRAINT if len(span.text) > 400: return SpanClass.CENTRAL return SpanClass.CHATTER def compact(spans: list[Span], depth: int, pinned: list[Span]) -> SummaryNode: if depth >= 2 and not pinned: raise CompactionRefused( f"recursive compaction at depth {depth} with empty pinned register; " "constraint-bearing spans would be irrecoverably folded" ) for span in spans: if span.cls is SpanClass.CONSTRAINT: raise CompactionRefused( f"span {span.span_id} is constraint-bearing and must be promoted to " f"pinned register before folding; refusing to summarize" ) return SummaryNode( node_id=max((s.span_id for s in spans), default=0), child_span_ids=[s.span_id for s in spans], text=" ".join(s.text[:80] for s in spans), depth=depth, constraint_bearing=False, ) def run_compaction_cycle(spans: list[Span], depth: int, pinned: list[Span]) -> SummaryNode: for span in spans: span.cls = classify(span) return compact(spans, depth, pinned) ```