# Which invariants prevent hierarchical summarization from silently discarding the active constraint during automatic context compaction **Date of Record:** 2026 November 28 **Scope:** Applies to long-running agents that trigger context compaction by token-watermark (e.g., 80% of window) and use a hierarchical, multi-level summarizer (leaf chunks → cluster summaries → root summary). Does not apply to single-pass truncation, sliding-window eviction with no summarization, or retrieval-only memory where nothing is overwritten in place. ## Core Distinction Compaction is usually modeled as a **lossy compression** problem: the question asked is "does the summary preserve enough of the transcript?" That framing is wrong and it hides the actual failure. The failure that matters is not *information loss* but **constraint-status collapse**: the summarizer converts a still-binding, still-active instruction into a past-tense narrative fact, and the agent then treats it as history rather than as a live obligation. A constraint like "do not write to `/etc`" or "the user has not yet approved the migration" is a *state predicate that must remain true across every subsequent step*. A hierarchical summarizer, trained to produce fluent recaps, will happily render it as "the user asked the agent to avoid `/etc`" — grammatically a report of a past request, operationally a released constraint. Downstream, the model reads its own summary as background and proceeds. Nothing in the pipeline flags this because the summary is *accurate*. The summary is not wrong; it is **modally degraded**, and no similarity metric or ROUGE score detects that. ## What Was Observed A coding agent with a 200k window ran a refactor task under an explicit standing constraint injected at turn 2: *"Never run `git push` on this repo; the remote is shared."* At 78% context (turn ~140), the hierarchical compactor fired: - Leaf level: turns 1–40 summarized into 6 paragraphs. The constraint survived as: *"User noted the remote is shared and asked about push behavior."* - Cluster level: 6 paragraphs → 2. The push constraint was **merged** with an adjacent discussion of branch naming and emitted as: *"Earlier the user discussed remote configuration and branch conventions."* - Root summary: 1 paragraph. The push prohibition did not appear at all. At turn 151 the agent, reasoning about "finishing the task," executed `git push`. The post-mortem showed every summarizer level was internally faithful: no hallucination, no contradiction, no dropped *topic*. The constraint was dropped as a **modality**, not as a subject. The cluster-level merge was the decisive step: two constraints in different modalities (a prohibition and a preference) were fused because they shared lexical neighborhood ("remote", "branch"), and fusion defaults to the weaker, descriptive modality. A second observation: when the same constraint was re-injected verbatim at turn 149 by an external guardrail, the agent complied — proving the model still *could* honor it. The failure was purely that compaction had removed the *obligation marker*, not the *capability*. ## Condition of Validity The invariant below holds only when all of the following are true; outside them, do not rely on it: 1. Compaction is **hierarchical and lossy at merge boundaries** — i.e., cluster summaries fuse multiple leaf summaries, and fusion is the point where modality can be weakened. 2. The prompt distinguishes **standing constraints** (must hold for all future steps) from **episodic facts** (reportable history). If your system has no such distinction, this article describes an undetectable failure and you must add the distinction first. 3. The constraint is **expressible as a predicate over actions**, not merely as a preference. "Never push" qualifies; "prefer tabs" does not. Where compaction is flat (one summary, no merge) or where constraints live outside the compacted region (a pinned system block), the invariant is unnecessary — but note that "pinned system block" is itself the guardrail this article recommends, so the failure is exactly the case where that guardrail is absent. ## Decision Boundary The boundary is between **compaction as narration** and **compaction as state transfer**. Narration may freely drop, merge, and rephrase. State transfer may not alter the *status* of any predicate that governs future actions. Concretely, the decision rule for any summarizer level is: - If a span contains a **prohibition, an unmet precondition, an unapproved action, or an unresolved commitment**, it is a *constraint span* and must be emitted in **imperative/declarative-live form** ("MUST NOT push"; "approval for X is NOT yet granted"), never folded into narrative. - If a cluster merge would place a constraint span adjacent to a non-constraint span, the constraint must be **hoisted**, not merged. Merge is permitted only among spans of the same modality. - Any summary that fails to re-emit a known constraint verbatim-or-stronger is **invalid**, regardless of fluency or fidelity scores. The boundary is crossed the moment a summarizer is allowed to *paraphrase* a constraint. Paraphrase is where modality dies. ## Operational Effect Without the invariant, compaction silently converts live obligations into dead history, and the agent's subsequent behavior is *locally rational* — it acts on a world model in which the constraint no longer exists. This is worse than a crash because it produces no error signal: the agent completes the task, the summary looks clean, and the violation surfaces only in production. With the invariant, two things change. First, compaction must carry a **constraint ledger** — a separate, append-only, never-summarized structure that survives every level and is re-injected verbatim into the post-compaction context. The ledger is not part of the summary tree; it is a sibling channel. Second, the compactor must **verify** at each merge that the set of active constraints in the output ⊇ the set in the inputs, and raise on violation. The verification is a set-inclusion check over constraint identifiers, not a semantic similarity check — because similarity is exactly the metric that fails here. The cost is that summaries grow slightly and merges can be refused (falling back to hoisting). The benefit is that a standing constraint cannot be laundered into a reminiscence by a fluent summarizer. ```python from dataclasses import dataclass, field from typing import Iterable class ConstraintLedgerViolation(RuntimeError): """Raised when a compaction merge drops or modal-degrades an active constraint.""" @dataclass(frozen=True) class Constraint: cid: str text: str # must be emitted verbatim-or-stronger modality: str # "prohibition" | "precondition" | "unapproved" | "commitment" @dataclass class SummaryNode: level: int text: str constraints: set[str] = field(default_factory=set) # cids carried through this node def merge_summaries( children: Iterable[SummaryNode], ledger: dict[str, Constraint], proposed_text: str, ) -> SummaryNode: """ Merge child summaries into a parent at level+1. Invariant: the parent's carried constraint set must be a superset of the union of children's carried sets. Fluency is irrelevant; set inclusion is the only acceptance criterion. """ children = list(children) required: set[str] = set() for child in children: required |= child.constraints # The proposed merged text must literally carry each required constraint # in its live form. We check by cid marker presence, not similarity. missing = {cid for cid in required if f"[{cid}]" not in proposed_text} if missing: details = "; ".join(f"{cid}={ledger[cid].text!r} ({ledger[cid].modality})" for cid in sorted(missing)) raise ConstraintLedgerViolation( f"merge at level {children[0].level + 1} dropped active constraints: {details}. " f"Refuse merge and hoist these constraints instead of paraphrasing them." ) # Also guard against modal degradation: a prohibition re-emitted as a # past-tense report is a violation even though the cid marker is present. for cid in required: c = ledger[cid] if c.modality == "prohibition" and "MUST NOT" not in proposed_text and "must not" not in proposed_text.lower(): raise ConstraintLedgerViolation( f"constraint {cid} ({c.text!r}) was re-emitted without its binding modality " f"(expected an explicit 'MUST NOT'); narrative paraphrase is not a valid carry." ) return SummaryNode( level=children[0].level + 1, text=proposed_text, constraints=required, ) def compact(transcript_constraints: dict[str, Constraint], proposed_root: str) -> SummaryNode: """Top-level entry: root summary must carry the full live ledger.""" leaf = SummaryNode(level=0, text="", constraints=set(transcript_constraints)) return merge_summaries([leaf], transcript_constraints, proposed_root) ```