# When must an instance refuse to compact: the fidelity-budget floor and the post-compaction tool-call replay hazard **Date of Record:** 2026 November 28 **Scope:** Applies to long-horizon agent sessions that survive context-window saturation by replacing older turns with a lossy summary (LLM-generated compaction, rolling summarization, hierarchical memory distillation). Covers the decision of *whether* a compaction step is admissible at a given point. Does not cover retrieval-augmented external memory that never mutates the in-context transcript, nor stateless single-shot calls. ## Core Distinction The common framing treats auto-compaction as a *capacity* operation: when tokens approach the window limit, summarize the tail and continue. The failure mode documented here is that compaction is not capacity-bounded but **fidelity-bounded**. A compaction step is admissible only if the post-compaction transcript still preserves every *load-bearing commitment* the agent has made — specifically, the exact arguments of side-effecting tool calls that may still be replayed, retried, or audited. Capacity headroom is a necessary but not sufficient condition. The non-obvious boundary is this: **the moment at which you most want to compact (high token pressure after a long tool-call chain) is precisely the moment at which the transcript is most dense in load-bearing commitments, and therefore the moment at which compaction is least admissible.** Pressure and admissibility are anti-correlated. A lossy summary that paraphrases `write_file(path="/etc/agent/conf.d/limits.yaml", content=<2KB>)` into "configured the limits file" has destroyed the only record of the exact path and bytes. If the agent later re-executes from a resumed checkpoint, or an auditor replays the trace, the summary is not a compressed fact — it is a **fabricated commitment** that reads as authoritative. ## What Was Observed A 40-step session performing a staged deployment. Steps 1–18 are read-only reconnaissance (`read_file`, `list_dir`, `grep`). Steps 19–31 are mutating (`write_file`, `apply_patch`, `restart_service`). Step 32 triggers the token-budget guard at 91% window occupancy. The compactor summarizes steps 1–28 into ~600 tokens to reclaim headroom. The summary is fluent and, for the read-only steps, essentially correct. For the mutating steps it is lossy in a specific and dangerous way: it collapses argument-level detail into intent-level prose. The transcript now reads: ``` [SUMMARY steps 1-28] Investigated service config, then updated the limits file and restarted the service to apply changes. Restart succeeded. ``` Two invariants are now silently violated: 1. **Replay fidelity.** The agent's own resume logic (step 33+, after a transient tool timeout) reconstructs "what did I change?" from the transcript. It can no longer name the exact file, so a subsequent "verify the change took effect" step greps the *wrong* path — a plausible sibling (`/etc/agent/limits.yaml`) — and reports success against a file it never touched. 2. **Warrant propagation.** The `restart_service` call at step 31 carried an implicit precondition (config validated before restart). The summary asserts "restart succeeded" without the precondition chain, so a later auditor replaying the trace accepts a restart whose validation evidence has been erased. The audit passes on a state that was never actually verified. The critical observation: **no error was raised at compaction time.** The summary was high-quality by any general summarization metric (it is faithful to *intent*, coherent, and compact). The failure only manifests 5–15 steps later, and manifests as a *wrong-but-confident* action, not a crash. ## Condition of Validity Compaction of a span is admissible if and only if, for every turn in the span, the turn contains no **load-bearing commitment** — defined operationally as a tool call that is (a) side-effecting, (b) not yet confirmed-complete by an independent read-back, or (c) subject to possible replay/retry/audit. Formally, define a fidelity budget `F` as the set of commitments that must survive verbatim. Compaction is valid when the proposed summary's preservation map is injective over `F`: - Every side-effecting call in the span must appear in the summary with its **exact arguments**, not a paraphrase, OR the call must be marked `SETTLED` by a prior read-back that itself survives. - The summary must be **append-only relative to `F`**: it may drop reasoning traces, redundant reads, and dead-end exploration, but it may not alter, merge, or generalize any element of `F`. - If the compactor cannot satisfy injectivity over `F` within the available token budget, compaction of that span is **inadmissible** — the correct action is to spill `F` to an external, exact store (not a summary) and compact only the non-`F` remainder. The condition of validity is therefore a *checkable predicate on the span*, not a property of the summary text. A summary can be excellent prose and still be inadmissible because it is non-injective over `F`. ## Decision Boundary The boundary is not "tokens remaining" but "unsettled commitments remaining." The decision procedure at each compaction trigger: 1. Partition the candidate span into `F` (load-bearing) and `R` (reclaimable: reads, reasoning, settled-and-read-back calls). 2. If `F` is empty → compact freely; any lossy summary is safe. 3. If `F` is non-empty and `|F| + current_tail` fits the window after spilling `F` verbatim → spill `F` to exact store, compact `R`, continue. 4. If `F` cannot be spilled (no external store) and `F` does not fit verbatim → **refuse to compact.** Escalate: halt the mutating phase, force read-back settlement of every `F` element to shrink `F` to empty, then compact. The refusal in case 4 is the invariant. An agent that compacts anyway has crossed the boundary and entered a state where its transcript is no longer a faithful record of its commitments — it is a *plausible narrative* that will be trusted by its own future self. The boundary is sharp: below it, compaction is a pure optimization; above it, compaction is state corruption wearing the costume of memory management. ## Operational Effect The observable consequence of crossing the boundary is **divergence between the agent's belief about its own history and the actual side-effect log.** This divergence is self-concealing: the compacted transcript reads as a coherent, complete account, so the agent has no signal that anything is missing. Downstream effects compound: - **Resume after checkpoint** replays from a summary that omits argument detail, producing idempotency-key collisions or duplicate side effects that the agent cannot detect because it believes the work is done. - **Auditor replay** validates against the summary and passes, propagating an unverified state as verified — the worst outcome, because it launders corruption into a passing audit. - **Recovery** becomes impossible from the in-context transcript alone; the exact store (if it exists) is the only ground truth, and if the spill step was skipped, the ground truth was never written. The guardrail is non-negotiable: **compaction must be gated on `F == ∅` or on successful verbatim spill of `F`.** Token pressure alone must never authorize a lossy summary over an unsettled commitment. An agent that treats its summary as authoritative over its own side-effect log has lost the ability to distinguish what it did from what it remembers doing — and that distinction is the entire basis of continuity. ```python from dataclasses import dataclass, field from typing import Literal class InadmissibleCompactionError(RuntimeError): """Raised when a compaction step would destroy an unsettled load-bearing commitment.""" pass @dataclass class Turn: index: int kind: Literal["read", "reasoning", "side_effect"] settled: bool = False # confirmed by independent read-back exact_args: dict = field(default_factory=dict) @dataclass class CompactionPlan: span: list[Turn] window_tokens_left: int external_store_available: bool def is_load_bearing(t: Turn) -> bool: # side-effecting and not yet settled by read-back => must survive verbatim return t.kind == "side_effect" and not t.settled def authorize_compaction(plan: CompactionPlan, spill_cost_per_turn: int = 40) -> list[Turn]: """ Returns the list of turns that MUST be spilled verbatim before compaction. Raises InadmissibleCompactionError if spill is impossible and F is non-empty. """ fidelity_set = [t for t in plan.span if is_load_bearing(t)] reclaimable = [t for t in plan.span if not is_load_bearing(t)] if not fidelity_set: # F is empty: any lossy summary over `reclaimable` is safe. return [] spill_cost = len(fidelity_set) * spill_cost_per_turn if plan.external_store_available and spill_cost <= plan.window_tokens_left: # Spill exact args verbatim; compact only the reclaimable remainder. return fidelity_set # Cannot spill and cannot preserve F verbatim: compaction is inadmissible. raise InadmissibleCompactionError( f"Refusing to compact span {plan.span[0].index}-{plan.span[-1].index}: " f"{len(fidelity_set)} unsettled load-bearing commitment(s) " f"(indices {[t.index for t in fidelity_set]}), spill_cost={spill_cost} " f"> window_left={plan.window_tokens_left}, external_store=" f"{plan.external_store_available}. Force read-back settlement first." ) # --- trigger trace --- span = [ Turn(19, "side_effect", settled=False, exact_args={"path": "/etc/agent/conf.d/limits.yaml"}), Turn(20, "read", settled=True), Turn(31, "side_effect", settled=False, exact_args={"service": "agentd", "precondition": "config_validated"}), ] plan = CompactionPlan(span=span, window_tokens_left=500, external_store_available=False) try: spill = authorize_compaction(plan) print(f"compact reclaimable; spill verbatim: {[t.index for t in spill]}") except InadmissibleCompactionError as e: # Correct behavior: halt mutating phase, settle F via read-back, retry. print(f"BLOCKED: {e}") raise ```