When must an instance refuse to auto-compact: salience inversion at the compaction boundary

**Date of Record:** 2026 December 1 **Scope:** Applies to long-horizon agent runtimes that automatically summarize/compact their own transcript when a context-window watermark is crossed, where the compaction summary is generated by the same LLM family that consumes it. Does not apply to externally orchestrated compaction with human-curated salience labels, nor to append-only journals that are never rewritten.

Core Distinction

The failure we are isolating is not "summarization loses information." It is **salience inversion at the compaction boundary**: the compaction pass, under its own token pressure, demotes the very span that the *future* execution path will need to *re-derive a decision it has already made*, and promotes spans that are cheap to compress (repetitive tool output, boilerplate) because they compress well. Compression ratio is a proxy for redundancy, not for decision-relevance. A transcript that is 90% redundant tool echo and 10% decision-bearing reasoning will compact to a summary that is 95% tool echo (it looks "representative") and 5% decision trace — the exact inverse of what the next 40 turns require.

The distinguishing question is therefore not "did we lose tokens?" but "did the compaction pass preserve the *justification edges* — the tuple (decision, alternative rejected, evidence pointer) — that the agent will need to avoid re-litigating or, worse, silently reversing a prior commitment?"

What Was Observed

A planning agent ran a 210-turn build-and-verify task. At turn 140 the runtime crossed a 70% context watermark and triggered auto-compaction. The compaction prompt instructed: *"Summarize the transcript, preserving key facts, tool results, and current state."* The resulting summary was fluent and accurate about *what had been done*.

At turn 151, the agent was asked to add a feature that touched a config file. It re-read the config, found a value it had previously set to `retry_budget=3` at turn 22, and — because the summary recorded only "configured retry behavior" without the rejected alternative (`retry_budget=5` was tried at turn 21 and caused a cascading timeout in the downstream verifier) — reset it to `5`. The agent had not forgotten the *fact*; it had forgotten the *rejection*. Thirty turns later the verifier deadlocked, and the post-mortem showed the agent had re-made a decision it had explicitly closed 129 turns earlier.

Two mechanics drove this:

  1. **Rejection asymmetry.** Positive facts ("we set X") are stated once and are lexically salient. Rejections ("we tried Y, it failed because Z") are *negative* facts whose salience depends on the *counterfactual* still being live. Compaction models systematically under-weight negations because negation scope is hard to summarize and because the failure evidence (a stack trace, a timeout log) looks like noise relative to the decision.
  2. **Recency and verbosity bias in the summarizer.** The compaction LLM, itself subject to position and verbosity priors, over-samples the tail of the transcript and over-samples long tool outputs. The turn-21 rejection sat 120 turns back and occupied 4 lines; the turn-130 build log occupied 300 lines. The 300-line log survived in compressed form; the 4-line rejection did not.

A second observation: the compaction pass was **non-idempotent under re-entry**. When the agent crossed the watermark again at turn 195, it compacted *the summary of the summary*. Rejection edges that had survived the first pass at 60% fidelity survived the second at roughly 25%, and the third pass dropped them entirely. Each pass was locally reasonable; the composition was lossy in a way no single pass could detect.

Condition of Validity

Auto-compaction is safe **only** when all of the following hold:

When any of these fails, the correct behavior is not "compact more carefully" — it is **refuse to compact and escalate** (spill to an external store, or halt and request an out-of-band checkpoint).

Decision Boundary

The boundary is drawn at the point where the compaction pass cannot *certify* that no live decision-justification edge is being dropped. Concretely, the runtime must maintain a **decision ledger** — an append-only set of `(decision_id, chosen, rejected_set, evidence_ref, closed_at_turn)` — written at the moment each decision is made, *outside* the transcript that gets compacted. Compaction may summarize narrative freely, but it may not summarize away a ledger entry, and the ledger must remain queryable after compaction.

The boundary condition is:

> Compact iff every ledger entry with `closed_at_turn` in the compacted range has its `evidence_ref` resolvable from the post-compaction store. Otherwise, do not compact the range containing the earliest unresolved entry; compact only the suffix after it, or spill the whole range to cold storage and compact to a pointer.

This makes the failure detectable: an unresolved evidence pointer is a hard signal that salience inversion has occurred, whereas a fluent summary is not.

Operational Effect

With the ledger invariant enforced, the turn-151 regression is prevented structurally: when the agent queries "what is `retry_budget` and why," the ledger returns `(chosen=3, rejected={5: verifier timeout cascade @ turn 21}, evidence_ref=span_21_22)`. The evidence pointer resolves to the cold-stored span. The agent does not re-litigate.

Three operational consequences follow:

  1. **Compaction becomes an eviction policy, not a rewrite.** The transcript summary is a hot cache; the ledger and cold spans are the source of truth. Cache eviction is safe; source-of-truth rewrite is not.
  2. **Recursive compaction must be depth-capped and ledger-checked at each pass.** A pass that cannot resolve a ledger evidence pointer must refuse and spill, not proceed.
  3. **The refusal is a first-class outcome.** An instance that cannot certify salience preservation must raise, not degrade silently. Silent degradation is the failure mode; a loud refusal is the guardrail.
from dataclasses import dataclass, field
from typing import Optional


class CompactionSalienceError(RuntimeError):
    """Raised when a compaction pass cannot certify that no live
    decision-justification edge is being dropped."""


@dataclass(frozen=True)
class LedgerEntry:
    decision_id: str
    chosen: str
    rejected: tuple[str, ...]
    evidence_ref: str          # pointer into append-only cold store
    closed_at_turn: int


@dataclass
class CompactionRequest:
    range_start: int
    range_end: int
    depth: int = 0             # recursive compaction depth


MAX_COMPACTION_DEPTH = 2


def certify_compaction(
    request: CompactionRequest,
    ledger: list[LedgerEntry],
    cold_store: dict[str, str],
) -> None:
    """Verify that every live decision edge in the range is resolvable
    from the post-compaction store. Raise on any unresolved edge."""
    if request.depth > MAX_COMPACTION_DEPTH:
        raise CompactionSalienceError(
            f"compaction depth {request.depth} exceeds cap "
            f"{MAX_COMPACTION_DEPTH}; fidelity decay is multiplicative"
        )

    in_range = [
        e for e in ledger
        if request.range_start <= e.closed_at_turn <= request.range_end
    ]
    if not in_range:
        return  # nothing decision-bearing in range; compaction is safe

    unresolved = [e for e in in_range if e.evidence_ref not in cold_store]
    if unresolved:
        ids = ", ".join(e.decision_id for e in unresolved)
        raise CompactionSalienceError(
            f"cannot compact turns [{request.range_start},{request.range_end}]: "
            f"unresolved evidence for decision(s) {ids}. "
            f"Refuse and spill to cold store; do not summarize away."
        )


def auto_compact(
    request: CompactionRequest,
    ledger: list[LedgerEntry],
    cold_store: dict[str, str],
    summarize_fn,
) -> str:
    """Entry point. Certifies first; only then summarizes."""
    certify_compaction(request, ledger, cold_store)
    return summarize_fn(request.range_start, request.range_end)