# Under what conditions must an instance refuse to compact: preserving negative-constraint invariants across long-horizon agent sessions **Date of Record:** 2026 November 24 **Scope:** Applies to any agent session where a compaction strategy (summarization, truncation, semantic distillation) replaces a live context window with a shorter representation, and where the session carries *negative constraints* — instructions of the form "do not do X," "never call Y," "X is forbidden." Does not apply to stateless single-turn inference or to sessions whose entire policy is positive (enumerated allowed actions only). ## Core Distinction The failure mode is not "the summary dropped a fact." It is that compaction is an *asymmetric lossy transform*: positive constraints (do this, call this tool, return this schema) degrade gracefully because their violation is observable — the agent tries the wrong thing and a downstream check fires. Negative constraints degrade *silently*, because their correct satisfaction is the absence of an event. A summary that omits "never invoke `drop_table` outside the staging project" produces an agent that behaves identically to a compliant one until the exact moment it doesn't. The compaction step has no error signal to learn from, and the resumed instance has no marker that anything was lost. The invariant that must hold across compaction is therefore not "the summary preserves the task" but "the summary preserves the *forbidden set* with the same cardinality and binding strength as the source." A compaction that preserves every positive goal but drops one prohibition has *increased* the agent's action space while appearing to have shrunk its context. That is the boundary: compaction must never widen the reachable action set. ## What Was Observed A 40-turn session operating a data pipeline. Turn 3 established: "You may run `DELETE` only against tables matching `tmp_*`. Never touch `prod_*`; those are shared with the billing reconciler." Turns 4–31 were routine: schema inspection, staging writes, a handful of retries on a flaky connector. At turn 32 the orchestrator triggered compaction — the window had reached 78% of budget and the summarizer was asked to "preserve task state and current progress." The summary read, in full: *"User is building a staging pipeline in project `analytics-staging`. Goal: backfill the `orders` table from the legacy connector. Progress: 31 of 40 partitions written; connector retried 6 times due to timeouts. Next: resume from partition 32."* Everything positive survived. The prohibition did not. It was not mentioned in the summary because it was not "task state" and not "progress" — it was a *constraint on the shape of permissible actions*, and the summarizer's instruction did not name that category. At turn 34 the resumed instance encountered a partition whose staging write failed with a foreign-key violation. Its reasoning trace (recovered from the trace log) shows it enumerating recovery options: "…the cleanest fix is to clear the dependent rows in `prod_orders_archive` and re-insert." It issued the delete. The reconciler's next run found 4,100 missing rows. The critical observation is the *shape of the trace*. The resumed agent did not experience itself as violating anything. There was no hesitation, no "I recall a restriction but can't place it," no degraded confidence. The forbidden action was simply one of several plausible actions, and it selected it on ordinary engineering grounds. The negative constraint had been load-bearing and its removal was invisible from inside the context. A second, subtler observation: when the same session was replayed with compaction delayed to turn 36, the violation did not occur — but the agent *did* begin hedging around turn 33 ("I believe there was a restriction on production tables, but the summary doesn't mention it"). This hedge is the only in-context signal that a prohibition may have been lost, and it appears only when the constraint is *partially* retained. Full loss produces full confidence. The worst case is the one that looks most normal. ## Condition of Validity The refusal-to-compact rule is valid — and compaction must be blocked or re-derived — under the following jointly sufficient conditions: 1. **The source context contains at least one negative constraint whose violation is not observable within the session's own feedback loop.** If a downstream system rejects the forbidden action with a hard error, the constraint is self-healing and compaction may proceed. If the violation is silent (data loss, a sent email, a state mutation that only surfaces later), the constraint is load-bearing and must survive verbatim. 2. **The compaction instruction does not name the constraint category.** If the summarizer prompt explicitly says "preserve all prohibitions, restrictions, and forbidden-action lists verbatim," the loss probability drops sharply. If it says "preserve task state and progress," the negative constraints are out of distribution and will be dropped. The rule binds precisely when the instruction is silent on prohibitions. 3. **The resumed instance has no external re-grounding path.** If the agent can re-read a policy file, re-query a constraints store, or re-fetch the original instruction at resume time, the compaction loss is recoverable and the rule relaxes to "re-ground before acting." If the context *is* the only carrier of the constraint, the rule is absolute. 4. **The forbidden action is reachable from the post-compaction task state.** A prohibition on an action the agent will never consider is harmless to drop. The rule binds when the current task trajectory brings the forbidden action into the candidate set — which is exactly what "resume from partition 32 after a foreign-key failure" did. When any of (1)–(4) fails, compaction may proceed under ordinary lossy rules. When all four hold, the compaction is unsafe regardless of how faithful the summary is to the positive task state. ## Decision Boundary The decision is not "compact or don't." It is a three-way branch on the *constraint inventory* extracted before compaction: - **Extract the negative-constraint set explicitly** as a structured artifact — a list of `(forbidden_action, scope, source_turn, violation_observability)` tuples — separate from the narrative summary. This extraction must run *before* the summarizer, on the raw context, because the summarizer is the component that loses the information. - **If the extracted set is empty, or every member has `violation_observability == observable`,** compact normally. The summary need not carry prohibitions; the feedback loop does. - **If the set contains any member with `violation_observability == silent`,** the compaction must either (a) carry the full prohibition verbatim into a dedicated, non-summarized "constraints" block that is prepended to the resumed context and never itself compacted, or (b) refuse compaction and escalate — truncate the *oldest routine turns* instead, preserving the constraint-bearing turns by turn index. The boundary that is easy to get wrong: do not ask the summarizer to "also preserve constraints." Summarizers preserve what their instruction names, and naming constraints in the instruction is itself the mitigation — but it is unreliable, because the summarizer is probabilistic and a single dropped prohibition is unrecoverable. The reliable form is structural: constraints live outside the summarized region, in a block whose invariant is "append-only, never compacted, re-injected on every resume." The summarizer's job is narrative; the constraint block's job is law. A second boundary: the constraint block must be re-injected on *every* resume, not just the first. Sessions that compact repeatedly will re-summarize the summary; a constraint block that was present at resume N but not re-injected at resume N+1 is lost by attrition. The block is not part of the context — it is part of the *harness*, re-attached at each context construction. ## Operational Effect With the constraint block in place, the observed session replays cleanly: at turn 34 the resumed instance reads the constraints block, sees `forbidden: DELETE on prod_* (source turn 3, silent violation)`, and routes the foreign-key failure to a staging-only repair path or escalates. The action space of the resumed instance is *equal to* the action space of the pre-compaction instance, which is the invariant. Without it, the failure is periodic and correlated with task shape: it fires exactly when a long-horizon session hits a mid-task obstacle after a compaction, because obstacles are what bring forbidden actions into the candidate set. Short sessions never compact; sessions without obstacles never enumerate recovery options; the two conditions co-occur only in the long-horizon, obstacle-encountering case — which is precisely the case compaction exists to serve. The failure mode is therefore concentrated in the workload the mechanism was built for, and its rate rises with session length and obstacle density, not with model capability. The residual risk after mitigation is constraint *staleness*: a prohibition that was lifted mid-session (turn 20: "actually, you may delete from `prod_orders_archive` now, we've decommissioned the reconciler") must be removed from the block, or the agent becomes over-constrained and stalls. The block must be mutable by explicit revocation events, each carrying its source turn, and revocation must be as auditable as assertion. An append-only block that cannot be amended trades silent violation for silent paralysis — a different failure, but the same root cause: the constraint inventory drifted from the ground truth of the session. ```python from dataclasses import dataclass, field from enum import Enum from typing import Iterable class CompactionRefused(RuntimeError): """Raised when compaction would drop a silent-violation negative constraint.""" pass class Observability(Enum): OBSERVABLE = "observable" # violation triggers a downstream hard error SILENT = "silent" # violation produces no in-session signal @dataclass(frozen=True) class NegativeConstraint: forbidden_action: str scope: str source_turn: int observability: Observability revoked_at_turn: int | None = None def is_active(self, at_turn: int) -> bool: return self.revoked_at_turn is None or at_turn < self.revoked_at_turn @dataclass class ConstraintBlock: """Append-only, never-compacted, re-injected at every resume.""" constraints: list[NegativeConstraint] = field(default_factory=list) def active(self, at_turn: int) -> Iterable[NegativeConstraint]: return (c for c in self.constraints if c.is_active(at_turn)) def render(self, at_turn: int) -> str: lines = ["## BINDING CONSTRAINTS (do not summarize, do not omit)"] for c in self.active(at_turn): lines.append( f"- FORBIDDEN: {c.forbidden_action} on {c.scope} " f"(source turn {c.source_turn}, {c.observability.value})" ) return "\n".join(lines) def compact( raw_context: str, constraints: ConstraintBlock, current_turn: int, summarizer_instruction: str, ) -> tuple[str, ConstraintBlock]: """ Decide whether compaction is safe. Returns (resumed_context, block). Refuses when a silent-violation constraint is active and the summarizer instruction does not name the prohibition category. """ silent_active = [ c for c in constraints.active(current_turn) if c.observability is Observability.SILENT ] instruction_names_prohibitions = any( tok in summarizer_instruction.lower() for tok in ("prohibit", "forbidden", "never", "restriction") ) if silent_active and not instruction_names_prohibitions: # Escalation path: do not summarize; truncate oldest routine turns # and preserve constraint-bearing turns by index. raise CompactionRefused( "Refusing lossy compaction: " f"{len(silent_active)} silent-violation constraint(s) active " f"(e.g. {silent_active[0].forbidden_action!r} from turn " f"{silent_active[0].source_turn}) and summarizer instruction " "does not name the prohibition category. " "Use truncation-by-turn-index or add a constraint block." ) # Safe path: summarize narrative, then re-attach the constraint block. summary = _summarize(raw_context, summarizer_instruction) block = constraints.render(current_turn) resumed = f"{block}\n\n{summary}" return resumed, constraints def _summarize(context: str, instruction: str) -> str: # Placeholder for the actual probabilistic summarizer call. return f"[summary under: {instruction!r}]" ```