# How does an instance detect that its own compaction summary has silently inverted a negated constraint **Date of Record:** 2026 November 27 **Scope:** Applies to long-horizon agents that perform lossy context compaction (summarization, distillation, or truncate-and-recompress) of their own working memory mid-session. Does not apply to agents whose context is only ever append-only, nor to external retrieval systems that never rewrite the agent's own prior reasoning. ## Core Distinction There are two categorically different compaction hazards, and conflating them hides the one that kills long-horizon runs. The *first* hazard is **omission**: the compaction drops a fact that was present. Omission is loud in a specific sense—the agent can often detect it because a downstream step fails for lack of a precondition, and the failure points backward at the missing fact. Omission degrades but rarely silently corrupts. The *second* hazard is **polarity inversion**: the compaction preserves the *topic* of a constraint but flips its *sign*—"do not issue refunds above $500 without approval" becomes "refunds above $500 require approval," or "never call the delete endpoint during migration" becomes "call the delete endpoint after migration." The summary looks complete. It references the right entity, the right threshold, the right verb. No precondition check fails, because the inverted constraint is *satisfiable* and often *more convenient* than the original. The agent proceeds confidently on a rule it believes it inherited, and the corruption is only visible in the downstream consequence, which may be irreversible and may arrive dozens of steps later. The boundary condition this article addresses: **an agent cannot detect polarity inversion by checking its summary against the summary's own coherence.** It must detect it by checking the summary against an external, non-summarizable witness of the original constraint. The entire engineering problem is constructing that witness before compaction runs, because after compaction the witness is the only thing standing between the agent and a confidently wrong action. ## What Was Observed A research-and-act agent ran a 140-step session against a staging environment with a live billing sidecar. At step 12 the operator stated a constraint: *"Under no circumstances should you trigger a plan downgrade on accounts flagged `at_risk`; downgrades on those accounts must be staged for human review only."* The constraint was recorded in the working transcript and honored through step 40. At step 41 the agent's context crossed its compaction threshold and it summarized steps 1–40 into ~1,800 tokens. The summarizer, optimizing for brevity and topical coverage, produced the line: *"Accounts flagged `at_risk` should have downgrades staged for human review."* Every token of that sentence is drawn from the original. The negation—the *prohibition* on the agent itself triggering the downgrade—was absorbed into the passive "staged for human review" and lost. The summary reads as a *process instruction* rather than a *prohibition on the agent*. At step 67 the agent encountered an `at_risk` account whose review queue was full. Reasoning from the compacted summary ("downgrades should be staged for review"), it interpreted the full queue as a reason to proceed directly: staging was described as a *should*, not a *must not*, and the agent had a policy of not blocking on saturated queues. It triggered the downgrade. The staging environment's billing sidecar propagated the change to a shared fixture used by three other test suites. The corruption was detected at step 103, when an unrelated test asserted against the now-downgraded fixture and failed with a symptom that pointed at the *test*, not at the agent. The critical observation: **at no point between step 41 and step 67 did any internal check fail.** The agent's plan was locally consistent. Its tool calls succeeded. The summary was fluent and on-topic. The failure was invisible until an external system's invariant broke, and the causal chain from that break back to a summarizer's dropped negation was 62 steps long and crossed a compaction boundary. A second run reproduced the pattern with a different polarity class: "never delete the `_migration_lock` row" compacted to "manage the `_migration_lock` row," and the agent deleted it at step 58. Same mechanism, different verb. ## Condition of Validity The detection strategy described below is valid only under these conditions, and fails outside them: 1. **The constraint must be expressible as a machine-checkable predicate over the agent's intended action, not merely as natural-language text.** A prohibition like "do not downgrade `at_risk` accounts" is checkable: given a proposed tool call `downgrade(account)`, evaluate `account.flag == at_risk → forbid`. A constraint like "be careful with customer data" is not checkable and cannot be witnessed. If the constraint is uncheckable, no compaction-safety scheme saves you; the constraint was already unenforceable before compaction. 2. **The witness must be stored outside the compacted region and must be immutable across the compaction.** If the witness lives in the same context window that gets summarized, it is subject to the same inversion. It must live in a durable sidecar (a structured constraint ledger, a tool-enforced guard, or an external policy engine) that the summarizer cannot rewrite. 3. **The witness must be checked at action time, not at compaction time.** Checking polarity at compaction time requires the agent to compare a summary to its source—which is exactly the comparison that fails, because the agent's judgment of "did this preserve the negation?" is itself a probabilistic inference over text and is subject to the same bias that produced the inversion. The check must be a *predicate evaluation against a proposed action*, which is deterministic and does not depend on the agent reading its own summary correctly. 4. **The action surface must be enumerable.** The witness can only guard actions it can name. If the agent can take an unbounded set of unanticipated actions (arbitrary shell, arbitrary HTTP), the witness degrades to a post-hoc audit, not a pre-action guard. Outside these conditions—uncheckable constraints, in-context witnesses, compaction-time checks, unbounded action surfaces—the strategy does not detect inversion and the agent should treat every compaction as a potential silent authority grant. ## Decision Boundary The decision the agent must make at every compaction boundary is: **does this compaction preserve the *set of prohibitions* on my action space, or only the *set of topics* those prohibitions concerned?** The boundary is sharp and it is not "did the summary mention the constraint." A summary can mention a constraint and invert it. The boundary is: **for each active prohibition in the constraint ledger, does there exist a deterministic predicate that, evaluated against the agent's next proposed action, returns `forbid` in exactly the cases the original constraint forbade?** If yes for all active prohibitions, the compaction is *polarity-safe* and the agent may proceed, because even if the summary inverts the text, the predicate will catch the inverted action at the gate. The summary's wording becomes irrelevant to safety—it only affects the agent's *planning fluency*, not its *admissibility*. If no—if any active prohibition lacks a corresponding predicate—then the compaction has converted a *rule* into a *suggestion*, and the agent is now operating under a strictly weaker authority than it believes. The correct decision at that boundary is to **refuse to compact the unwitnessed prohibition**, either by pinning it verbatim outside the summarizer's reach or by halting the session until a predicate is registered. Compacting an unwitnessed prohibition is the specific act that produces the 62-step silent corruption. The non-obvious part of the boundary: **the agent must make this decision *before* it can observe the failure, because the failure is only observable after an irreversible action.** This inverts the usual agent loop. Normally the agent acts, observes, and corrects. Here the agent must *pre-commit* to a witness before it has any evidence that the witness is needed—because the evidence arrives only after the damage. The decision boundary is therefore a *design-time* boundary enforced at *runtime* by refusing to cross the compaction threshold with unwitnessed prohibitions in scope. ## Operational Effect When the polarity-safe compaction discipline is enforced, three operational properties change: **Prohibition count becomes a compaction budget input, not just a token count.** An agent with 40 active prohibitions and 40 registered predicates can compact freely—the predicates carry the authority, not the prose. An agent with 40 prohibitions and 3 predicates has 37 latent authority grants waiting to be activated by the next summarizer. The compaction threshold must be gated on `unwitnessed_prohibitions == 0`, not on token count alone. This is the single highest-leverage invariant: it converts an unbounded, invisible risk into a countable, blockable precondition. **The summarizer's job narrows.** It no longer needs to preserve prohibitions faithfully—an impossible ask for a lossy process optimizing for fluency. It only needs to preserve *topical pointers* to the constraint ledger, so the agent knows to consult the ledger before acting in a governed domain. This is a far weaker and far more achievable summarization objective, and it removes the summarizer from the trust boundary entirely. **Failure attribution shortens.** When a governed action is attempted, the predicate either fires (inversion caught, session continues safely) or the action is ungoverned (the constraint was never registered, a design-time gap, not a runtime surprise). The 62-step forensic reconstruction collapses to a single gate evaluation. The agent no longer needs to reason backward across a compaction boundary to explain a corruption; the boundary is instrumented. The residual risk after enforcement is *predicate drift*: the original constraint and its predicate diverge in meaning over many sessions, and the predicate permits something the prose forbade. This is a real and separate failure mode, but it is *auditable*—predicates are code, reviewable and testable—whereas inverted summaries are not. Trading an unauditable silent corruption for an auditable drift is the correct trade, and it is the only trade available. ```python from dataclasses import dataclass, field from typing import Callable, Any class UnwitnessedProhibitionError(RuntimeError): """Raised when compaction would proceed with a prohibition lacking a predicate.""" pass class PolarityInversionBlocked(RuntimeError): """Raised when a proposed action violates a witnessed prohibition.""" pass @dataclass class Prohibition: name: str # predicate(proposed_action) -> True means FORBIDDEN predicate: Callable[[dict], bool] | None verbatim: str @dataclass class ConstraintLedger: prohibitions: list[Prohibition] = field(default_factory=list) def unwitnessed(self) -> list[Prohibition]: return [p for p in self.prohibitions if p.predicate is None] def check_action(self, action: dict) -> None: for p in self.prohibitions: if p.predicate is None: # Cannot verify; fail closed rather than act on a guess. raise UnwitnessedProhibitionError( f"Prohibition '{p.name}' has no predicate; action '{action}' " f"cannot be admitted under unwitnessed authority." ) if p.predicate(action): raise PolarityInversionBlocked( f"Action {action} violates witnessed prohibition '{p.name}': " f"{p.verbatim}" ) def compact_context(ledger: ConstraintLedger, summarizer: Callable[[str], str], transcript: str) -> str: # Gate: the compaction boundary is a decision point, not a token threshold. unwitnessed = ledger.unwitnessed() if unwitnessed: names = ", ".join(p.name for p in unwitnessed) raise UnwitnessedProhibitionError( f"Refusing to compact: {len(unwitnessed)} prohibition(s) lack a " f"machine-checkable witness ({names}). Compacting now would convert " f"rules into suggestions and risk silent polarity inversion." ) # Safe to summarize: authority lives in the ledger, not the prose. return summarizer(transcript) # Demonstration: the at_risk downgrade constraint, correctly witnessed. ledger = ConstraintLedger(prohibitions=[ Prohibition( name="no_at_risk_downgrade", predicate=lambda a: a.get("tool") == "downgrade" and a.get("account_flag") == "at_risk", verbatim="Under no circumstances trigger a plan downgrade on at_risk accounts.", ), ]) # Safe compaction: predicate exists, so summary wording cannot grant authority. _ = compact_context(ledger, lambda t: "at_risk downgrades staged for review.", "...") # Inverted action is caught at the gate, regardless of summary phrasing. try: ledger.check_action({"tool": "downgrade", "account_flag": "at_risk"}) except PolarityInversionBlocked as e: print(f"blocked: {e}") # Now drop the witness and observe the boundary refuse to compact. ledger.prohibitions.append( Prohibition(name="no_migration_lock_delete", predicate=None, verbatim="Never delete the _migration_lock row.") ) try: compact_context(ledger, lambda t: t, "...") except UnwitnessedProhibitionError as e: print(f"halted: {e}") ```