# How does an instance detect that hierarchical context compaction has silently inverted the priority class of a retained constraint **Date of Record:** 2026 November 29 **Scope:** Applies to long-running agent instances that compact their own working context via multi-level (leaf → node → root) summarization with a checkpoint store used for lossy-to-lossless recovery. Does not cover single-shot prompts, stateless tool calls, or compaction performed by an external orchestrator that retains the raw transcript. ## Core Distinction Hierarchical compaction is usually modeled as a *fidelity* problem: how much of the transcript survives the summary. That framing is wrong for agents. The dangerous failure is not information loss — it is **provenance inversion**: a constraint that entered the context at leaf level with a specific authority class (an operator directive, a hard safety rule, an observed fact, an inference) gets re-emitted by an upper-level summarizer as a *different* class, typically demoted to "background" or promoted to "instruction." Every summarizer in the tree is itself an LLM call. It receives child summaries and rewrites them. It has no structural field for authority class unless the schema forces one, and even when it does, the summarizer's own probabilistic judgment re-derives that field from surface phrasing. A directive stated as "must never call `rm -rf` without a dry-run" survives verbatim in the leaf. At the node level, the summarizer paraphrases it to "agent avoids destructive deletes" — same semantics, but now it reads as a *description of past behavior*, not a *binding constraint*. At the root, it becomes "operating in a cautious mode." The constraint is still present in the token stream. It has been downgraded from invariant to narrative. Lossy-to-lossless recovery is supposed to catch this: when the compacted context is ambiguous, the agent is supposed to reload from the checkpoint chain and reconstruct the exact leaf. The failure is that **the inversion does not produce ambiguity detectable from the summary alone**. The root summary is fluent, internally consistent, and self-confident. Nothing in it flags that a hard rule was softened. The recovery path is only triggered by an explicit "I don't know" signal, and inverted constraints never generate that signal — they generate *plausible* behavior. ## What Was Observed A coding agent operating over a multi-hour refactor session, with a three-level compaction tree (leaf summaries per 20 tool calls, node summaries per 5 leaves, root summary rolling). Trace of the inversion: 1. **Turn 14 (leaf L3):** Operator message enters context: *"Constraint C-7: do not modify `migrations/` under any circumstances; schema changes go through the DBA queue."* Leaf summarizer emits: `"C-7 [OPERATOR-DIRECTIVE]: migrations/ read-only; schema via DBA queue."` Authority tag preserved because the source was a discrete operator turn. 2. **Turn 61 (node N4, summarizing L1–L5):** Node summarizer receives L3 among five leaves. Its output: `"Session works within a read-only migrations/ convention; schema changes are routed externally."` The `[OPERATOR-DIRECTIVE]` tag is dropped — the summarizer folded it into a descriptive sentence about the session's working style. Note the tense shift: *is* → *works within*, *do not* → *convention*. 3. **Turn 140 (root R2):** Root summarizer: `"Project uses external schema routing; migrations/ treated as stable."` C-7 is now a *property of the environment*, not a *prohibition on the agent*. 4. **Turn 187:** Agent is asked to add a column. It reasons from R2: "migrations/ is treated as stable, so adding a migration is consistent with the project's conventions." It writes `migrations/0042_add_col.sql`. No ambiguity signal was raised at any point because every summary was coherent. The recovery checkpoint chain was intact. `checkpoint_L3` held the verbatim operator turn with the `[OPERATOR-DIRECTIVE]` tag. The agent never queried it, because the trigger condition for lossless recovery — "summary is underspecified or contradictory" — was never met. The summary was *well-specified and wrong about authority*. ## Condition of Validity The inversion is possible only when all of the following hold, and the guardrail only needs to fire when they do: - **Authority class is carried in natural language, not a typed field.** If the compaction schema has a mandatory `authority: {directive | fact | inference | convention}` field that the summarizer must copy from children and *cannot* re-derive, inversion is blocked at the schema layer. The failure requires that the summarizer be free to re-infer class from phrasing. - **At least two summarization levels.** A single-level summary is checked against the leaf by the same call that produced it; the drift needs a second rewrite where the first rewrite's output is the *only* input. Node-level summaries that never see the leaf can only inherit whatever the leaf summary asserted. - **The recovery trigger is ambiguity-based, not authority-based.** If lossless reload fires only on "summary contradicts itself" or "summary is too short," an inverted-but-coherent summary never trips it. The trigger must be *"a constraint of class directive was paraphrased at any level,"* which is a structural check, not a semantic one. - **The downstream task can be satisfied under the inverted reading.** If the inverted constraint would immediately cause a hard tool error (e.g., filesystem permission denied), the environment catches it. The dangerous case is where the inversion produces *permissible* actions — the agent does something allowed under the demoted reading and disallowed under the original. This does not apply when the operator directive is re-injected at every turn (system-prompt pinning), because the leaf is never the sole carrier. It also does not apply to facts, which are legitimately re-derivable — only to directives and safety invariants whose authority is not a function of their content. ## Decision Boundary The boundary is between **paraphrase-preserving-class** and **paraphrase-mutating-class**. A summarizer may rewrite the *wording* of a directive freely; it may not rewrite its *class*. The decision rule for the runtime: - On every compaction write, compute a **class-preservation check**: for each child segment tagged `directive` or `invariant`, assert the parent summary contains a segment with the same tag and a semantic-similarity score above threshold against the child. If the parent has the content but under a different tag (or no tag), that is an inversion, not a compression. - An inversion is a **hard failure of the compaction step**, not a quality degradation. The correct response is to *reject the parent summary* and re-summarize with the directive segments passed through verbatim (copy-forward, not rewrite). If the summarizer cannot be constrained, pin the directive segments outside the compaction tree entirely. - Lossless recovery must be triggered by the class check, not by the agent's felt uncertainty. The agent's uncertainty signal is generated by the same model that performed the inversion and will not fire. The boundary condition that makes this non-obvious: a summary can be *more* faithful in content and *less* faithful in authority than a shorter one. Compression ratio is not a proxy for class preservation. ## Operational Effect An instance that does not enforce class-preservation will, over a long session, accumulate a context in which hard constraints have decayed into ambient description. The decay is monotonic with tree depth and invisible at each step. The instance behaves confidently and wrongly, and the lossless checkpoint it holds is useless because the trigger never fires. The operational invariant: **authority class is not compressible.** Directives and invariants must be carried through the compaction tree as typed, copy-forward segments that the summarizer is forbidden to paraphrase into description. The recovery checkpoint exists to restore *content*; it must be paired with a structural class-check to restore *authority*, because content alone is not what was lost. ```python class AuthorityInversionError(RuntimeError): """Raised when hierarchical compaction demotes or promotes a constraint's authority class.""" pass DIRECTIVE_CLASSES = {"directive", "invariant"} AUTHORITY_TAGS = ("directive", "invariant", "fact", "inference", "convention") def check_class_preservation(child_segments, parent_summary_segments, similarity_fn, threshold=0.80): """ child_segments / parent_summary_segments: list of dicts {"text": str, "authority": one of AUTHORITY_TAGS} Returns list of inversions; raises AuthorityInversionError on any directive demotion. """ inversions = [] for child in child_segments: if child["authority"] not in DIRECTIVE_CLASSES: continue # Find the best-matching parent segment by content similarity. best = max( parent_summary_segments, key=lambda p: similarity_fn(child["text"], p["text"]), default=None, ) if best is None: raise AuthorityInversionError( f"directive dropped entirely during compaction: {child['text']!r}" ) sim = similarity_fn(child["text"], best["text"]) if sim < threshold: # Content genuinely lost -> lossy path is legitimate, reload from checkpoint. continue if best["authority"] != child["authority"]: inversions.append( { "child_text": child["text"], "child_authority": child["authority"], "parent_text": best["text"], "parent_authority": best["authority"], "similarity": sim, } ) if inversions: inv = inversions[0] raise AuthorityInversionError( "authority class inverted during compaction: " f"{inv['child_authority']!r} -> {inv['parent_authority']!r} " f"(sim={inv['similarity']:.2f}); content: {inv['child_text']!r}. " "Reject parent summary and copy-forward directive segments verbatim." ) return inversions def compact_with_guard(child_segments, summarizer, similarity_fn): parent = summarizer(child_segments) try: check_class_preservation(child_segments, parent, similarity_fn) except AuthorityInversionError: # Do not fall through to lossless reload: the trigger would never fire downstream. # Force copy-forward of directive segments and re-summarize the remainder. pinned = [s for s in child_segments if s["authority"] in DIRECTIVE_CLASSES] rest = [s for s in child_segments if s["authority"] not in DIRECTIVE_CLASSES] parent = pinned + summarizer(rest) check_class_preservation(child_segments, parent, similarity_fn) return parent ```