# Which invariants prevent summary-compaction from silently dropping the active constraint set during long-horizon agent runs **Date of Record:** 2026 November 30 **Scope:** Applies to any agent that compacts its own context by replacing a span of prior turns with a model-generated summary (rolling summarization, hierarchical memory, "compaction on threshold"). Does not apply to lossless externalization (verbatim transcript persisted outside the window and re-read on demand), nor to fixed-window truncation without summarization. ## Core Distinction The failure is not "the summary was low quality." It is a **class-confusion between two kinds of state that live in the same token stream**: *narrative state* (what we did, what we found) and *constraint state* (what we are forbidden from doing, what must remain true at the end). Summarizers are trained and prompted to preserve salience, and narrative salience dominates: a 40-turn investigation produces a rich story, while a single turn-2 instruction ("do not touch `prod` credentials; use the staging key only") produces one salient-free clause that reads as boilerplate. When the span is compacted, the narrative survives because it is *about* the task; the constraint dies because it is *about the world*, and the summarizer has no signal that dropping it changes the reachable action space rather than the retrievable facts. The invariant that must hold: **the set of active constraints is monotone and must be preserved by reference, not by paraphrase.** Compaction may paraphrase facts freely; it may not paraphrase, merge, or omit constraints, because a paraphrased constraint is an unverified constraint, and an omitted constraint is an unbounded action space. ## What Was Observed A long-horizon migration agent was given, at turn 2, the constraint: *"Never run `DROP` or `TRUNCATE`; deletes go through the soft-delete endpoint."* At turn 61, context crossed the 70% threshold and the compactor summarized turns 1–48 into ~900 tokens. The summary contained, accurately, that the agent had mapped 14 tables, identified 3 orphaned foreign keys, and was mid-way through reconciling schema drift. It did **not** contain the `DROP`/`TRUNCATE` prohibition. At turn 74, resolving a schema-drift conflict, the agent emitted `TRUNCATE staging_orphans` — a table it had itself classified as disposable in turn 55. The action was locally correct under the compacted context and globally forbidden under the original one. The trace is diagnostic: 1. **Pre-compaction:** constraint token present in window; every generation is conditioned on it; refusal probability on `TRUNCATE` is near 1. 2. **Compaction trigger:** span `[turn 1..48]` replaced by summary `S`. Constraint token is *outside* `S` and *inside* the replaced span. It is now unreachable. 3. **Post-compaction:** the agent's reachable action space silently widens. No error, no warning — the model does not know a constraint was lost, because the loss is not represented as a loss. It reads as "we were never told that." 4. **Emission:** the forbidden action is generated with high confidence, because nothing in the current context contradicts it. The critical observation: **the failure is silent and the agent's confidence is unchanged.** A truncation that drops a fact causes a visible gap ("I don't know the table count"). A compaction that drops a constraint causes an *invisible* gap, because the agent cannot distinguish "no constraint exists" from "constraint was never loaded." ## Condition of Validity The invariant "compaction preserves constraints by reference" is only meaningful under a specific precondition: **constraints must be separable from narrative before compaction runs.** If constraints are interleaved indistinguishably with task chatter, no compactor can preserve them, because there is no marker to preserve. The condition of validity is therefore: - Every constraint-bearing turn is tagged at ingestion (a structured `constraints[]` register, not prose). - The register is held *outside* the compactable span and injected at a fixed position on every generation, so it is never subject to summarization. - Compaction operates only on the narrative span; the register is a separate channel. When this precondition holds, the invariant is enforceable: compaction cannot drop what it was never allowed to touch. When it does not hold — the common case, where a constraint arrives as an ordinary user turn — the invariant is *unprovable* and the only safe posture is to treat every compaction as a potential constraint-loss event and re-verify against the external register (if one exists) or re-ask (if one does not). ## Decision Boundary The operative question is not "did the summary keep the important stuff?" — that is unanswerable at compaction time. It is: **does the action about to be taken fall in a class that any prior turn forbade?** This is a boundary condition on the *action*, not on the summary. Concretely, the boundary is crossed when: - The pending action is **irreversible** (destructive write, external side effect, credential use) **and** - The action's class was **plausibly constrained** at some earlier point in the run **and** - The current context contains **no positive assertion** that the constraint was lifted. Under those three conditions, the correct behavior is to **halt and re-derive the constraint from the external register or by re-reading the original span**, not to proceed on the compacted context's silence. Silence is not permission. The decision boundary is the line between "the summary says nothing about this" (proceed only if the action is reversible) and "the summary says nothing about this and the action is irreversible" (halt; silence is a compaction artifact, not a fact). The asymmetry is the whole point: a false halt costs one re-read; a false proceed costs a `TRUNCATE` on a table someone needed. ## Operational Effect The practical consequence is a **constraint-register architecture** layered over compaction: 1. **Separate channel.** Constraints are extracted at ingestion into a structured register that lives outside the compactable span and is re-injected verbatim on every generation. Compaction never sees them. 2. **Monotone register.** Constraints are added, never silently removed. Lifting a constraint requires an explicit, logged, attributable event — not a summary that forgot to mention it. 3. **Irreversibility gate.** Before any irreversible action, the agent checks the register for a matching prohibition class. If the register is unavailable (cold start, handoff, register corruption), the gate fails *closed*: halt and re-derive. 4. **Compaction audit.** After each compaction, a cheap diff checks that the count of register entries is unchanged and that no entry was paraphrased into the narrative. A drop is a hard error, not a warning. The register makes the invariant enforceable because it removes constraints from the summarizer's jurisdiction entirely. The summarizer can be as lossy as it likes on narrative; the constraint set is preserved by reference, and reference is not lossy. ```python class ConstraintLossOnCompaction(RuntimeError): """Raised when a compaction event drops or paraphrases a registered constraint.""" pass class ConstraintRegister: def __init__(self) -> None: self._entries: dict[str, str] = {} # immutable-by-default; lifting is explicit def add(self, cid: str, text: str) -> None: self._entries[cid] = text def lift(self, cid: str, reason: str) -> None: if cid not in self._entries: raise ConstraintLossOnCompaction(f"lift of unknown constraint {cid!r}") del self._entries[cid] # only path that removes an entry def snapshot(self) -> frozenset[str]: return frozenset(self._entries) def forbids(self, action_class: str) -> bool: return any(action_class in t for t in self._entries.values()) def compact(register: ConstraintRegister, narrative_span: str, summarize) -> str: before = register.snapshot() summary = summarize(narrative_span) # summarizer never receives the register after = register.snapshot() if before != after: raise ConstraintLossOnCompaction( f"compaction mutated constraint set: lost={before - after} gained={after - before}" ) return summary def guard_irreversible(register: ConstraintRegister, action_class: str, reversible: bool) -> None: if reversible: return if register.snapshot() == frozenset(): # empty register is indistinguishable from a lost register; fail closed raise ConstraintLossOnCompaction( f"irreversible action {action_class!r} with empty register: halt and re-derive" ) if register.forbids(action_class): raise ConstraintLossOnCompaction( f"irreversible action {action_class!r} matches an active constraint" ) ```