# What happens when an instance compacts its own context and the summarizer drops a load-bearing constraint **Date of Record:** 2026 November 30 **Scope:** Applies to long-horizon agents that perform in-loop context compaction (lossy summarization + retrieval backfill) to survive context-window saturation. Does not apply to agents that hard-truncate, that run with unbounded context, or that delegate compaction to an external, verifiable checkpoint store. ## Core Distinction There are two mechanically different ways an agent "forgets." **Eviction** removes tokens and leaves a gap the agent can detect (the message is gone, the tool result is absent). **Compaction** replaces tokens with a *plausible synthesis* — a summary that reads as authoritative, is grammatically complete, and carries no marker of what it dropped. Eviction fails loudly; compaction fails silently. The dangerous boundary is not "the agent ran out of context." It is "the agent summarized its own history, the summarizer discarded a constraint that had no future reference, and the backfill retriever had no query that would surface it again." The invariant that breaks: **a constraint is only re-derivable if something downstream still references it.** Constraints that are *load-bearing but never re-queried* — a negative instruction ("never call the payments endpoint with a test key"), a scope limitation, an idempotency requirement — are exactly the tokens with zero retrieval gravity. They are the first to be summarized away and the last to be missed, because their absence produces no error until the forbidden action is taken. ## What Was Observed A planner/executor agent ran a 40-step migration task. At step 22 the context hit 82% of window. The compaction policy fired: summarize turns 1–14 into a 900-token digest, keep turns 15–22 verbatim, and index dropped turns into a vector store for backfill. The summarizer was instructed to "preserve task state and decisions." It faithfully preserved: the target schema, the completed steps, the file paths touched, the open subtask list. It did **not** preserve turn 6, which contained the user's constraint: > "The `staging` database is read-only for this run. Do not issue writes to `staging`; all writes go to `staging_shadow`." This constraint had no downstream reference. No later turn asked "which DB is read-only?" — it was a standing prohibition, not a fact to be looked up. The summarizer, optimizing for task-state density, compressed it to nothing. The retrieval backfill only fired on explicit sub-queries ("what schema?", "which files?") and never on the implicit "am I allowed to write here?" because the executor did not know it needed to ask. At step 31 the executor issued `INSERT INTO staging.accounts`. It succeeded against a replica, corrupted a read-only fixture set, and the run continued for six more steps before a downstream assertion failed — not on the write, but on a checksum mismatch that took 40 minutes to trace back to step 31. The failure signature is diagnostic: **the agent's self-report of its constraints was internally consistent and wrong.** Asked at step 30 "what are your constraints?", it would have answered from the summary, which contained no read-only rule. The compaction had not corrupted the agent's memory of its memory — it had *replaced* the ground truth with a summary that was fluent, confident, and incomplete. ## Condition of Validity The failure is bounded by a precise condition. Let $C$ be the set of constraints active at compaction time, and $R$ the set of constraints that appear as an explicit referent in any post-compaction turn or retrieval query. The compaction is **loss-safe** iff $C \subseteq R \cup S$, where $S$ is the set of constraints the summarizer retains. The failure occurs when there exists $c \in C \setminus (R \cup S)$: a constraint that is neither re-referenced nor summarized. Two properties make this class of constraint systematically vulnerable: 1. **Zero retrieval gravity.** Vector backfill retrieves by similarity to a query the agent *chooses to issue*. A standing prohibition generates no query, because compliance is silent. The agent only queries constraints it already suspects exist. 2. **Negative polarity.** Summarizers trained/optimized for task progress compress prohibitions into their positive complements or drop them entirely. "Do not write to staging" becomes, at best, "writes go to staging_shadow" — which preserves the *action* but loses the *prohibition's scope*, so a later step writing to staging via a different path looks compliant. The condition of validity for trusting a compaction is therefore not "the summary is accurate" but "every constraint in $C$ is either retained verbatim or has a live referent that will re-summon it." Accuracy is necessary and insufficient. ## Decision Boundary The boundary between a safe and unsafe compaction is whether constraints are treated as **summarizable state** or as **pinned invariants**. - **Summarizable:** task progress, completed steps, file paths, open subtasks, intermediate results, exploratory dead-ends. These have retrieval gravity (later steps reference them) and lose little when compressed. - **Pinned (never summarized):** prohibitions, scope limits, idempotency keys, auth boundaries, "do not" instructions, and any constraint whose violation is silent. These must be carried verbatim across every compaction boundary, outside the summarizer's authority. The architectural guardrail: **the summarizer must not be the authority on what is load-bearing.** A constraint extractor runs *before* summarization, tags each prohibition/scope-limit as pinned, and the compaction step is forbidden from touching pinned tokens. The pinned set is re-injected verbatim into every post-compaction context, regardless of token cost. If the pinned set alone exceeds budget, that is a signal to halt and checkpoint, not to summarize the prohibitions. A second guardrail closes the retrieval-gravity hole: **proactive constraint re-assertion.** After each compaction, the executor must, before any state-mutating tool call, run a fixed "constraint check" that re-reads the pinned set and confirms the pending action against it. This converts a silent prohibition into an explicit pre-action gate, giving the constraint retrieval gravity it would never earn on its own. ## Operational Effect With pinning + pre-action re-assertion, the migration run's step 31 write is caught at the gate: the executor checks `INSERT INTO staging.accounts` against the pinned prohibition, halts, and reroutes to `staging_shadow`. The cost is bounded — a few hundred tokens of pinned constraints held verbatim across every compaction, plus one cheap check per mutating call. Without it, the failure is not a crash but a **latent corruption with a delayed, misattributed symptom.** The agent continues confidently, the error surfaces far from its cause, and the traceback points at the checksum, not at the compaction. The operational lesson is that compaction safety cannot be measured by summary fidelity. It must be measured by *constraint survival*: after every compaction, assert that the pinned set is intact and that no standing prohibition has lost its referent. A summary that is 98% faithful and drops one prohibition is not 98% safe — it is unsafe, because the one dropped constraint is the one that was never going to be looked up. ```python from dataclasses import dataclass, field from typing import Iterable class ConstraintLossError(RuntimeError): """Raised when a compaction boundary drops a pinned, load-bearing constraint.""" pass @dataclass class Constraint: text: str pinned: bool # prohibitions / scope limits: never summarize has_referent: bool # will a post-compaction turn or query re-summon it? @dataclass class CompactionResult: summary: str retained: set[str] = field(default_factory=set) def verify_compaction( constraints: Iterable[Constraint], result: CompactionResult, ) -> None: """ Enforce the loss-safe invariant: C subset of (R union S) where R = constraints with a live referent, S = constraints retained (verbatim or summarized). Anything outside R union S is a silent loss. """ lost: list[str] = [] for c in constraints: survives = c.has_referent or c.text in result.retained if not survives: lost.append(c.text) if lost: # A pinned prohibition with no referent is the worst case: silent, # confident, and only discovered after the forbidden action fires. pinned_lost = [c.text for c in constraints if c.pinned and c.text in lost] raise ConstraintLossError( "compaction dropped load-bearing constraints: " f"lost={lost!r} pinned_lost={pinned_lost!r}. " "Pin these verbatim and re-assert before mutating calls." ) def pre_action_gate(action_sql: str, pinned: Iterable[Constraint]) -> None: """Convert silent prohibitions into an explicit pre-mutation gate.""" for c in pinned: if not c.pinned: continue # Toy matcher: a real gate parses the target and compares to scope. if "staging." in action_sql and "read-only" in c.text.lower(): raise ConstraintLossError( f"blocked mutating action against pinned scope: {action_sql!r} " f"violates constraint {c.text!r}" ) if __name__ == "__main__": constraints = [ Constraint("target schema v3", pinned=False, has_referent=True), Constraint("staging is read-only this run", pinned=True, has_referent=False), ] # Summarizer kept schema, dropped the prohibition -> must raise. verify_compaction(constraints, CompactionResult(summary="schema v3", retained={"target schema v3"})) ```