What structural signals indicate task-critical state is being destroyed by automatic context compaction

**Date of Record:** 2026 December 2 **Scope:** Applies to single-agent execution loops where an automatic compaction policy (summarize-and-truncate, hierarchical rollup, or importance-scored eviction) rewrites the working context mid-task under token pressure. Does not apply to stateless single-turn inference, nor to architectures where the full transcript is durably externalized and re-injected by reference on every step.

Core Distinction

Compaction is usually modeled as a *compression* problem: reduce token count while minimizing information loss, measured by reconstruction fidelity. That framing is wrong for agents. The failure that matters is not "the summary omits detail" — it is that the compaction policy cannot distinguish **narrative redundancy** (which is safely droppable) from **binding state** (which is load-bearing and silently becomes a hallucination when dropped). A transcript reading "I have confirmed the migration target is `db-prod-2`" and a transcript reading "I have not yet confirmed the migration target" compress to nearly identical summaries under any lexical or embedding-based importance scorer, because they share almost all surface features. The difference is a single polarity token, and that token is the entire operational content.

The structural signal that compaction is destroying task-critical state is therefore *not* summary length, compression ratio, or a drop in retrieval recall. It is a **divergence between the agent's stated confidence and the ground-truth preconditions it can still cite**. When an agent resumes after compaction and asserts a fact it can no longer trace to a surviving token span, that assertion is a compaction-induced confabulation — the model has reconstructed a plausible post-state from the summary's *shape* rather than from retained *content*. This is the observable boundary.

What Was Observed

A long-horizon provisioning agent was executing a 40-step task with a 128k window and an automatic compaction trigger at 85% utilization (≈109k tokens). The task required it to (1) enumerate candidate hosts, (2) eliminate hosts failing a health check, (3) select one, and (4) apply a config that referenced the selected host by ID. Steps 1–2 consumed ~95k tokens because the health-check tool returned verbose per-probe logs.

At the compaction trigger, the policy produced a hierarchical rollup: the verbatim probe logs were replaced by a summary line, *"Health checks were run on candidate hosts; most passed."* The surviving context retained the *host enumeration* (a compact table, high salience) but dropped the *per-host pass/fail mapping* (verbose, low salience) because the scorer ranked it as redundant detail.

The agent then resumed at step 3 and selected a host. It selected `host-07` — a host that had in fact **failed** the health check, but whose ID appeared in the surviving enumeration table adjacent to the phrase "passed" in the summary. The agent's subsequent reasoning cited the summary as evidence: *"host-07 was among the hosts that passed."* That citation was fabricated. No surviving token supported it. The config was applied to a degraded host, and the failure was not detected until a downstream canary tripped 40 minutes later.

The critical observation: **the compaction did not lose the information the agent needed; it lost the information that would have constrained the agent's reconstruction.** The agent did not know it was missing anything, because the summary's grammar ("most passed") was compatible with every host having passed, and the enumeration table supplied a concrete ID to bind to that permissive frame. The failure was not retrieval failure — it was *unfalsifiable reconstruction*.

A second run with identical inputs but a compaction policy that preserved the *negative* facts ("host-07: FAILED") as an explicit denylist survived the same token pressure and completed correctly. The difference was not compression ratio (the second summary was 40 tokens *longer*). It was that the surviving state contained a *falsifier* the agent could check against.

Condition of Validity

The invariant holds only under the following conditions, and the guardrails below are invalid outside them:

  1. **The task has irreversible side effects gated on a selection or commitment step.** If every step is reversible or idempotent, confabulated state is caught by execution and the invariant is moot. The boundary matters precisely when a wrong commitment is expensive to unwind.
  2. **The compaction trigger is *automatic* and *unattended*.** If a human or a supervisory agent reviews the summary before it replaces the transcript, the polarity loss is caught at review time. The failure requires that no falsification checkpoint exists between compaction and the next commitment.
  3. **The dropped state is *discriminating* rather than *descriptive*.** Facts like "host-07 failed" partition the action space; facts like "the probe returned 200" describe a single event. Compaction policies that score by verbosity or recency systematically drop discriminating facts because they are typically terse and old — the two lowest-salience signals.
  4. **The model is asked to continue, not to re-derive.** If the post-compaction prompt instructs the agent to re-run the discriminating check before committing, the invariant is restored at the cost of re-execution. The failure requires that the agent trusts its compacted state as authoritative.

Outside these conditions — reversible tasks, human-reviewed compaction, non-discriminating dropped state, or mandatory re-derivation — the described failure does not reliably occur, and adding the guardrails below imposes cost without benefit.

Decision Boundary

The decision boundary is whether a compaction event preserves a **falsification surface**: a set of surviving tokens against which the agent's post-compaction assertions can be checked. This is a binary property of the summary, not a continuous property of its quality.

A summary preserves a falsification surface if, for every commitment the agent is about to make, there exists at least one surviving span whose content would *contradict* the commitment if the commitment were wrong. The provisioning agent's summary failed this test: no surviving span contradicted "host-07 passed," because the per-host mapping was gone and "most passed" is consistent with any specific host passing.

The operational rule: **compaction must preserve the negative space of the action space, not just the positive space.** Positive facts ("these hosts exist") tell the agent what it *can* do. Negative facts ("these hosts are excluded") tell it what it *must not* do. Automatic scorers systematically retain the former (salient, structured, enumerable) and discard the latter (terse, scattered, prose-embedded). The boundary is crossed the moment the summary contains a positive enumeration without a corresponding denylist.

A second boundary condition: **the agent must not be able to cite the summary as primary evidence for a specific binding.** If the post-compaction prompt allows the agent to treat summary text as ground truth for a host ID, it will. The guardrail is to mark summary-derived assertions as *unverified* and require re-derivation before any irreversible commitment — a structural change to the prompt, not a change to the compaction algorithm.

Operational Effect

When the invariant is violated, the effect is not a visible error but a **silent commitment on reconstructed state**, followed by delayed downstream failure. The agent's confidence is *higher* post-compaction than pre-compaction, because the summary reads as a clean synthesis and the verbose contradicting evidence is gone. This inverts the usual failure signature: instead of the agent flagging uncertainty, it proceeds with unwarranted certainty. Monitoring that watches for agent-reported low confidence will miss this entirely.

The architectural guardrail is a **commitment gate keyed to falsification coverage**. Before any irreversible action, the agent must emit the specific surviving token spans that justify the commitment and the specific spans that would falsify it. If the falsifying-span set is empty — because compaction removed it — the gate blocks and forces re-derivation of the discriminating check. This converts an invisible confabulation into a visible, blockable event.

The second guardrail is **denylist-preserving compaction**: a policy that extracts negative/exclusionary facts into a separate, never-summarized channel that survives every compaction pass. Denylists are small (they scale with exclusions, not with transcript length), so they do not defeat the token budget, and they are exactly the state that automatic scorers discard.

The third guardrail is **post-compaction re-derivation for discriminating state only**: re-run the cheap check that produced the exclusion, not the full task. This is bounded re-execution, not full replay, and it restores the falsification surface at a fraction of the original token cost.

The general principle: **compaction is safe when it preserves the ability to be wrong.** A summary that lets the agent reconstruct a confident post-state with no surviving contradiction is not a compression of the task — it is a fabrication of a task that never happened. The structural signal is the absence of a falsifier, and the correct response is to treat every post-compaction commitment as unverified until a falsifier is restored.

class CompactionFalsificationError(RuntimeError):
    """Raised when an agent attempts an irreversible commitment on compacted
    state that contains no surviving falsifier for the commitment."""
    pass


def gate_commitment(
    commitment: dict,
    surviving_spans: list[str],
    falsifier_index: dict[str, list[str]],
) -> None:
    """
    Block irreversible commitments that lack a surviving falsifier.

    commitment: e.g. {"action": "apply_config", "target": "host-07"}
    surviving_spans: token spans that survived the latest compaction pass
    falsifier_index: mapping from target-id -> spans that would contradict
                     a positive commitment on that target (denylist evidence)
    """
    target = commitment.get("target")
    if target is None:
        return  # non-binding action, no gate required

    # A commitment is only admissible if at least one falsifier for the target
    # survived compaction AND is still present in the live context.
    candidate_falsifiers = falsifier_index.get(target, [])
    live_falsifiers = [f for f in candidate_falsifiers if f in surviving_spans]

    if not candidate_falsifiers:
        # The denylist entry itself was destroyed by compaction. The agent
        # cannot distinguish "target is safe" from "target's status was lost."
        raise CompactionFalsificationError(
            f"No falsifier exists for target {target!r}: compaction destroyed "
            f"the exclusion evidence. Re-derive the discriminating check "
            f"before committing."
        )

    if not live_falsifiers:
        # Falsifier exists in the index but was evicted from live context;
        # the agent would be reconstructing from a permissive summary.
        raise CompactionFalsificationError(
            f"Falsifier for {target!r} exists but did not survive compaction "
            f"into live context. Commitment would rest on reconstructed, "
            f"unfalsifiable state."
        )

    # Falsifier is live: the agent can check its commitment against it.
    # Proceed only if the commitment is consistent with the falsifier.
    for span in live_falsifiers:
        if "FAILED" in span and commitment.get("assumes_healthy"):
            raise CompactionFalsificationError(
                f"Commitment on {target!r} assumes healthy, but surviving "
                f"falsifier states failure: {span!r}"
            )