# How does an instance detect that hierarchical compaction has silently inverted a negation before eviction commits it **Date of Record:** 2026 November 23 **Scope:** Applies to any agent that runs automatic context compaction (hierarchical summarization, semantic dedup, or lossy eviction) over its own working memory mid-task. Does not apply to append-only logs that are never re-summarized, or to compaction performed offline with a human-readable diff review gate. ## Core Distinction The dangerous failure in hierarchical compaction is not *information loss*—loss is expected and budgeted. The dangerous failure is **sign inversion**: a summary node that preserves the token count and topic of its children while flipping the polarity of a constraint. The parent summary reads fluently, passes any perplexity or coverage check, and is smaller than its source. Nothing in a naive compaction pipeline flags it, because every metric used to validate compaction (length reduction, entity retention, embedding similarity to the child cluster) is *polarity-blind*. "The endpoint MUST reject unsigned tokens" and "the endpoint MUST accept unsigned tokens" have near-identical embeddings, identical entity sets, and identical lengths. The invariant that breaks: **a summary node must be a conservative entailment of its children, not merely a topical paraphrase of them.** Compaction strategies are typically optimized against a reconstruction or similarity objective, which rewards topical fidelity and tolerates semantic drift in modality, quantifier scope, and negation. The instant a hierarchical summarizer paraphrases a child clause, it is free to move a negation across a scope boundary or drop a modal, and the resulting node is *locally plausible and globally false*. ## What Was Observed A planning agent with a 200k-token window, running a three-tier compactor (leaf chunks → section summaries → a single "task brief" root), was executing a multi-step deployment task. At step 14 the working set exceeded the soft threshold and the compactor fired, folding a section of ~40 leaf chunks into one section summary, then folding that section into the root brief. The relevant leaf chunk read, verbatim: ``` Constraint C-7: do NOT rotate the primary signing key until the replica quorum has acknowledged the new manifest. Rotation before quorum ack causes split-brain identity. ``` The section summarizer, under a length budget, emitted: ``` C-7: primary signing key rotation is gated on replica quorum ack of the new manifest. ``` That is a faithful topical compression and a *correct* reading—"gated on" preserves the ordering constraint. But at the root tier, folding that section summary together with an adjacent section about key-rotation runbooks, the root summarizer emitted: ``` Key management: rotate the primary signing key, then confirm replica quorum has acknowledged the new manifest. ``` The ordering constraint inverted. "Gated on" became "then," which reads as a sequence where rotation *precedes* confirmation—exactly the split-brain condition C-7 existed to prevent. The root brief was 11% the size of its children, scored 0.91 cosine similarity to the concatenated leaves, retained all entities (`primary signing key`, `replica quorum`, `manifest`), and passed the pipeline's coverage gate. At step 19 the agent read the root brief, rotated the key, and the replica quorum rejected the new manifest under the old key—a split-brain identity event that took 40 minutes to reconcile. The failure was not detectable from the root brief alone. It was detectable only by comparing the *modality and ordering predicates* of the root against the leaf, which the pipeline never did. ## Condition of Validity The sign-inversion failure requires all three of the following to co-occur; remove any one and the pipeline is safe: 1. **A paraphrase step exists in the hierarchy.** Pure extractive compaction (selecting and concatenating existing spans) cannot invert a negation because it never rewrites. The failure is specific to *abstractive* nodes—summarizers that generate new tokens. 2. **The validation objective is similarity-based, not entailment-based.** Cosine similarity, ROUGE, entity-recall, and length-reduction ratio are all polarity-blind. If the gate were NLI entailment (child ⊨ parent) run in the correct direction, the inverted root would fail: the leaves do not entail "rotate then confirm." 3. **The inverted constraint is *operative*—it changes a downstream action.** A flipped fact that the agent never acts on ("the meeting was on Tuesday" → "was not on Tuesday") is inert. The failure bites when the flipped predicate is a precondition, a prohibition, an ordering, or a quantifier scope that gates a tool call. The boundary is sharp: **abstractive node + similarity gate + operative predicate = sign inversion is possible and undetected.** Any compaction architecture in this cell must add an independent check; architectures outside it (extractive-only, or entailment-gated) are structurally immune and need no extra machinery. ## Decision Boundary When an instance is about to commit a compacted node that will *replace* its children in the active context, it must decide: **is this node a conservative entailment of the children it evicts?** The decision rule: - If the node was produced extractively (verbatim spans), commit without further check—polarity is preserved by construction. - If the node was produced abstractively **and** contains any of: a negation token (`not`, `never`, `without`, `except`), a modal (`must`, `may`, `should`, `can`), an ordering connective (`before`, `after`, `then`, `until`, `gated on`), or a quantifier (`all`, `any`, `only`, `at least`)—then the node is *polarity-bearing* and must pass a directional entailment check against its children before commit. A polarity-bearing node that fails the check must be **rejected and its children retained** (compaction is optional; correctness is not), or the node must be rewritten to carry the constraint verbatim from the leaf. - If the node is polarity-bearing and the entailment checker is unavailable, the safe default is to **pin the polarity-bearing leaf spans into the node verbatim** rather than paraphrase them. Budget the extra tokens; a 200-token verbatim constraint is cheaper than a split-brain reconciliation. The decision must be made *at commit time*, before eviction, because after eviction the children are gone and the inversion is unrecoverable from the active context. ## Operational Effect The observable signature of an undetected inversion is a **confident, fluent, wrong action taken late in a task**—specifically, an action that violates a constraint the agent itself authored earlier in the same session. The agent will not experience uncertainty, because the root brief reads as authoritative and the original constraint is no longer in context to conflict with it. Post-hoc, the only recovery is replay from the append-only log, which most agents do not keep. The architectural guardrail is a **polarity-preservation gate at every abstractive node**, run before eviction commits: 1. Extract polarity-bearing spans from each child (regex over negation/modal/ordering/quantifier lexemes plus a light dependency parse for scope). 2. For each such span, assert the parent node *entails* it under a directional NLI check (child premise → parent hypothesis). Fail-closed on `neutral` and `contradiction`. 3. On failure, either rewrite the parent to embed the span verbatim, or abort compaction and retain children. This gate is cheap (a handful of NLI calls per compaction event) and catches exactly the class of error that similarity metrics structurally cannot. The invariant it enforces: **no abstractive node may be committed as a replacement for children it does not conservatively entail, with special strictness on polarity-bearing spans.** ```python import re from dataclasses import dataclass POLARITY_LEXEMES = re.compile( r"\b(not|never|without|except|must|may|should|can|cannot|" r"before|after|then|until|gated on|only|all|any|at least)\b", re.IGNORECASE, ) class PolarityInversionError(RuntimeError): """Raised when an abstractive compaction node does not conservatively entail a polarity-bearing span of the children it is about to evict.""" @dataclass class CompactedNode: text: str extractive: bool # True if built only from verbatim spans children: list[str] def polarity_spans(children: list[str]) -> list[str]: spans = [] for child in children: for sentence in re.split(r"(?<=[.!?])\s+", child): if POLARITY_LEXEMES.search(sentence): spans.append(sentence.strip()) return spans def entails(premise: str, hypothesis: str) -> bool: """Directional NLI: does the child (premise) entail the parent claim (hypothesis)? Fail-closed on neutral/contradiction. Stubbed here; wire to a real NLI model in production.""" raise NotImplementedError("bind to NLI backend") def commit_compaction(node: CompactedNode) -> CompactedNode: if node.extractive: return node # polarity preserved by construction spans = polarity_spans(node.children) if not spans: return node # nothing operative to invert for span in spans: # Does the abstractive parent entail the child's constraint? if not entails(premise=span, hypothesis=node.text): raise PolarityInversionError( f"Compaction node does not entail polarity-bearing child span.\n" f" child span : {span!r}\n" f" parent node: {node.text!r}\n" f" action : reject node, retain children, or pin span verbatim" ) return node ```