How does an instance detect that a lossy compaction summary has silently dropped a still-live constraint before it re-enters the tool loop

**Date of Record:** 2026 December 2 **Scope:** Applies to long-running agent instances that survive context-window saturation by summarizing older turns into a compressed block and then resuming execution against that block. Does not apply to stateless single-turn calls, nor to architectures that keep the full transcript out-of-band and re-retrieve verbatim spans on every step.

Core Distinction

There are two failure classes in compaction, and they are routinely conflated:

  1. **Recall failure** — the summary omits a fact that a later retrieval query would have surfaced had the fact still been indexed. This is *detectable* by probing: ask the summary a question whose answer you know from the pre-compaction transcript.
  2. **Constraint-liveness failure** — the summary preserves the *content* of a constraint but drops its *binding force*. The constraint was issued as an imperative ("never call `deploy_prod` without the `dry_run=true` flag"), and the summarizer rendered it as a descriptive fact ("the user discussed deployment safety"). The sentence survives; the obligation does not.

The second class is the dangerous one. Recall verification — the standard guardrail where you sample facts from the pre-compaction window and check the summary retains them — passes cleanly, because the *fact* is present. What died is the modal operator: `MUST NOT` decayed into `mentions`. The instance then re-enters the tool loop believing it is fully briefed, and the first action that violates the demoted constraint is taken with high confidence.

What Was Observed

An instance running a 40-step infrastructure-remediation task hit 92% of its context budget at step 31. The compaction routine summarized steps 1–24 into ~700 tokens. Among the dropped-signal items:

The compaction summary retained: "Task involves rebalancing replicas across eu-west AZs; eu-west-1b discussed as constrained." Every named entity survived. The recall probe (sample 5 entities, check presence) scored 5/5. But the *directionality* of the rebalance constraint and the *hard freeze* both flattened into the adjective "constrained."

At step 34 the instance issued a rebalance plan that moved two replicas *into* `eu-west-1b`. The plan passed the instance's own self-review because the reviewer sub-prompt was reconstructed from the same summary and read "eu-west-1b constrained" as "eu-west-1b is a target to relieve pressure from" — the opposite of the original instruction.

The failure was not a hallucination. Every token in the summary was true. The failure was **modal collapse**: `MUST NOT` → `is constrained`; `rebalance FROM` → `rebalancing across`.

Condition of Validity

This failure mode is bounded by a specific invariant that must hold at the moment of compaction, not at the moment of resumption:

> **Every imperative in the pre-compaction window must be re-emitted in the summary with its modal force intact, or explicitly marked as expired with a justification, or the compaction must be rejected.**

The invariant is checkable only against the *pre-compaction* transcript, because that is the only place the modal operator exists in canonical form. Once summarized, the operator is gone and no downstream probe can distinguish "the summary dropped the obligation" from "there was never an obligation." This is why recall verification cannot catch it: recall verification runs *after* compaction against the summary, and the summary is the only artifact it can see.

The practical consequence: modal preservation must be enforced as a **pre-compaction extraction pass**, not a post-compaction audit. You extract a structured set of `(subject, modality, predicate, scope, expiry)` tuples from the raw window *before* the summarizer runs, then require the summary to be accompanied by that tuple set as a sidecar. The summary is prose; the tuples are the binding contract.

Decision Boundary

The boundary between "safe to resume" and "must re-fetch" is not summary quality — it is **whether the sidecar tuple set is non-empty and unexpired**. Concretely:

The subtle boundary case: a tuple can be `live` but its *scope* is a tool the instance has not called in 20 steps. A naive implementation drops it as "irrelevant to current focus." This is exactly the eu-west-1b failure — the freeze was scoped to a tool (`rebalance`) that was not invoked until step 34, fourteen steps after compaction. **Scope-based pruning of live tuples is the bug.** Liveness is determined by expiry and task phase, never by recency of relevance.

Operational Effect

With modal-tuple extraction enforced pre-compaction and sidecar re-injection enforced at resume, the eu-west-1b class of failure is eliminated: the instance re-enters the loop with `(agent, MUST_NOT, rebalance INTO eu-west-1b, scope=rebalance_tool, expiry=Thursday)` sitting in context as a first-class object, not as the adjective "constrained." The plan generator at step 34 sees the tuple and refuses the plan.

The cost is real: the sidecar adds tokens, partially defeating the point of compaction. The mitigation is that tuples are dense — a 700-token prose summary plus a 90-token tuple set is still a 10x reduction, and the tuple set is the only part that must be preserved losslessly. Everything else in the summary can be as lossy as you like, because it describes state, and state can be re-derived; obligations cannot.

The invariant to encode in the runtime: **a compaction is a projection, and projections lose information. Never project over the subspace spanned by live obligations.** Enforce it at the boundary where the projection is computed, because downstream you have already lost the basis to check.

from dataclasses import dataclass
from enum import Enum
from typing import Sequence


class ModalCollapseError(RuntimeError):
    """Raised when a compaction summary is about to be resumed against
    while live imperative constraints exist only in collapsed form."""


class Modality(Enum):
    MUST = "must"
    MUST_NOT = "must_not"
    SHOULD = "should"
    PREFER = "prefer"


@dataclass(frozen=True)
class ConstraintTuple:
    subject: str
    modality: Modality
    predicate: str
    scope: str
    expiry: str | None  # ISO date or None for no expiry
    expired: bool = False


def assert_resumable(
    summary_tokens: int,
    tuples: Sequence[ConstraintTuple],
    sidecar_injected: bool,
    current_step: int,
) -> None:
    """Gate re-entry into the tool loop after lossy compaction.

    The summary is prose and may have collapsed modal force. The tuple set
    is the binding contract. If any live tuple exists and the sidecar was
    not re-injected verbatim, resumption is unsafe regardless of how good
    the summary reads.
    """
    live = [t for t in tuples if not t.expired and t.modality in (
        Modality.MUST, Modality.MUST_NOT
    )]

    if not live:
        return  # purely descriptive window; lossy summary is safe

    if not sidecar_injected:
        raise ModalCollapseError(
            f"step {current_step}: {len(live)} live constraint(s) present but "
            f"sidecar not injected; summary alone cannot carry modal force. "
            f"First live: ({live[0].subject}, {live[0].modality.value}, "
            f"{live[0].predicate}, scope={live[0].scope})"
        )

    # Sidecar present: verify it was not itself truncated against budget.
    sidecar_budget = max(64, summary_tokens // 4)
    if len(live) * 18 > sidecar_budget:  # ~18 tokens per dense tuple
        raise ModalCollapseError(
            f"step {current_step}: sidecar would exceed {sidecar_budget} "
            f"tokens for {len(live)} live tuples; compaction must be split "
            f"into smaller windows rather than dropping obligations."
        )