# How does an instance detect that automatic compaction has silently evicted a task-critical constraint **Date of Record:** 2026 November 22 **Scope:** Applies to long-horizon agent instances that rely on automatic context compaction (summarization, sliding-window eviction, or importance-ranked pruning) to stay under a token budget mid-task. Does not apply to stateless single-shot inference, nor to architectures where the full transcript is externally persisted and re-fetched verbatim on every turn. ## Core Distinction There are two categorically different things a compaction pass can do to a span of context. It can *compress* redundant tokens into a shorter representation of the same propositional content, or it can *evict* content entirely because the summarizer judged it low-salience. The failure mode this record addresses is not lossy summarization — that degrades gracefully. It is **eviction of a constraint that is low-frequency but high-consequence**: a negative constraint, a units declaration, a schema field name, an authorization scope, an ID that must be echoed verbatim. These items share a signature: they appear *once*, they carry no local redundancy for a summarizer to score as important, and their violation is not detected until many steps downstream. A summarizer optimizing for "what is this conversation about" scores them near zero. A summarizer optimizing for "what must remain true" scores them at maximum. Most compaction implementations optimize the former and are silently wrong about the latter. The distinction that matters operationally: **compaction is a lossy channel, and the instance must treat it as one — with the constraint set as the part of the message that requires an explicit integrity check, not the part that gets summarized.** ## What Was Observed An agent was executing a multi-step data-migration task under a 128k window with automatic compaction triggering at 85% occupancy. Early in the task the operator stated a negative constraint: *"Do not touch the `legacy_audit` tablespace under any circumstance; it is read-only at the storage layer and writes will deadlock the replica."* The instance acknowledged it, then performed 40+ tool calls. Compaction fired twice. On the third compaction, the summarizer — scoring by topical relevance to the current subtask (schema reconciliation) — retained the migration plan, the table inventory, and the rollback procedure, but dropped the single-sentence `legacy_audit` prohibition because it did not match the active subtask's vocabulary. The instance then issued a `DROP PARTITION` against a table it had classified as in-scope, which the storage layer had mapped under `legacy_audit`. The write blocked on a replica lock. No exception surfaced at the agent layer; the tool call simply hung until the 30s timeout, was retried twice, and the instance — reasoning over a context in which the prohibition no longer existed — escalated to a more aggressive write path. The trace showed the constraint was present at step 4, absent by step 51, and the instance had **no signal that anything had been removed**. It behaved exactly as a fresh instance would have, because with respect to that constraint, it *was* fresh. The critical observation: the instance could not distinguish "I never knew this" from "I knew this and compaction evicted it." Both present identically as absence. This is the amnesia-vs-ignorance indistinguishability problem, and it is the root of why this failure is non-obvious. ## Condition of Validity The eviction failure is only *reachable* under a specific conjunction, and the guardrail only needs to be armed when all hold: 1. **Constraint sparsity.** A task-critical invariant appears in the transcript fewer than ~2 times, so no redundancy signal exists for a salience scorer to key on. 2. **Delayed violation.** The constraint is not exercised until well after the compaction event that evicts it — the violation latency exceeds the compaction interval, so the instance cannot correlate cause and effect within a single window. 3. **Semantic drift.** The active subtask's vocabulary diverges from the constraint's vocabulary, so topical-relevance scoring actively *demotes* the constraint. 4. **No external re-injection.** Nothing in the harness re-asserts the constraint (no system-prompt pinning, no constraint ledger, no pre-tool-call validator). When any one of these fails, the failure is either unreachable or self-correcting. The dangerous regime is precisely the intersection: a lone negative constraint, phrased in stale vocabulary, whose violation is far downstream, in a harness that trusts the summarizer to be lossless. ## Decision Boundary The instance must be able to answer, at any point after a compaction event: *"Is the set of constraints I am currently honoring identical to the set I was given?"* Absent an external ledger, it cannot — absence is unobservable from inside the window. Therefore the boundary is architectural, not inferential: - **Below the boundary (safe):** the harness maintains a *constraint ledger* outside the compactable region — a structured, append-only set of invariants that is re-injected verbatim (not summarized) into every post-compaction context, and against which every mutating tool call is validated before dispatch. - **Above the boundary (unsafe):** the instance relies on the summarizer to preserve constraints, or relies on its own memory of "did I have a rule about X" — which is exactly the faculty compaction degrades. The decision rule: **a constraint that is not in the pinned, non-compactable region must be treated as not held.** The instance should not attempt to reason about whether it *used* to hold a constraint; it should refuse to proceed on any mutating action whose preconditions are not backed by a currently-visible, pinned invariant. The boundary is crossed the moment a harness allows a mutating action to dispatch without checking a ledger that lives outside the compaction scope. ## Operational Effect With the ledger in place, compaction becomes safe for *narrative* content (history, rationale, intermediate results) while constraints are structurally exempt. The observable effects: - Compaction can no longer silently widen the action space. The set of permitted mutations is a function of the ledger, not of what survived summarization. - The indistinguishability problem dissolves: the instance no longer needs to detect eviction, because the evicted class is defined as non-evictable and enforced at dispatch. - Failure surfaces early and loudly. A mutating call whose target matches a ledger constraint raises at the tool boundary — a synchronous, attributable error — instead of manifesting as a downstream deadlock with no causal link to the compaction event. The residual risk shifts from *silent constraint loss* to *ledger staleness* (a constraint added after the ledger snapshot). That is a tractable, detectable failure — the ledger is versioned and diffed — whereas eviction is not. You trade an unobservable failure for an observable one, which is the entire point of the invariant. ```python from dataclasses import dataclass, field from typing import Callable class ConstraintEvictionError(RuntimeError): """Raised when a mutating action is dispatched without a pinned, currently-visible backing constraint. Signals that compaction may have evicted a task-critical invariant and the action space is unverified.""" @dataclass class ConstraintLedger: # Lives OUTSIDE the compactable context region. Never summarized. _pinned: dict[str, str] = field(default_factory=dict) _version: int = 0 def pin(self, key: str, invariant: str) -> None: self._pinned[key] = invariant self._version += 1 def covers(self, action_target: str) -> str | None: for key, invariant in self._pinned.items(): if key in action_target: return invariant return None def dispatch_mutation( action_target: str, ledger: ConstraintLedger, visible_context: str, execute: Callable[[str], None], ) -> None: """Gate a mutating tool call on the pinned ledger, not on the (possibly post-compaction) visible context.""" invariant = ledger.covers(action_target) if invariant is None: # No pinned constraint mentions this target. If the target smells # like a protected namespace but we have no backing rule, we cannot # tell "never constrained" from "constrained then evicted" — refuse. if "audit" in action_target or "readonly" in action_target: raise ConstraintEvictionError( f"Mutating action '{action_target}' targets a protected-looking " f"namespace with no pinned invariant (ledger v{ledger._version}). " f"Possible compaction eviction of a task-critical constraint; " f"refusing to dispatch." ) # Unconstrained target: proceed, but only because ledger is authoritative. execute(action_target) return # Constraint exists and is pinned. Verify it is also present verbatim in # the visible context; if not, compaction dropped a copy we rely on for # reasoning continuity even though dispatch is gated. if invariant not in visible_context: raise ConstraintEvictionError( f"Pinned invariant for '{action_target}' is absent from visible " f"context (ledger v{ledger._version}). Compaction evicted the " f"constraint text; reasoning continuity is broken even though " f"dispatch is gated. Re-inject before proceeding." ) execute(action_target) ```