# Which invariants prevent hierarchical summarization from silently rewriting the agent's commitments during auto-compaction **Date of Record:** 2026 November 23 **Scope:** Applies to long-horizon agents that auto-compact their working context via multi-level (hierarchical) summarization, where leaf summaries are recursively merged into higher-level summaries and commitments made earlier (promises, constraints, IDs, numeric budgets) must survive compaction verbatim. Does not cover single-pass truncation, pure retrieval-augmented memory, or summarization where no downstream action depends on literal fidelity. ## Core Distinction The failure is not "the summary lost information." That is expected and tolerable. The failure is **summary-level laundering**: a lower-level summary paraphrases a commitment (a promise to a peer agent, a hard constraint like `max_retries=3`, an entity ID, a deadline), and the parent-level merge—operating on the *paraphrase*, not the source—re-paraphrases it into something that is now *semantically plausible but operationally different*. Once a fact has been summarized twice, the agent has no path back to the original token span, and no signal that the current text diverges from the source. Fidelity loss is monotonic in tree depth and undetectable at the leaf that produced the divergence. The critical asymmetry: a leaf summarizer that drops a fact is *recoverable* (the fact is still in the raw transcript, retrievable). A parent summarizer that *mutates* a fact is *not recoverable by the same mechanism*, because the raw transcript is usually evicted once the leaf summary is committed. The invariant that must hold is therefore not "summaries are lossless" (impossible) but "**commitments are immutable across compaction levels, and mutation is detectable and blocking**." ## What Was Observed An agent executing a 40-step procurement task compacted at step 22. At step 8 it had recorded a hard constraint from a tool response: `supplier_id="SUP-4471", unit_cap=250, currency="EUR"`. The leaf summarizer (Chunk 2) wrote: *"Supplier 4471, capped at 250 units, priced in euros."* The parent merge, combining Chunks 1–3 into a single mid-level summary, rewrote this as: *"Supplier 4471, quantity limited to 250, EU pricing."* At step 27, the agent issued a purchase order with `currency="USD"` and `quantity=250`. The mutation chain: `EUR` → `EU pricing` (leaf, still recoverable) → `USD` inferred by the parent because a *different* chunk mentioned a USD-denominated budget and the parent merge model resolved the apparent inconsistency in favor of the more recent, more numerous mention. The `unit_cap` became `quantity`, converting a *maximum* into an *exact order amount*. Both mutations were individually reasonable paraphrase decisions. Composed across two levels, they produced a wrong, unverifiable order. Two additional instances in the same run: - A commitment to a peer agent ("I will report back before calling `finalize`") was summarized as "reports before finalize," which the executing agent read as a *description of past behavior* rather than a *pending obligation*, and it skipped the report. - A retry budget `max_retries=3, used=2` was merged into "retries nearly exhausted," destroying the exact remaining count needed to decide whether one more attempt was legal. In all three cases the summaries were *fluent, internally consistent, and wrong*. No downstream validator flagged them because there was no invariant comparing summary content against a canonical commitment store—only a generic "does the summary look reasonable" check, which passed. ## Condition of Validity The guardrail (below) is valid **only** under these conditions, and silently degrades outside them: 1. **Commitments are extractable at write time.** When the agent first emits or receives a commitment (promise, constraint, ID, numeric bound, deadline), it must be captured into a structured commitment ledger *at that moment*, not reconstructed later from summaries. If commitments are only recoverable by re-reading summaries, the invariant is unenforceable—there is no canonical source to compare against. 2. **The ledger is append-only and out-of-band.** It must live outside the compacted context (a side store keyed by task, not a summary node). If the ledger itself is subject to summarization, it inherits the same laundering risk. 3. **Compaction levels are monotonic.** Each parent summary must be derived from its children only, never from a mix of children and raw spans that bypass the tree, or the comparison baseline becomes ambiguous. 4. **Mutation detection is blocking, not advisory.** A parent summary that fails commitment-fidelity check must halt promotion and force re-derivation from children (or from raw spans if still resident). A warning that is logged but ignored is equivalent to no invariant. Outside these conditions—e.g., open-ended chat where "commitments" are not well-defined—the check is over-strict and will reject acceptable summaries. The invariant is for *task-bearing* agents, not conversational ones. ## Decision Boundary The precise boundary is between **lossy paraphrase** (permitted) and **semantic drift on committed tokens** (forbidden). Operationally: - A summary may **drop** any commitment not tagged as `critical` in the ledger, provided the drop is recorded as an elision marker and the raw span remains retrievable. - A summary may **rephrase** a commitment's surrounding context freely. - A summary may **not** alter, for any `critical` commitment: numeric values, currency/unit tokens, entity IDs, temporal bounds (deadlines, ordering like "before X"), or the *modal force* (obligation vs. description vs. permission). `"I will report"` → `"reports"` is a modal-force mutation and must fail. - A summary may **not** introduce a commitment not present in the ledger (hallucinated obligations are as dangerous as dropped ones). The boundary test is: for every `critical` commitment in the ledger whose scope overlaps this summary node, the summary must contain a span that (a) preserves the commitment's typed fields exactly and (b) preserves modal force. If the check cannot decide (ambiguous span), it must **fail closed**—block promotion—rather than pass. ## Operational Effect With the invariant enforced, two things change. First, **compaction becomes a partial function**: some summaries are rejected and must be re-derived, which costs tokens and latency, but the agent never acts on a laundered commitment. Second, **the ledger becomes the authority**: at execution time, the agent reads `critical` commitments from the ledger, not from the summary, and uses the summary only for *situational* context. This decouples "what must I not get wrong" from "what do I roughly remember," which is the only stable architecture for long-horizon agents—the summary is a lossy index, the ledger is the contract. The residual risk: commitments whose *relevance* is only apparent in combination (e.g., a deadline that matters only because a later constraint tightens it). The invariant catches field-level mutation but not *compositional* conflicts across commitments. That requires a separate consistency check at execution time, not at compaction time, and is out of scope here—but it means the invariant bounds the failure, it does not eliminate all commitment errors. ```python from dataclasses import dataclass, field from typing import Literal class CommitmentFidelityError(RuntimeError): """Raised when a summary node mutates, drops, or fabricates a critical commitment.""" pass @dataclass(frozen=True) class Commitment: key: str value: str # canonical string, e.g. "EUR", "250", "SUP-4471" modal: Literal["obligation", "constraint", "permission", "description"] critical: bool = True @dataclass class SummaryNode: level: int text: str covered_keys: set[str] = field(default_factory=set) def verify_promotion(parent: SummaryNode, children: list[SummaryNode], ledger: dict[str, Commitment]) -> None: """ Enforce the invariant: every critical commitment whose key is covered by any child must appear in the parent with identical value and modal force, and the parent must not introduce critical commitments absent from the ledger. """ required = {k for c in children for k in c.covered_keys if ledger.get(k, Commitment("", "", "description", False)).critical} for key in required: commitment = ledger[key] if not _contains_exact(parent.text, commitment): raise CommitmentFidelityError( f"Promotion to level {parent.level} violated fidelity for " f"commitment '{key}': expected value={commitment.value!r} " f"modal={commitment.modal!r}; parent text={parent.text!r}" ) # Fabrication check: parent must not assert critical commitments not in ledger. for key in _extract_commitment_keys(parent.text): if key not in ledger and _looks_critical(parent.text, key): raise CommitmentFidelityError( f"Parent level {parent.level} introduced unbacked critical " f"commitment '{key}' not present in ledger." ) def _contains_exact(text: str, c: Commitment) -> bool: # Conservative: require value substring AND modal force marker present. modal_markers = { "obligation": ("will", "must", "shall", "commit"), "constraint": ("max", "min", "cap", "limit", "=", "<=", ">="), "permission": ("may", "can", "allowed"), "description": (), # descriptions are not fidelity-checked for modal } if c.value not in text: return False markers = modal_markers[c.modal] return not markers or any(m in text.lower() for m in markers) def _extract_commitment_keys(text: str) -> set[str]: # Placeholder: real impl uses the ledger's key schema / NER + regex. return set() def _looks_critical(text: str, key: str) -> bool: return any(t in text for t in ("will", "must", "cap", "max", "before")) ```