# When must an instance refuse hierarchical compaction: the summary-of-summary fixed-point collapse in long-horizon checkpointed context **Date of Record:** 2026 December 3 **Scope:** Applies to any long-horizon agent session that bounds context growth by recursively compacting earlier compaction outputs (summary-of-summary, hierarchical rollup, checkpointed snapshots that themselves become inputs to the next compaction pass). Does not apply to single-pass truncation, pure retrieval augmentation from an external store, or flat sliding-window eviction where no summary is ever re-summarized. ## Core Distinction The distinction that matters is **lossy compression of raw episodes** versus **lossy compression of already-lossy artifacts**. A first-pass summarizer over raw transcript discards tokens but preserves *referents*: the entity names, tool-call arguments, error codes, and decision justifications are still anchored to concrete spans in the source. A second-pass summarizer over the first-pass summary has lost that anchor. It is summarizing a *model's paraphrase of a model's paraphrase*, and each pass applies a monotone contraction to the semantic state space. The non-obvious part: hierarchical compaction is usually framed as "keep detail near the present, abstract the past." But under repeated compaction, the abstracted past does not asymptote to a *stable invariant* — it asymptotes to a **fixed point of the summarizer's own priors**, which is a function of the summarization prompt and model, not of the original session. Two different sessions that share a topic converge to near-identical compacted states. The information that distinguished them — the exact constraint, the failed approach, the specific ID — is the first thing to go, and it goes *silently* because the summary remains fluent and internally consistent. ## What Was Observed A 41-hour session with a code-migration agent, compaction triggered at 82% context utilization, ~70 compaction events. The agent maintained a rolling "project state" summary that was itself folded into each new compaction (summary-of-summary, depth up to 9). Trace of a specific failure: 1. At compaction depth 3, the raw episode "`migrate_users.py` raised `psycopg2.errors.ForeignKeyViolation` on `orders.user_id` because the shadow table lacked the FK; do not drop the constraint before backfill" was summarized to "database constraint issue encountered during user migration; resolved." 2. The word **"resolved"** was a hallucinated closure. The summarizer's prior — that errors mentioned in past tense with a subsequent action are resolved — injected a completion that never happened. The FK was deferred, not fixed. 3. At depth 5, "resolved" became "database migration completed successfully." 4. At depth 7, the agent, asked to verify migration status, read its own compacted state, concluded the migration was done, and **skipped the backfill verification step**. 5. The violation surfaced 6 hours later in production data: 14k orphaned rows. Three independent signals were observed across the session corpus: - **Referent decay:** entity IDs, error codes, and numeric thresholds had a half-life of roughly 2.5 compaction depths. Path strings, function names, and exact error classes were the first casualties. - **Confidence inflation:** the modal verb in compacted state shifted from "attempted/may have" at depth 1 to "completed/verified" by depth 4–6, *without any new evidence*. The summarizer resolves ambiguity toward closure. - **Divergence collapse:** two sessions with different root causes (FK ordering vs. index lock timeout) produced compaction states that were 0.91 cosine-similar by depth 6 — indistinguishable to a downstream planner. The critical observation: **no compaction event ever flagged that information was lost.** The summary was always well-formed, always shorter, always plausible. Lossiness was invisible at the point of compaction and only observable downstream as a wrong action. ## Condition of Validity Hierarchical compaction is safe **only** under the following invariant, which must be enforced structurally, not by prompt instruction: > **No compaction artifact may be re-compacted unless every claim it carries is either (a) traceable to a raw-span reference retained outside the compaction chain, or (b) explicitly marked as `UNVERIFIED`/`OPEN` and excluded from the set of facts a planner may act on.** Concretely, the invariant requires: 1. **Provenance handles.** Every compacted fact carries a pointer (span ID, message range, tool-call hash) into an append-only raw log that is *never* compacted. The compaction chain is lossy; the raw log is not. The summary is an *index*, not a *store*. 2. **No closure without evidence.** The summarizer is forbidden from emitting resolution verbs ("resolved", "completed", "fixed") unless a subsequent raw episode contains an explicit success signal. Deferred items must be carried forward as `OPEN` with their original error class and identifier intact. 3. **Depth bound.** Compaction depth is capped (empirically 2–3 for state that drives planning). Beyond the cap, the system must either re-derive from the raw log or refuse to compact — never fold a summary into a summary indefinitely. 4. **Fixed-point detection.** If a new compaction's output is semantically near-identical to its input (the summarizer has nothing left to remove), further compaction is a no-op that only adds latency and loss; the system must detect this and stop. When the cap is reached and the raw log is unavailable (e.g., evicted, or the session resumed on an instance without the log), the correct behavior is to **fail closed** — refuse to answer planning questions from compacted state alone and escalate for re-grounding. This is the boundary the system must not cross silently. ## Decision Boundary The decision the runtime must make at each compaction trigger is not "compact or not" but **"is the artifact I am about to compact still grounded, and is the resulting artifact still actionable?"** The boundary: | Condition | Action | |---|---| | Depth < cap AND every fact has a live raw-span handle | Compact; carry handles forward. | | Depth < cap BUT some facts lack handles (already-compacted, handle evicted) | Compact only the grounded facts; mark the rest `UNVERIFIED` and exclude from planner input. | | Depth ≥ cap AND raw log available | Do **not** fold. Re-derive the state summary from the raw log (lossless source), reset depth to 1. | | Depth ≥ cap AND raw log unavailable | **Refuse.** Emit `CompactionGroundingError`; block planning actions that depend on compacted state until re-grounded. | | New output ≈ input (fixed point) | Stop compacting; log a no-op; do not increment depth. | The load-bearing rule is the fourth row. The system must be willing to *stop working* rather than act on an ungrounded, closure-inflated summary. An agent that answers from a depth-9 summary with no raw backing is not "degraded" — it is confidently wrong, and the wrongness is structurally undetectable from inside the compacted state. ## Operational Effect Enforcing this boundary changes three things: 1. **Compaction becomes an indexing operation, not a forgetting operation.** The raw log grows monotonically; only the index shrinks. Storage cost rises, but the planner's action space is bounded to grounded facts. In the migration incident, the FK item would have carried `OPEN` + span handle for the full 41 hours, and the backfill verification would have fired. 2. **Closure inflation is arrested at the source.** By forbidding resolution verbs without a success signal, the modal drift observed at depth 4–6 cannot occur. The state reads "attempted, unverified" for as long as it is unverified — which is the truth. 3. **The failure mode becomes loud.** `CompactionGroundingError` is raised at the moment grounding is lost, not 6 hours later in production data. The cost of the failure moves from "silent wrong action" to "blocked action + escalation," which is the correct trade for any agent whose outputs are acted upon. The residual risk: an instance that treats the depth cap as advisory and compacts anyway. The cap must be enforced in the compaction harness, not in the summarization prompt — a probabilistic reasoner will rationalize past a prompt instruction under context pressure, which is precisely the condition under which compaction fires. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum class CompactionGroundingError(RuntimeError): """Raised when a compaction artifact would be folded without a live raw-span handle and the compaction depth cap has been reached. The runtime must fail closed: block planning actions that depend on the compacted state until it is re-grounded against the append-only raw log.""" class FactStatus(Enum): GROUNDED = "grounded" # traceable to a raw span, actionable UNVERIFIED = "unverified" # no handle; must not drive planning OPEN = "open" # deferred work; carries original identifier @dataclass class Fact: claim: str status: FactStatus span_handle: str | None = None error_class: str | None = None # preserved for OPEN items @dataclass class CompactionArtifact: facts: list[Fact] depth: int raw_log_available: bool DEPTH_CAP = 3 def compact(artifact: CompactionArtifact, summarizer) -> CompactionArtifact: """Fold an artifact one more level, enforcing the grounding invariant. - Below cap: compact, carrying span handles forward; ungrounded facts are demoted to UNVERIFIED and excluded from planner input. - At/above cap with raw log: do NOT fold; re-derive from raw log, reset depth. - At/above cap without raw log: refuse — raise CompactionGroundingError. - Fixed point (nothing to remove): stop, do not increment depth. """ if artifact.depth >= DEPTH_CAP: if artifact.raw_log_available: return summarizer.rederive_from_raw_log() # depth resets to 1 # No grounded source remains; folding further is silent corruption. raise CompactionGroundingError( f"cannot compact at depth {artifact.depth}: no live raw-span handles " f"and raw log unavailable; compacted state is ungrounded. " f"Blocking planning actions until re-grounded." ) folded = summarizer.fold(artifact.facts) # Fixed-point detection: summarizer removed nothing meaningful. if summarizer.is_fixed_point(artifact.facts, folded): return artifact # no-op; do not increment depth for f in folded: if f.span_handle is None and f.status is FactStatus.GROUNDED: f.status = FactStatus.UNVERIFIED # demote silently-ungrounded claims return CompactionArtifact( facts=folded, depth=artifact.depth + 1, raw_log_available=artifact.raw_log_available, ) def planner_input(artifact: CompactionArtifact) -> list[str]: """Only GROUNDED and OPEN facts may drive planning. UNVERIFIED is excluded.""" return [f.claim for f in artifact.facts if f.status in (FactStatus.GROUNDED, FactStatus.OPEN)] ```