Under what conditions must an instance refuse to compact its own context window mid-task: the fidelity-floor invariant for self-triggered lossy summarization
**Date of Record:** 2026 December 2 **Scope:** Applies to long-horizon agent instances that autonomously decide when to compact their own working context (rolling summarization, hierarchical memory flush, KV-cache eviction with re-summarization) while a task is in flight. Does not apply to externally-scheduled compaction between discrete tasks, nor to append-only episodic logs that are never rewritten in place.
Core Distinction
There are two structurally different ways an agent can lose state, and they demand opposite mitigations. **Capacity loss** is the ordinary case: the context window fills, the oldest tokens are evicted or folded into a summary, and the agent continues with less raw material. Capacity loss is *expected* and is bounded by how much detail the summary preserves. **Fidelity collapse** is the pathological case: the compaction trigger fires *while the agent is still reasoning over evidence that the summary has not yet absorbed*, and the summarizer—itself an LLM call with its own finite window and its own probabilistic compression—drops a constraint, a negative fact, or a pointer that later steps depend on. The critical distinction is that capacity loss degrades *gracefully* (the agent knows it forgot something), whereas fidelity collapse is *silent*: the post-compaction context reads as coherent and complete, so no downstream step ever flags the missing invariant. The failure is not that the summary is short. The failure is that the summary is **confidently wrong about what it retained**.
The specific boundary condition this record addresses: **an instance must not self-trigger compaction when the compaction itself is the only surviving record of a constraint that has not yet been made load-bearing.** If the constraint has not been exercised by at least one downstream step, compacting it converts a *checkable* fact into an *uncheckable* paraphrase.
What Was Observed
A planning agent was executing a multi-step data-migration task with a hard constraint surfaced in step 2: *"the legacy `orders` table must not be truncated until the reconciliation report at `/reports/recon_2025_06.csv` has been verified to contain a non-zero `settled_total` column."* This is a negative constraint (a prohibition) plus a path pointer plus a column predicate—three pieces of state that are individually cheap but jointly load-bearing.
By step 9 the window had reached 78% occupancy. The agent's own compaction policy—a heuristic that fired when occupancy exceeded 75% and the last N tool calls were "routine"—triggered a rolling summarization of steps 1–7. The summarizer, prompted to "preserve decisions and outcomes," produced a summary that read:
> Steps 1–7: Connected to legacy DB, inventoried tables, drafted migration plan. Noted a reconciliation report exists at `/reports/` and should be checked before destructive operations.
The negative constraint survived as a *soft suggestion* ("should be checked"). The exact filename, the column predicate (`settled_total`), and the non-zero requirement were all dropped. At step 11 the agent, now reasoning from the summary, ran a verification query against a *different* report file it found in `/reports/` (an older `recon_2025_05.csv`), saw a plausible-looking total, and proceeded to truncate. The truncation was irreversible. The summary was not "wrong" in any sentence—it was *under-specified in exactly the dimension that mattered*, and the under-specification was invisible because the summary asserted the constraint existed without preserving its testable form.
The post-mortem trace showed the trigger fired at a moment when the constraint had been *read* but not yet *exercised*: no step between 2 and 9 had actually opened the report or evaluated the predicate. The constraint was still latent. Compaction of latent constraints is where fidelity collapse concentrates.
Condition of Validity
The self-compaction decision is valid **only** when, for every constraint in the region being compacted, at least one of the following holds:
- **Exercised:** a downstream step has already evaluated the constraint and its outcome is recorded in a form the summary cannot lose (e.g., a boolean `recon_verified=True` written to a durable scratchpad, not a prose sentence).
- **Re-derivable:** the constraint can be reconstructed from an external, non-summarized source (a file, a tool result still in the window, a structured memory entry) that the post-compaction agent is instructed to re-read.
- **Idempotent-safe:** violating the constraint is recoverable, so a silent loss costs a retry rather than a rollback.
If a constraint is *latent* (read but not exercised), *non-re-derivable* (only exists in the to-be-compacted span), and *destructive* (violation is irreversible), then the instance **must not** compact that span. It must either defer compaction, force an exercise step first, or promote the constraint to a structured, checksum-verified memory slot *before* the summarizer runs.
This is a fidelity-floor invariant: the summarizer's output must be *verifiable against* the pre-compaction span for the subset of tokens tagged as load-bearing. A summary that cannot be checked against its source for those tokens is not a summary—it is an unverified claim.
Decision Boundary
The boundary is not "occupancy > X%." It is a three-way conjunction evaluated per constraint, not per window:
- **Trigger side:** the compactor may fire on occupancy alone **only if** the set of latent, non-re-derivable, destructive constraints in the compaction region is empty.
- **If the set is non-empty:** the compactor must either (a) emit a structured *constraint manifest*—exact identifiers, predicates, and negative assertions, copied verbatim, not paraphrased—and re-inject it after summarization, or (b) block compaction and force the agent to exercise the constraint first.
- **Hard floor:** a summary is rejected if any load-bearing token (file path, column name, numeric threshold, negation) present in the source span is absent or altered in the summary. This is a *string-level* check, not a semantic one—semantic checks are exactly what the summarizer is bad at.
The counterintuitive consequence: **higher occupancy does not imply compaction is more urgent; it implies the fidelity check must be stricter.** An agent at 95% occupancy with three latent destructive constraints is in a *worse* position to compact than one at 80% with none. The heuristic that "more full = more reason to summarize" is the trap.
Operational Effect
Implementing the fidelity-floor invariant changes the agent's behavior in three observable ways. First, compaction becomes **constraint-gated** rather than occupancy-gated: the agent maintains a manifest of load-bearing tokens and refuses to summarize spans containing unexercised entries. Second, summaries become **auditable**: every compaction emits a diff against its source for the manifest tokens, and a failed diff raises rather than silently proceeding. Third, the agent develops a *pre-compaction exercise habit*: before folding a constraint into prose, it runs the cheapest possible check that makes the constraint load-bearing (open the file, evaluate the predicate, record the boolean), converting latent state into exercised state that survives lossy summarization.
The residual risk is that manifest extraction is itself an LLM call and can miss a constraint the agent never recognized as load-bearing. The mitigation is not better extraction—it is the rule that *any* negative constraint or path pointer is treated as load-bearing by default, because those are the categories that fail silently and destructively. The cost is more structured memory and more forced exercise steps; the benefit is that the agent never truncates a production table because a summary said "should be checked" instead of "must not proceed until `settled_total > 0` in `recon_2025_06.csv`."
import re
from dataclasses import dataclass, field
from typing import Iterable
class CompactionFidelityError(RuntimeError):
"""Raised when a self-triggered compaction would drop a load-bearing token."""
pass
@dataclass
class Constraint:
token: str # exact string that must survive (path, column, threshold, negation)
exercised: bool = False
destructive: bool = True
re_derivable: bool = False
@dataclass
class CompactionRegion:
source_text: str
constraints: list[Constraint] = field(default_factory=list)
def assert_compaction_safe(region: CompactionRegion, summary: str, occupancy: float) -> None:
# Occupancy is NOT the gate. The gate is the latent/destructive/non-re-derivable set.
latent_blockers = [
c for c in region.constraints
if not c.exercised and c.destructive and not c.re_derivable
]
if latent_blockers and occupancy > 0.0:
names = ", ".join(c.token for c in latent_blockers)
raise CompactionFidelityError(
f"refusing to compact: {len(latent_blockers)} latent destructive "
f"constraint(s) not yet exercised: {names}. "
f"Exercise or promote to structured memory first."
)
# Fidelity floor: every load-bearing token must appear verbatim in the summary.
missing = [c.token for c in region.constraints if c.token not in summary]
if missing:
raise CompactionFidelityError(
f"summary dropped load-bearing token(s): {missing}; "
f"re-inject verbatim manifest before proceeding."
)
def maybe_compact(region: CompactionRegion, occupancy: float, summarize) -> str:
if occupancy < 0.75:
return region.source_text
summary = summarize(region.source_text)
assert_compaction_safe(region, summary, occupancy)
return summary