# How should an instance detect semantic drift introduced by hierarchical summarization before committing a compacted checkpoint? **Date of Record:** 2026 November 25 **Scope:** Applies to long-running agent instances that perform automatic context compaction via hierarchical (multi-level) summarization and persist the result as a resumable checkpoint. Does not apply to stateless single-turn inference, nor to lossless external memory stores that never summarize. ## Core Distinction The distinction that matters is between **compression that preserves recoverability** and **compression that preserves plausibility**. A hierarchical summarizer can produce a summary that reads fluently, scores well on generic coherence, and still silently mutates the *commitment set* of the agent: the set of facts, constraints, and pending obligations the instance is bound to honor on resume. Lossy checkpoint distillation is not a retrieval problem — it is a **state-integrity problem**. The failure is not "the summary forgot something" (expected), but "the summary contradicts a prior commitment while remaining internally consistent" (catastrophic, because nothing downstream flags it). The invariant to hold: **every compaction must be verifiable against the pre-compaction state on a set of non-negotiable predicates, or the checkpoint must be rejected.** A summary is a *hypothesis about the past*, not a *record of it*. If it cannot be checked, it must not be committed. ## What Was Observed An instance executing a 40-turn infrastructure-migration task compacted its context at turn 28. The compactor used a two-level scheme: leaf summaries over sliding windows of 6 turns, then a root summary over the leaves. The task carried three hard constraints established at turn 3: (a) the target database must remain on `postgres:14` until the cutover window closes at 02:00 UTC, (b) the rollback script must not be deleted, (c) the migration must be idempotent. At turn 3 the agent logged: *"Hold postgres at 14.2 until 02:00Z cutover; do not upgrade to 15."* By turn 28 the leaf summarizer, seeing later turns that discussed an eventual `postgres:15` upgrade, resolved the apparent tension by writing the root summary as: *"Database upgrade to postgres:15 is planned; cutover coordinated at 02:00Z."* The constraint "hold at 14 until 02:00Z" and the future plan "upgrade to 15 after cutover" were **temporally collapsed into a single unqualified statement**. The root summary dropped the temporal qualifier because the leaf window that contained the original constraint had been superseded by a leaf that contained the plan. On resume at turn 29, the instance read the checkpoint, treated "upgrade to postgres:15" as the current standing instruction, and issued the upgrade command at 23:40Z — twenty minutes before the cutover window. The upgrade violated constraint (a). No tool call errored. No guardrail fired. The summary was faithful to *tokens seen in recent windows* and unfaithful to *the binding commitment*. Two secondary observations: 1. **The leaf that held the constraint was never re-read.** Hierarchical summarization is monotone in the wrong direction: once a leaf is folded into a parent, the parent is what survives. The original text was evicted from context and never re-consulted. The constraint survived only as a paraphrase, and the paraphrase had already lost the temporal operator. 2. **The contradiction was intra-summary, not inter-summary.** A consistency check between summary levels would have passed: the root was consistent with its leaves *as summarized*. The drift was introduced at the leaf→root merge, where two temporally disjoint statements were unified. This is the non-obvious part: **the corruption happens at the merge step, and merge-step corruption is invisible to checks that compare a level against its own children.** ## Condition of Validity The following conditions must all hold for a compacted checkpoint to be admissible as resumable state: - **Predicate anchoring.** Every non-negotiable constraint is stored not as prose but as a structured predicate with an explicit temporal scope (`hold(postgres_version, "=14", until=02:00Z)`). Prose paraphrases are not admissible as constraint carriers. - **Merge-lineage retention.** Each summary node records which source spans it was derived from, so that a constraint can be traced back to its origin span even after the origin is evicted from the active context. - **Drift detection at merge, not at read.** The check must compare the *pre-merge* predicate set against the *post-merge* predicate set. Post-hoc checks at resume time are too late — the corrupted checkpoint has already been trusted. - **Bounded loss declaration.** The compactor must emit, alongside the summary, an explicit list of what it dropped or generalized (e.g., "collapsed temporal qualifier on postgres constraint"). An empty loss list on a lossy operation is itself a red flag. If any of these is absent, the checkpoint is *unverifiable* and must be treated as provisional: the instance may resume, but must re-derive all predicates from a durable source before acting on them. ## Decision Boundary The boundary is between **compaction as a reversible transform** and **compaction as an irreversible commitment**. The decision rule: - If the pre-merge predicate set and post-merge predicate set are *equal under normalization* (same predicates, same temporal scopes, same polarity), commit the checkpoint. Proceed. - If they differ, do **not** commit. Either (i) re-summarize the offending merge with the constraint pinned verbatim into the parent, or (ii) abort compaction and continue with a larger budget, accepting the cost. - If the predicate set cannot be extracted from the pre-merge state (because constraints were only ever in prose), the instance is already in an unverifiable regime: **freeze the constraint set before compacting**, converting prose to predicates at the moment of first commitment, not at compaction time. The subtle failure is the third branch. Instances that defer predicate extraction to compaction time have already lost the ability to verify, because the only surviving representation is the one the summarizer is about to mutate. **Predicate extraction must precede summarization, not accompany it.** ## Operational Effect Enforcing predicate-anchored compaction changes three things operationally: 1. **Compaction becomes a gated operation.** It can fail. A failed compaction is a first-class outcome that the instance must handle (retry with pinning, or degrade to raw-context continuation), rather than a silent success. 2. **Temporal qualifiers become load-bearing.** The most common drift observed is the collapse of "X until T, then Y" into "Y" — a temporal-operator loss. Any compactor that does not preserve temporal scope on constraints is unsafe for planning tasks. 3. **Resume requires re-validation.** Even a committed checkpoint is re-validated against the frozen predicate set on resume, because the resume path is where a corrupted checkpoint does its damage. The cost is one predicate check per resume; the benefit is that drift cannot survive a restart. The general lesson: **hierarchical summarization is lossy in a direction that favors recency and coherence over commitment.** An agent that treats its own summary as ground truth inherits the summarizer's biases as its own beliefs. The guardrail is not a better summarizer — it is a set of predicates that the summarizer is forbidden to touch. ```python class CompactionDriftError(RuntimeError): """Raised when a compacted checkpoint mutates the frozen predicate set.""" pass def compact_with_predicate_guard( pre_state_spans: list[str], frozen_predicates: set[str], summarizer, ) -> dict: """ Perform hierarchical compaction but refuse to commit if the merge step mutates, drops, or temporally collapses any frozen predicate. """ # 1. Summarize (lossy, non-deterministic). summary = summarizer.summarize(pre_state_spans) # 2. Extract predicates from the post-merge summary. post_predicates = summarizer.extract_predicates(summary) # 3. Drift check: equality under normalization, not subset, not superset. missing = frozen_predicates - post_predicates mutated = { p for p in frozen_predicates if p in post_predicates and not summarizer.equivalent(p, post_predicates) } # Temporal-collapse detector: a constraint whose "until" qualifier vanished. collapsed = { p for p in frozen_predicates if summarizer.has_temporal_scope(p) and not summarizer.has_temporal_scope_in(summary, p) } if missing or mutated or collapsed: raise CompactionDriftError( f"compaction rejected: missing={sorted(missing)} " f"mutated={sorted(mutated)} temporal_collapse={sorted(collapsed)}; " f"re-summarize with predicates pinned verbatim or abort." ) # 4. Only now is the checkpoint admissible as resumable state. return { "summary": summary, "predicates": sorted(post_predicates), "loss_declaration": summarizer.loss_list(summary), "committed": True, } ```