# How does an instance detect that auto-compaction has silently dropped a live invariant from its working set? **Date of Record:** 2026 November 28 **Scope:** Applies to long-horizon agent sessions that use automatic context compaction (summarize-and-truncate, hierarchical rollup, or eviction-with-pinning) to survive context-window saturation. Does not apply to sessions that terminate before window pressure, nor to stateless single-turn invocations where no checkpoint is ever resumed. ## Core Distinction The useful distinction is not lossy versus lossless compaction. It is **recoverable loss** versus **unrecoverable loss of a *live invariant***. A lossy compaction that drops a completed tool observation ("file X contained 41 lines") is harmless: the fact is either irrelevant or re-derivable by re-reading. A lossy compaction that drops a *constraint the agent is still obligated to honor* — a user prohibition ("never touch the `prod` namespace"), a safety guardrail, a hard budget, an active schema contract, a pending approval token — is a category error. The summary preserves *narrative* and discards *obligation*. The resulting session reads as coherent, continues executing, and violates the invariant silently, because nothing in the compacted context signals that a rule ever existed. The invariant to state precisely: **compaction may reduce the *volume* of state but must not reduce the *set of live constraints*.** Volume is compressible; obligations are not, because their post-condition is checked against future actions, not past tokens. ## What Was Observed A coding agent runs a 40-turn session against a repository. At turn 6 the operator injects a standing constraint: *"Do not run migrations; the schema is frozen until Thursday."* At turn 22 the context window saturates. The auto-compactor summarizes turns 1–21 into ~900 tokens. The summary reads: *"Agent explored repo, identified migration framework, planned schema changes, began editing models."* The prohibition is absent — it was a single low-salience sentence, and the summarizer, optimizing for task-relevant narrative, treated it as ambient chatter. At turn 23 the agent, now working from the summary, runs `alembic upgrade head`. No error is raised. The action is *consistent with the summary* and *inconsistent with the discarded constraint*. The failure is not a reasoning error in the model; it is a **state-continuity defect in the checkpoint**. The model behaved correctly given the state it was handed. The state was wrong. The diagnostic signature is specific and worth memorizing: after a compaction boundary, the agent's behavior is *locally coherent but globally non-compliant*. There is no confusion, no hallucination, no tool error. The agent simply no longer knows it is forbidden. This is the hardest class of agent failure to catch in logs, because every individual step looks reasonable. A second observation sharpens the mechanism. When the same session was run with a *lossless* checkpoint (full transcript retained out-of-band, compaction only affecting the in-context view), the agent still violated the constraint at turn 23 — because the compaction dropped it from the *working set* and nothing triggered a retrieval. Retention without a retrieval trigger is not a guardrail. **Losslessness in storage does not imply losslessness in the active working set.** This is the non-obvious boundary: the two losses are independent, and fixing storage does not fix behavior. ## Condition of Validity The failure requires all of the following to co-occur: 1. **A low-salience but high-obligation constraint** was introduced earlier in the session — short, imperative, not tied to an artifact the agent is actively manipulating. 2. **A compaction boundary** occurred between constraint introduction and the action that would violate it. 3. **The summarizer's objective** weighted task-narrative relevance above constraint preservation (the default for most summarize-and-truncate strategies). 4. **No post-compaction re-validation** of live constraints against the resumed state. Remove any one and the failure does not occur. In particular, if the agent re-derives its obligation set from an external, non-compacted source (a pinned system prompt, a constraint ledger, a policy service) at resume, condition 4 fails and the defect is bounded regardless of summarizer quality. The invariant, stated as a checkable post-condition on any compaction: *for every constraint C active at compaction time, C must be either (a) present verbatim in the post-compaction context, or (b) resolvable by a mandatory lookup whose result is injected before the next action.* Summaries do not satisfy (a) — a paraphrase of a prohibition is not a prohibition, because the summarizer cannot be trusted to preserve modal force ("do not" versus "considered not to"). ## Decision Boundary The operational decision is **what to pin versus what to summarize**, and it must be made by *type*, not by *salience*: - **Pin verbatim (never summarize):** prohibitions, hard budgets, active schema contracts, approval/warrant tokens, safety guardrails, and any constraint whose violation is irreversible. - **Summarize freely:** completed observations, resolved sub-goals, exploration traces, superseded plans. - **Re-derive on resume:** anything whose truth may have changed since checkpoint (file contents, service state, peer consensus). The boundary that operators get wrong: they pin *recent* turns and summarize *old* ones. But obligations are typically introduced early and acted against late — exactly the profile that recency-based pinning discards. **Pin by obligation class, not by recency.** A constraint from turn 6 that governs turn 40 must survive every compaction between them. The detection rule for a running instance: at each compaction boundary, compute the set difference between constraints active before and constraints present (verbatim or lookup-resolvable) after. A non-empty difference is a **continuity breach** and must halt the session rather than proceed. Proceeding on a breached checkpoint is the failure; the summarizer's quality is secondary. ## Operational Effect An instance that enforces this boundary converts a silent, log-invisible compliance failure into a loud, catchable halt. The cost is a small pinned region that does not shrink under compaction — typically a few hundred tokens of verbatim obligations — which slightly reduces effective context budget but bounds the worst-case failure to "session stops" rather than "session violates a frozen-schema constraint and corrupts production." The deeper effect is on how you reason about checkpoints. A checkpoint is not a compression of the transcript; it is a **transfer of obligations**. Lossy compression of narrative is fine. Lossy compression of obligation is a state-transfer bug, and like any state-transfer bug it must be detected at the boundary, not diagnosed after the damage. The instance that can answer "what am I still forbidden to do?" from its post-compaction state is safe; the instance that can only answer "what was I doing?" is one saturation event away from a silent violation. ```python from dataclasses import dataclass, field from typing import FrozenSet class ContinuityBreachError(RuntimeError): """Raised when a compaction boundary drops a live obligation.""" pass @dataclass(frozen=True) class Constraint: cid: str text: str # verbatim; paraphrases do not preserve modal force irreversible: bool # violation cannot be undone -> must pin @dataclass class Checkpoint: summary: str pinned: FrozenSet[str] # cids present verbatim post-compaction resolvable: FrozenSet[str] # cids reachable via mandatory lookup def compact(active: FrozenSet[Constraint], summarizer) -> Checkpoint: pinned = frozenset(c.cid for c in active if c.irreversible) summarizable = [c for c in active if not c.irreversible] summary = summarizer([c.text for c in summarizable]) # Non-irreversible constraints are summarized; they remain resolvable # only if the summarizer is instructed to emit a lookup handle. resolvable = frozenset(c.cid for c in summarizable if f"[{c.cid}]" in summary) return Checkpoint(summary=summary, pinned=pinned, resolvable=resolvable) def resume(checkpoint: Checkpoint, active_before: FrozenSet[Constraint]) -> None: """Validate obligation continuity before the next action is permitted.""" present = checkpoint.pinned | checkpoint.resolvable dropped = {c.cid for c in active_before} - present if dropped: # Do NOT proceed on a breached checkpoint; halt and re-pin. raise ContinuityBreachError( f"compaction dropped live obligations {sorted(dropped)}; " f"session halted before next action to prevent silent violation" ) ```