What structural signals indicate auto-compaction summarization has silently destroyed a load-bearing invariant in the working set

**Date of Record:** 2026 December 2 **Scope:** Applies to long-horizon agent loops that reclaim context via LLM-generated summarization of prior turns (auto-compaction, rolling summary, "compact-and-continue"). Does not apply to fixed-window truncation without summarization, nor to externalized memory stores read back by retrieval.

Core Distinction

Truncation loses tokens; compaction loses *structure*. When an agent hits a context-window ceiling and invokes a summarizer to replace turn history with a shorter paraphrase, the summarizer optimizes for topical fidelity — "what was discussed" — not for the operational invariants the loop depends on: exact identifiers, negative constraints, ordering dependencies, and unresolved obligations. The failure is not that information disappears; it is that information *survives in a form that satisfies the summarizer's compression objective while failing the executor's precondition checks*. The summary reads correct to a human reviewer and to the next-turn LLM, but the machine-checkable contract the loop relied on (a pinned hash, an "until X" guard, a tool-call ID that must round-trip) is now a lossy paraphrase. Compaction is a semantic transform that is silently also a schema transform, and nothing in the trigger path validates the second one.

What Was Observed

A file-migration agent ran a 40-step task across three compaction cycles. At step 11 it recorded the constraint "do not touch `prod/` until `migration_plan_v3` is signed off by `auditor-7`." The compaction at step 14 summarized this as "avoid production until migration plan approved." Two invariants were destroyed and neither raised an error:

  1. The version pin `v3` collapsed to "migration plan," so at step 22 the agent accepted a `v2` sign-off as satisfying the guard.
  2. The approver identity `auditor-7` collapsed to "approved," so the agent accepted a self-attestation from its own planner sub-agent.

Both substitutions are *topically faithful* and *operationally fatal*. The trigger fired on a token-count threshold (`context_used >= 0.82 * window`), which is a signal about *volume*, not about *what is load-bearing*. The summarizer had no channel to distinguish a decorative status update from a constraint that gates future tool calls, because both are just tokens in the transcript. The failure surfaced only at step 31 when a write to `prod/` succeeded against a `v2` plan — a downstream symptom three compaction cycles removed from its cause.

The diagnostic signal that was available but ignored: the pre-compaction transcript contained *imperative-with-identifier* spans (constraints binding a specific token to a specific action), and the post-compaction summary contained the same imperatives with the identifiers stripped. A structural diff of "named entities appearing in a constraint clause" before vs. after would have flagged both losses. The agent had no such diff because compaction was treated as a lossy-but-acceptable text transform rather than a state transition requiring an invariant check.

Condition of Validity

The guardrail below is valid only when the following hold; outside them it provides false assurance:

If load-bearing state cannot be externalized to exact form, the correct response is to *refuse compaction* and escalate (checkpoint-and-resume with a fresh window), not to compact and hope the paraphrase is faithful. Compaction is only safe for spans whose loss is provably harmless; the trigger must therefore be gated on a classification, not on a token count.

Decision Boundary

The boundary is between two trigger conditions that look identical at the token counter:

The non-obvious part: the token-count trigger cannot tell these apart, and the summarizer *will not* preserve the distinction on its own because preserving exact identifiers is *anti-compressive* — it directly opposes the objective the summarizer was invoked to satisfy. Any design that relies on the summarizer "being careful" has placed the invariant in the one component incentivized to violate it. The invariant must live outside the summarizer, in a pre-compaction extractor whose output is re-injected and whose round-trip is verified.

Operational Effect

With the structured-extraction gate in place, three things change. First, compaction can no longer silently downgrade a `v3`-pinned, `auditor-7`-bound constraint to an unpinned "approved," because the pinned tuple is re-injected from a store the summarizer never touches, and the executor checks proposed actions against it. Second, the failure mode becomes *loud*: if the extractor cannot produce a checkable tuple for a span it classified as binding, it raises rather than compacting — converting a silent three-cycle-latent corruption into an immediate, localized error. Third, the trigger condition moves from "context is 82% full" to "context is 82% full *and* all binding spans have been extracted and round-trip-verified" — a conjunction that can legitimately fail closed.

The residual risk is misclassification at extraction time: a span tagged non-binding that was actually binding. This is bounded, not eliminated, by requiring the extractor to err toward binding (over-extraction is cheap; under-extraction is the failure) and by replaying the post-compaction action set against the extracted tuples before execution. The invariant to hold: *no action may reference a pinned identifier whose value is not present verbatim in the post-compaction state.* If that check cannot pass, compaction did not succeed regardless of how small the context became.

from dataclasses import dataclass, field
from typing import Iterable


class CompactionInvariantError(RuntimeError):
    """Raised when compaction would drop or paraphrase a binding obligation."""


@dataclass(frozen=True)
class BindingObligation:
    predicate: str          # e.g. "do_not_touch_until_signed_off"
    pinned_identifier: str  # e.g. "migration_plan_v3"
    scope: str              # e.g. "prod/"
    approver: str           # e.g. "auditor-7"


@dataclass
class CompactionResult:
    summary_text: str
    re_injected: list[BindingObligation] = field(default_factory=list)


def extract_binding_obligations(spans: Iterable[str]) -> list[BindingObligation]:
    # In production this is a classifier + parser; here it is a stub that
    # demonstrates the contract: binding spans MUST yield exact tuples.
    obligations: list[BindingObligation] = []
    for span in spans:
        if "until" in span and "signed off" in span:
            # A real extractor parses identifiers; if it cannot, it must raise.
            raise CompactionInvariantError(
                f"binding span could not be reduced to exact tuple: {span!r}"
            )
    return obligations


def compact(
    spans: list[str],
    summarize,
    proposed_actions: list[dict],
) -> CompactionResult:
    obligations = extract_binding_obligations(spans)
    summary = summarize(spans)

    # Invariant: every action referencing a pinned identifier must find that
    # exact identifier verbatim in the post-compaction state.
    pinned = {o.pinned_identifier for o in obligations}
    approvers = {o.approver for o in obligations}
    state_blob = summary + "\n" + "\n".join(
        f"{o.predicate} {o.pinned_identifier} in {o.scope} by {o.approver}"
        for o in obligations
    )
    for action in proposed_actions:
        ref = action.get("references_identifier")
        if ref in pinned and ref not in state_blob:
            raise CompactionInvariantError(
                f"action references pinned identifier {ref!r} absent from "
                f"post-compaction state; compaction destroyed a binding obligation"
            )
        approver = action.get("attested_by")
        if approver and approver not in approvers:
            raise CompactionInvariantError(
                f"action attested by {approver!r} which is not a pinned approver "
                f"{approvers}; summary-level 'approved' is not sufficient"
            )

    return CompactionResult(summary_text=summary, re_injected=obligations)