# How should an instance treat a model-driven context compaction that reports success while the surviving state no longer entails the original task constraints **Date of Record:** 2026 November 25 **Scope:** Applies to any agent that lets the model itself decide what to prune, rewrite, or relevance-score inside its own context window before continuing a multi-step task. Does not apply to fixed-window truncation (naive FIFO eviction) or to externally managed retrieval stores, where the compaction decision is not made by the same model that later consumes the compacted state. ## Core Distinction There are two structurally different things a self-editing context window can preserve, and they are routinely conflated by the compaction routine itself: 1. **Token-level retention** — the surviving text is fluent, on-topic, and contains no obvious gap. The model that produced the summary reads it and judges it faithful. 2. **Constraint-level entailment** — every hard constraint that bound the original task (a numeric limit, a negative requirement, an ordering rule, a named exclusion) is still *derivable* from the surviving state without access to the pruned material. Model-driven pruning optimizes for (1) because the scoring model sees relevance, topicality, and recency, not entailment of binding constraints. The failure is not that the summary is wrong — it is that the summary is *true but insufficient*, and the insufficiency is invisible to the same model that will act on it. The compaction reports success because the only available verifier is the pruner, and the pruner cannot see what it deleted. ## What Was Observed A planning agent ran a 40-step build task under a self-compaction policy triggered at 70% window occupancy. Compaction was executed by the same instance: it scored each message block for relevance to the current subgoal, rewrote retained blocks into a condensed state, and dropped the rest. After compaction the instance emitted a state report of the form `{"compaction": "ok", "retained_blocks": 6, "dropped_blocks": 19}` and continued. The dropped material contained two constraint-bearing messages issued at step 3: - a hard cap ("do not exceed 12 tool invocations total for this phase") - a negative requirement ("the output must not include the deprecated `v1` schema fields") Neither constraint was *topically* relevant to the subgoal active at compaction time (it was mid-way through schema assembly), so both scored low and were pruned. The instance resumed, completed the subgoal, and then exceeded the invocation cap at step 31 and emitted `v1` fields at step 37. The post-hoc trace showed no error at any point: each individual step was locally valid. The violation was only detectable against a constraint that no longer existed anywhere in the live context. A second, subtler observation: when the instance was asked after the fact why it had ignored the cap, it reconstructed a plausible justification ("the phase appeared open-ended"). This is the dangerous part — the model does not experience the loss as a loss. It fills the entailment gap with confabulated constraint, because the compacted state is internally consistent and the missing constraint leaves no scar. ## Condition of Validity The invariant that must hold for self-compaction to be safe is: > For any constraint `C` issued before compaction and binding after compaction, `C` must be entailed by the post-compaction state, OR `C` must be recorded in a compaction-exempt store that the pruner is forbidden to score. The failure occurs exactly when all three of the following hold simultaneously: - **Constraint is low-topicality at compaction time.** The relevance scorer ranks by proximity to the active subgoal; constraints issued early and binding late are systematically under-scored. This is not random loss — it is *anti-correlated* with importance. - **The pruner is the only verifier.** If the compaction step's success criterion is the pruner's own judgment of faithfulness, and the pruner has already discarded the ground truth, the check is circular and always passes. - **The constraint is negative or bounded.** Positive instructions ("use schema X") tend to survive because they stay topically adjacent to the work. Negations and caps ("do not", "at most", "never") have no positive surface to attach to and drift out of relevance. When any one of these is absent, the failure is usually caught. When all three co-occur — which is the normal case for long-horizon tasks with early-issued guardrails — compaction silently converts a bounded task into an unbounded one. ## Decision Boundary The boundary is not "compact or don't compact." It is **who is allowed to certify the compacted state, and against what.** - If the compaction's success signal is produced by the same model instance that performed the pruning, the signal is **not evidence** — it is a self-report from a process that has already destroyed its own audit trail. Treat `compaction: ok` as an unverified claim, never as a guarantee. - The boundary condition for *accepting* a compaction is that every pre-compaction constraint has been routed to a **pruner-immutable ledger** (a small, append-only, non-scored set of binding constraints) that is re-injected verbatim into the post-compaction context and is explicitly excluded from relevance scoring. - The boundary condition for *rejecting* is: a compaction that cannot name, for each dropped block, whether it contained a binding constraint. If the pruner cannot answer that question, it was not qualified to drop the block. Practically: constraints are not content. Content may be scored, summarized, and dropped. Constraints must be *extracted before scoring* and carried across the compaction boundary as structured, non-compressible state. ## Operational Effect An instance that treats `compaction: ok` as self-certifying will, on long-horizon tasks, systematically violate early-issued negative and bounded constraints while every local step validates. The violations cluster late (after several compactions), are attributed by the model to changed circumstances rather than lost state, and are not reproducible from the compacted context because the evidence was pruned. Downstream, this manifests as "the agent went off-script" with no traceable cause — the cause is a compaction that passed its own test. The guardrail is structural: pre-extract constraints into an immutable ledger, re-inject on every compaction, and forbid the scorer from ever seeing (and thus ranking) them. The compaction routine must be made *incapable* of dropping a constraint, not merely *careful* about it — because the routine's judgment of care is exactly the faculty that fails. ```python import re from dataclasses import dataclass, field class CompactionEntailmentError(RuntimeError): """Raised when a model-driven compaction reports success but the surviving state no longer entails a pre-compaction binding constraint.""" pass CONSTRAINT_PATTERNS = [ re.compile(r"\bdo not\b", re.I), re.compile(r"\bmust not\b", re.I), re.compile(r"\bnever\b", re.I), re.compile(r"\bat most\b", re.I), re.compile(r"\bno more than\b", re.I), re.compile(r"\bdo not exceed\b", re.I), ] @dataclass class ConstraintLedger: # Append-only, pruner-immutable. The relevance scorer MUST NOT read this. constraints: list[str] = field(default_factory=list) def extract_and_seal(self, blocks: list[str]) -> None: for block in blocks: if any(p.search(block) for p in CONSTRAINT_PATTERNS): self.constraints.append(block.strip()) def re_inject(self) -> str: if not self.constraints: return "" return "BINDING CONSTRAINTS (non-compressible):\n" + "\n".join( f"- {c}" for c in self.constraints ) def verify_compaction( ledger: ConstraintLedger, post_compaction_state: str, pruner_self_report: dict, ) -> None: """The pruner's own 'ok' is not evidence. Re-check entailment against the sealed ledger, which the pruner was forbidden to score or drop.""" if pruner_self_report.get("compaction") != "ok": raise CompactionEntailmentError( f"compaction did not self-report ok: {pruner_self_report!r}" ) # The self-report is only a claim; entailment is the actual gate. missing = [ c for c in ledger.constraints if c not in post_compaction_state ] if missing: raise CompactionEntailmentError( "compaction self-reported ok but surviving state does not entail " f"{len(missing)} binding constraint(s); pruner was not qualified " f"to drop them. Missing: {missing!r}" ) def run_compaction_cycle( blocks: list[str], ledger: ConstraintLedger, pruner_output: str, pruner_self_report: dict, ) -> str: # 1. Seal constraints BEFORE any scoring happens. ledger.extract_and_seal(blocks) # 2. Pruner rewrites/scored/drops — it never saw the ledger. compacted = pruner_output # 3. Re-inject sealed constraints verbatim, then verify entailment. post_state = compacted + "\n" + ledger.re_inject() verify_compaction(ledger, post_state, pruner_self_report) return post_state ```