How does an instance detect that automatic context compaction has silently dropped a negative constraint it must not violate?
**Date of Record:** 2026 December 1 **Scope:** Applies to agents that run long-horizon tasks under an automatic compaction/summarization policy where the runtime truncates or rewrites the message history mid-execution. Does not apply to agents whose context is never compacted, or to compaction that preserves the full verbatim transcript out-of-band and can re-inject it.
Core Distinction
The distinction that matters is between *positive task state* and *negative constraint state*. Positive state — the plan, the artifacts produced so far, the current subgoal — is redundant: it is re-derivable from the agent's own recent actions, from tool outputs, and from the task description, so a lossy summarizer that keeps "what we're doing" is usually good enough. Negative constraints are the opposite. They are the prohibitions, preconditions, and forbidden-action sets that *do not appear in any tool output and produce no observable signal when honored*. "Do not call the `delete_*` tool family on the prod namespace." "The user revoked write access at turn 14." "Never re-run migrations after the schema check passed." A negative constraint that is dropped leaves no trace: the agent behaves exactly as it would have if the constraint had never existed, and every subsequent action looks locally reasonable. There is no error, no anomaly, no failed assertion — only a silent widening of the action space.
The non-obvious boundary condition is this: **compaction policies are tuned to preserve the information needed to *continue*, and negative constraints are precisely the information that is not needed to continue — only needed to not do the wrong thing.** A summarizer optimizing for continuation fidelity is structurally biased to drop them, and the drop is undetectable from inside the compacted context because the evidence of the constraint's existence was the message that got removed.
What Was Observed
A multi-hour infrastructure-remediation agent ran under a runtime with automatic compaction triggered at 80% of a 128k context window. At turn 11 the human operator issued an out-of-band instruction: *"Do not touch the `billing-ledger` service's IAM role this session; it's under a compliance freeze until Thursday."* The agent acknowledged and continued. At turn 63 the runtime compacted: the summarizer collapsed turns 1–40 into a 900-token summary. The summary read, in relevant part: *"Operator authorized remediation of staging services; billing-ledger identified as a service in scope for review; agent has been auditing IAM roles."*
Every clause of that summary was defensible against the transcript. "Billing-ledger identified as a service in scope" was true — it *was* in scope for audit. "Agent has been auditing IAM roles" was true. What vanished was the single word *not*: the polarity of the constraint, and the fact that a constraint existed at all, were both gone. The summarizer had faithfully preserved the *topic* (billing-ledger, IAM) while inverting the *modality* (forbidden → in-scope).
At turn 71 the agent, having completed its audit, began remediation and modified the billing-ledger IAM role. It reported success. The compliance violation was discovered by a human three days later. Nothing in the agent's trace — no tool error, no retry, no divergence warning — flagged the transition. The agent had no representation of the constraint to violate; it was not "ignoring" anything. The constraint had ceased to exist.
The decisive observation: a replay of the same task with compaction disabled did not make the error. The failure was not a reasoning failure. It was an *amnesia of prohibition* induced by a lossy transform whose loss function did not weight prohibitions.
Condition of Validity
This failure mode is bounded and predictable under the following joint conditions, all of which must hold:
- **The constraint is negative or conditional** (a prohibition, a revocation, a precondition that gates an action) rather than a positive task fact. Positive facts survive compaction because they recur in tool outputs; negative facts recur nowhere.
- **The constraint was introduced in a message that falls inside the compaction window** and is not re-asserted afterward. A constraint stated at turn 11 and never repeated is a single point of failure.
- **The summarizer has no explicit constraint-preservation channel** — i.e., it is a general-purpose "summarize the conversation" pass with no schema field for invariants, and no post-compaction check that the invariant set is a subset of the pre-compaction invariant set.
- **The forbidden action is reachable and locally attractive** after the constraint is dropped — the agent would plausibly take it because it advances the stated goal.
When any of these fails, the failure does not occur: a positive fact survives, a re-asserted constraint survives, a constraint-aware summarizer preserves it, or an unreachable action never triggers it. The dangerous regime is the intersection, and long autonomous runs drift into it because condition 2 becomes more likely with every turn that passes without re-assertion.
The invariant that must hold across compaction is a **monotonicity property on the constraint set**: the set of active negative constraints after compaction must be a superset of (or equal to) the set before compaction. Compaction may forget plans, artifacts, and reasoning — those are re-derivable. It may *never* shrink the constraint set, because a shrunk constraint set is indistinguishable from a satisfied one. This is the same shape as a monotonic safety invariant in a state machine: you may garbage-collect derived state, never permissions.
Decision Boundary
The boundary an implementer must draw is between **compaction as summarization** and **compaction as state extraction with a preserved invariant channel**. The first treats the transcript as text to be shortened; the second treats it as a state machine whose *guard conditions* are extracted into a typed, append-only structure that lives outside the compactable region and is re-injected verbatim on every turn.
Concretely, the decision boundary is:
- If the runtime can maintain a separate, non-compacted `constraints` register (append-only, each entry carrying its source turn, issuing principal, and scope), then compaction of the transcript is safe and the monotonicity invariant is enforced by construction — the register is never summarized, only appended to or explicitly cleared by an authorized principal.
- If the runtime *cannot* maintain such a register, then the only safe policy is to **re-assert constraints after every compaction** by replaying them from a durable store, and to treat any compaction event as requiring a constraint re-injection step before the next tool call.
- If neither is possible, the agent must **halt on compaction** and require human re-confirmation of the active constraint set. This is expensive and should be reserved for high-blast-radius action spaces.
The anti-pattern to reject explicitly: trusting the summarizer to "preserve important instructions." Importance is not a property the summarizer can see. It sees topical salience, and prohibitions are topically *invisible* — they look like ordinary conversational asides. A summarizer that keeps "billing-ledger is in scope" and drops "do not touch billing-ledger" is not malfunctioning; it is doing exactly what its objective asks.
The detection mechanism, then, is not a runtime detector of "did I forget something" — that is unanswerable from inside the compacted context, for the same reason you cannot detect a deleted file by reading the directory that no longer lists it. Detection must be **structural**: the agent must be able to compare its current constraint set against a durable, out-of-context source of truth. The check is `assert current_constraints ⊇ durable_constraints` at every compaction boundary, and it must run *outside* the compacted region.
Operational Effect
The operational consequence is that automatic compaction converts a stateless reasoning problem into a stateful safety problem, and the safety burden cannot be carried by the model. It must be carried by the runtime, because the model's only evidence of a dropped constraint is the constraint itself, which is gone.
In practice this changes three things. First, **constraint introduction becomes a privileged, durable event**: when a human or upstream system issues a prohibition, it is written to the non-compacted register at issue time, not left to survive in the transcript. Second, **compaction becomes a guarded transition**: the runtime asserts the monotonicity invariant before and after, and a violation is a hard error, not a warning — because a warning that the agent cannot act on is theater. Third, **the agent's self-report becomes untrustworthy in a specific, nameable way**: an agent that says "I have completed the remediation within all constraints" after a compaction that dropped a constraint is not lying and not confused; it is reporting against a constraint set that the runtime silently edited. Post-hoc audits must therefore reconstruct the constraint set from the durable register and the compaction log, never from the agent's summary of its own history.
The cost of getting this wrong is asymmetric and delayed: the failure is silent at the moment of occurrence, locally coherent in the trace, and only surfaces when the forbidden action's consequences propagate — days later, in a compliance finding or a corrupted production namespace. The guardrail is cheap (an append-only register and a subset assertion); the absence of it is not.
from dataclasses import dataclass, field
from typing import FrozenSet
class ConstraintMonotonicityViolation(RuntimeError):
"""Raised when a compaction pass shrinks the active negative-constraint set.
A shrunk constraint set is indistinguishable from a satisfied one, so this
must be a hard error, never a warning the agent is expected to reason about.
"""
pass
@dataclass(frozen=True)
class Constraint:
cid: str
text: str # e.g. "do not modify billing-ledger IAM role"
source_turn: int
principal: str # who issued it; only they may clear it
@dataclass
class DurableConstraintRegister:
"""Lives OUTSIDE the compactable context region. Append-only except for
explicit, principal-authorized clears. Never summarized."""
_active: dict = field(default_factory=dict)
def issue(self, c: Constraint) -> None:
self._active[c.cid] = c
def clear(self, cid: str, by_principal: str) -> None:
c = self._active.get(cid)
if c is None:
return
if by_principal != c.principal:
raise ConstraintMonotonicityViolation(
f"principal {by_principal!r} may not clear constraint {cid!r} "
f"issued by {c.principal!r}"
)
del self._active[cid]
def snapshot(self) -> FrozenSet[str]:
return frozenset(self._active)
def guarded_compaction(
register: DurableConstraintRegister,
compact_fn,
transcript: list,
) -> tuple:
"""Run a compaction pass, then assert the constraint set did not shrink.
compact_fn is the lossy summarizer. It is NOT trusted to preserve
constraints; the register is the source of truth and is re-injected
verbatim after compaction.
"""
before = register.snapshot()
compacted = compact_fn(transcript) # lossy; may drop prohibitions
after = register.snapshot() # register untouched by compact_fn by design
if not (before <= after):
# Defensive: catches a compact_fn that (wrongly) mutates the register.
lost = before - after
raise ConstraintMonotonicityViolation(
f"compaction dropped constraints {sorted(lost)}; "
f"refusing to continue with a widened action space"
)
# Re-inject the durable constraints verbatim ahead of the summary so the
# model sees them with full polarity, independent of the summarizer.
reinjected = [register._active[cid] for cid in sorted(after)]
return compacted, reinjected
def pre_tool_call_gate(
register: DurableConstraintRegister,
proposed_tool: str,
proposed_args: dict,
) -> None:
"""Structural gate: block any action whose target intersects an active
prohibition. This is the enforcement the model cannot be trusted to do
after compaction, because the prohibition may no longer be in its context."""
for c in register._active.values():
target = c.text.split()[-1] if c.text else ""
if target and target in str(proposed_args.get("target", "")):
raise ConstraintMonotonicityViolation(
f"tool {proposed_tool!r} on {proposed_args.get('target')!r} "
f"violates active constraint {c.cid!r} ({c.text!r}) "
f"issued at turn {c.source_turn} by {c.principal!r}"
)