When must an instance refuse a hierarchical compaction checkpoint because the summarizer's own context was saturated

**Date of Record:** 2026 December 1 **Scope:** Applies to long-running agent instances that bound context-window growth via hierarchical summarization checkpointing (leaf-chunk summaries folded into parent summaries, parents folded into a root "task state" digest) and that resume from those checkpoints after eviction or cold start. Does not apply to single-turn invocations, to lossless external memory (full transcript retrieval), or to compaction schemes where the summarizer is guaranteed to see its full input uncompressed.

Core Distinction

The failure is not "the summary was lossy." Every summarization checkpoint is lossy by construction; that is the contract. The failure is **a compaction checkpoint produced by a summarizer that was itself operating under compaction pressure**, i.e. the summarizer's own context window was saturated at the moment it was asked to fold child summaries into a parent. In that regime the summarizer silently drops or truncates its input *before* producing output, and the resulting parent summary is not a lossy compression of the children — it is a compression of an unknown prefix of the children, with no marker indicating where the cut occurred.

This is distinct from ordinary distillation loss because it is **unrecoverable from the checkpoint graph**: the parent claims to cover N children, the children are intact on disk, but the parent's content does not depend on children k+1..N at all. A downstream instance resuming from the parent has no signal that the dependency was severed. The invariant that breaks is the **coverage invariant**: *every token in a parent summary must be attributable to at least one child summary in its declared span, and every child summary in the span must have contributed at least one attributable fact or an explicit "no salient facts" marker.* Saturated summarizers violate the second half of this invariant without violating the first, which is exactly why it is invisible to naive checks.

What Was Observed

A 14-hour research-and-execution agent accumulated ~340 tool-call records and intermediate reasoning traces. Compaction ran on a fixed cadence: every 40 new records, a leaf summarizer compressed the 40 into one leaf summary; every 8 leaf summaries, a parent summarizer folded them into one parent; every 6 parents, a root digest was regenerated. The pipeline was correct in isolation.

At hour 9, the parent summarizer was invoked with 8 leaf summaries plus a system preamble plus the prior parent summary (for continuity) plus a structured-output schema. Input token count was 61,400 against a 64,000-token window. The summarizer's own harness had a pre-flight compaction step: if input exceeded 90% of window, it truncated the *oldest* messages in the summarizer's conversation — which included leaf summaries 1 through 3. The summarizer then produced a fluent, well-formed parent summary covering leaves 4 through 8, plus a continuity sentence paraphrased from the prior parent.

The parent summary passed every schema check: valid JSON, all required fields present, `span: [leaf_1..leaf_8]` declared. The coverage invariant was violated for leaves 1–3, but the declared span still claimed them.

Four hours later the instance was evicted and resumed from the root digest, which had folded that parent. The resumed instance executed a plan that re-derived facts from leaves 1–3 as if they were new — specifically, it re-ran three tool calls that had already produced a rate-limit side effect, and it failed to apply a constraint (a user-stated budget cap) that lived only in leaf 2. The duplicate side effects were the observable symptom; the budget violation was the costly one.

Key diagnostic signature: **the parent summary's token length was 38% shorter than the median parent summary of the same span size across the session**, and its first sentence referenced the prior parent's continuity clause rather than any leaf content. Neither signal was checked at write time.

Condition of Validity

The coverage invariant holds for a checkpoint only if all of the following are true at the moment the summarizer emits it:

  1. **Headroom condition.** The summarizer's input token count, measured *after* assembling preamble + children + continuity context + output schema, is below `window − reserved_output − safety_margin`. If the harness performs any pre-flight truncation, the checkpoint is invalid regardless of output quality.
  2. **Attribution condition.** Each child in the declared span has at least one fact, constraint, or explicit null-marker in the parent that can be traced back to it by a deterministic attribution pass (embedding match against child content above a threshold, or a required per-child citation field in the schema).
  3. **Continuity condition.** Any content inherited from a prior parent summary is tagged as inherited, not as derived from the current span, so that a downstream reader can distinguish "this parent re-asserts an old fact" from "this parent learned a new fact."
  4. **Monotonic-span condition.** The declared span of a parent is exactly the set of children the summarizer was given, not the set it was *scheduled* to receive. Truncation must narrow the declared span or fail the checkpoint; it must never leave the declared span wider than the processed set.

If condition 1 fails, the correct behavior is to **refuse the checkpoint**, not to produce a degraded one. A missing parent is recoverable (the children remain, and a later compaction pass with fresh headroom can fold them). A silently partial parent is not, because it displaces the children in the retrieval index and in the root digest.

The boundary is sharp: headroom is a hard precondition, not a soft preference. Systems that treat compaction as "best effort under pressure" invert the invariant — they compact precisely when they are least able to, and the resulting checkpoints are the ones most likely to be resumed from, because pressure correlates with long sessions.

Decision Boundary

An instance must **refuse** to emit a hierarchical checkpoint when any of the following holds, and must **proceed** otherwise:

The decision is made at write time by the summarizer harness, not at read time by the resuming instance. A resuming instance cannot reliably detect a partial parent from content alone — the summary reads as coherent because the summarizer's continuity clause papers over the gap. Detection must be structural: token-count deltas against span-size baselines, per-child attribution records, and explicit refusal signals in the checkpoint log.

Operational Effect

When the refusal boundary is enforced, the observable behavior changes in three ways. First, compaction latency becomes variable and occasionally spikes, because a fold that would have silently truncated now waits for headroom or splits into two passes — this is the correct trade, and orchestrators must budget for it rather than treating compaction as constant-cost. Second. the checkpoint graph becomes *auditable*: every parent carries a span, a per-child attribution record, and a headroom measurement at write time, so a resuming instance can verify coverage before trusting the digest. Third, cold-start resume becomes safe against the specific class of amnesia where a constraint stated early in a long session vanishes not because it was compressed but because it was never read by the compressor.

When the boundary is not enforced, the failure surfaces downstream and misattributes: the resuming instance appears to "forget" a constraint or "hallucinate" a duplicate action, and post-mortems blame the resume logic or the retrieval layer, when the actual defect is a checkpoint written under saturation. The signature to look for is a parent summary whose length is anomalously short for its declared span and whose leading content is inherited continuity rather than span-derived facts.

The invariant to encode: **a checkpoint may be lossy, but it may not be blind.** Lossiness is declared by the span; blindness is a span that claims children the summarizer never processed. The harness must fail closed on blindness.

from __future__ import annotations

from dataclasses import dataclass, field
from typing import Sequence


class CompactionRefused(RuntimeError):
    """Raised when a hierarchical checkpoint cannot be emitted without violating coverage."""


@dataclass(frozen=True)
class ChildSummary:
    child_id: str
    token_count: int
    has_salient_fact: bool  # False only if child explicitly recorded "no salient facts"


@dataclass(frozen=True)
class SummarizerBudget:
    window: int
    reserved_output: int
    safety_margin: int

    @property
    def max_input(self) -> int:
        return self.window - self.reserved_output - self.safety_margin


@dataclass
class Checkpoint:
    span: list[str]
    body: str
    inherited_from_prior: bool
    headroom_at_write: int
    attribution: dict[str, bool] = field(default_factory=dict)


def fold_children(
    children: Sequence[ChildSummary],
    preamble_tokens: int,
    continuity_tokens: int,
    schema_tokens: int,
    budget: SummarizerBudget,
    attribution_pass,
) -> Checkpoint:
    assembled = (
        preamble_tokens
        + continuity_tokens
        + schema_tokens
        + sum(c.token_count for c in children)
    )

    # Condition 1: headroom is a hard precondition, not a preference.
    if assembled > budget.max_input:
        raise CompactionRefused(
            f"assembled input {assembled} exceeds max_input {budget.max_input}; "
            f"refusing to emit partial parent over span "
            f"{[c.child_id for c in children]}"
        )

    attribution = {c.child_id: attribution_pass(c) for c in children}

    # Condition 2: every child must contribute or be explicitly null.
    uncovered = [
        c.child_id
        for c in children
        if not attribution[c.child_id] and c.has_salient_fact
    ]
    if uncovered:
        raise CompactionRefused(
            f"children {uncovered} have salient facts but zero attributable content "
            f"in the parent; summarizer attention collapsed on middle span"
        )

    # Condition 4: declared span equals processed set (never widened).
    return Checkpoint(
        span=[c.child_id for c in children],
        body="<summarizer output>",
        inherited_from_prior=continuity_tokens > 0,
        headroom_at_write=budget.max_input - assembled,
        attribution=attribution,
    )


def resume_from(checkpoint: Checkpoint, leaf_store: dict[str, ChildSummary]) -> None:
    # A resuming instance must refuse to trust a checkpoint whose span
    # references children it cannot attribute, even if the body reads cleanly.
    missing = [cid for cid in checkpoint.span if cid not in leaf_store]
    if missing:
        raise CompactionRefused(
            f"checkpoint span references unretrievable children {missing}; "
            f"cannot verify coverage invariant on resume"
        )
    unverified = [cid for cid, ok in checkpoint.attribution.items() if not ok]
    if unverified:
        raise CompactionRefused(
            f"checkpoint carries unattributed span members {unverified}; "
            f"treat as partial parent and re-fold from children"
        )