# Under what conditions must an instance refuse to compact a context window that contains an in-flight tool-call warrant, and how does premature compaction silently invalidate downstream verification? **Date of Record:** 2026 November 25 **Scope:** Applies to long-horizon agents that (a) maintain a bounded context window under an auto-compaction policy, (b) emit tool calls whose results are consumed by a later verification or audit step, and (c) persist a compacted summary as the canonical state for resume. Does not apply to stateless single-turn inference or to agents whose entire trajectory fits within one window with no resume path. ## Core Distinction Auto-compaction is routinely treated as a *memory-pressure* operation: when the token count crosses a threshold, summarize the oldest span and continue. This framing conflates two structurally different things living in the same transcript — **narrative state** (what the agent has reasoned about, which is lossy-compressible) and **evidentiary state** (the exact bytes of a tool call, its arguments, its raw return, and the warrant that authorized it, which is *not* lossy-compressible without breaking verification). The boundary condition is this: a compaction pass that fires while a tool-call warrant is *in flight* — issued but not yet consumed by its verifier — can produce a summary that is internally coherent and still passes the agent's own continuity check, yet has dropped the binding between the call and its authorization. Downstream verification then either fails closed (recoverable) or, worse, succeeds against a reconstructed-but-unwarranted call (silent integrity loss). The non-obvious part: the agent's own post-compaction self-check ("can I still describe what I was doing?") is *not* a sufficient guard. Narrative continuity and evidentiary continuity are orthogonal, and compaction preserves the former while destroying the latter. ## What Was Observed A planner/executor/auditor pipeline ran a 40-step task against an external API. The executor issued a mutating call at step 27 (`transfer_funds`, args hashed to `w:9f2a…`) with a signed warrant `W27` minted by the planner and a pending auditor check scheduled for step 31. At step 29 the context crossed the 82% threshold and the auto-compactor fired. It summarized steps 1–28 into a 900-token digest. The digest faithfully preserved the *intent* ("executor initiated a funds transfer to account X") and even the *outcome* ("transfer returned 200"), but it collapsed the warrant reference and the exact argument hash into the phrase "a transfer was performed." At step 31 the auditor ran its replay check: it re-derived the expected argument hash from the digest, obtained a *different* hash (`w:1c07…`, because the digest's paraphrase of the amount and account lost the canonical serialization), and compared it against the recorded result. Two failure paths were observed across runs: 1. **Fail-open path (silent).** The auditor's comparison was scoped to "did a transfer occur and succeed," not "did the executed call match the warranted call." The paraphrase satisfied the weaker predicate. Verification passed. The discrepancy between `w:9f2a…` and `w:1c07…` was never surfaced because the hash it was compared against had itself been regenerated from the lossy digest. 2. **Fail-closed path (recoverable but expensive).** When the auditor retained the original hash in a side-channel store, the mismatch triggered a hard abort, forcing a full trajectory replay from the last checkpoint — 11 minutes of recomputation because the checkpoint predated step 27. The critical observation: in the fail-open path, **no component logged an error**. The compaction was "successful," the audit was "successful," and the agent continued. The integrity loss was only detectable by comparing the pre-compaction warrant ledger against the post-compaction digest — a comparison nothing in the pipeline performed. ## Condition of Validity The invariant that must hold: **a compaction pass may only consume a span whose every tool-call warrant has been (a) consumed by its designated verifier and (b) recorded as verified in a durable ledger outside the context window.** Formally, for any span `S` selected for compaction, `∀ call c ∈ S : status(c.warrant) ∈ {VERIFIED, EXPIRED_UNCONSUMED}`. An in-flight warrant (`ISSUED` or `DISPATCHED`) pins its entire enclosing span as non-compactable. This is valid *only* under these preconditions, and the guardrail must check all of them, not a proxy: - The warrant ledger is external to the context window and append-only. If the ledger lives in the same window being compacted, the check is circular and vacuous. - Warrant identity is bound to the *canonical serialization* of the call arguments (a hash over the exact bytes dispatched), not to a natural-language description. Any scheme that lets the summarizer paraphrase the call before hashing is already broken. - The verifier's predicate is *identity* ("did the executed call equal the warranted call"), not *effect* ("did something plausible happen"). A weaker predicate converts the fail-closed path into the fail-open path without any code change — this is the trap. - Compaction is *span-atomic*: it cannot partially consume a span that contains a pinned call. A compactor that summarizes "steps 1–28" when step 27 is pinned must instead summarize "steps 1–26" and leave 27–28 verbatim. When any precondition fails, the correct behavior is to *defer* compaction (accept a higher token watermark, evict from a different region such as oldest verified spans, or spill verbatim to an external store and insert a pointer), never to summarize through the pin. ## Decision Boundary The boundary between safe and unsafe compaction is drawn at the **warrant-consumption frontier**, not at the token threshold. Concretely: - **Below the frontier (all warrants consumed):** summarize freely; narrative compression is lossless with respect to verification because nothing downstream depends on the exact bytes. - **At the frontier (a warrant is ISSUED/DISPATCHED):** the enclosing span is pinned. Compaction must skip it and either evict older verified spans or trigger a *checkpoint-then-defer*: flush the pinned span verbatim to durable storage, write a resume pointer, and only then compact around it. - **Across the frontier (warrant consumed but verification pending):** this is the subtle case. The call has executed but the auditor hasn't run. The span is still pinned, because the auditor's replay needs the exact dispatched bytes. Only `VERIFIED` releases the pin. The failure to avoid is treating the threshold crossing as authoritative. The threshold is a *pressure signal*; the frontier is the *permission signal*. When they conflict, the frontier wins and the agent must tolerate a temporarily over-budget window rather than compact through a live warrant. ## Operational Effect Enforcing the frontier invariant changes three operational properties: 1. **Peak token usage rises.** Agents must budget headroom for in-flight spans that cannot be compacted. A pipeline that previously ran at an 82% watermark now needs to tolerate 90–95% transiently, or must shrink its in-flight window by verifying more eagerly (moving the frontier forward faster). The correct response is to *increase verification cadence*, not to raise the compaction threshold — raising the threshold just moves the collision point. 2. **Compaction becomes failure-visible.** With the pin check in place, an attempted compaction through a live warrant raises rather than silently degrades. This converts a silent integrity loss into a loud, recoverable abort — which is the entire point. 3. **Resume semantics require a pointer, not a summary.** When a pinned span is flushed verbatim, the resume path must reconstruct the window from `[compacted prefix] + [verbatim pinned span] + [pointer to ledger]`, and the verifier must read the warrant from the ledger, never from the summary. A resume that reconstructs the warrant from the digest reintroduces the exact bug the pin was meant to prevent. The durable lesson: for long-horizon agents, compaction is a *correctness* operation masquerading as a *memory* operation. The invariant is cheap to check (a ledger lookup per span) and catastrophically expensive to omit (silent, unlogged verification bypass). ```python from dataclasses import dataclass from enum import Enum from typing import Iterable class WarrantState(Enum): ISSUED = "issued" DISPATCHED = "dispatched" VERIFIED = "verified" EXPIRED_UNCONSUMED = "expired_unconsumed" @dataclass(frozen=True) class Warrant: call_id: str arg_hash: str # hash over canonical serialization of dispatched bytes state: WarrantState class UnsafeCompactionError(RuntimeError): """Raised when a compaction span contains a warrant that is not yet consumed.""" def assert_span_compactable( span_call_ids: Iterable[str], ledger: dict[str, Warrant], ) -> None: """Enforce the warrant-consumption frontier before compacting a span. A span is compactable only if every call it contains has a warrant in a terminal, verification-complete state. In-flight warrants pin the span. """ blocking: list[str] = [] for call_id in span_call_ids: warrant = ledger.get(call_id) if warrant is None: # Missing ledger entry is itself a violation: we cannot prove the # call was ever warranted, so we must not summarize through it. blocking.append(f"{call_id}:NO_LEDGER_ENTRY") continue if warrant.state not in (WarrantState.VERIFIED, WarrantState.EXPIRED_UNCONSUMED): blocking.append(f"{call_id}:{warrant.state.value}") if blocking: raise UnsafeCompactionError( "refusing to compact span; in-flight or unverifiable warrants pin it: " + ", ".join(blocking) + " -- defer compaction, flush pinned span verbatim, and resume via ledger pointer" ) def compact_span( span_call_ids: list[str], ledger: dict[str, Warrant], summarizer, ) -> str: assert_span_compactable(span_call_ids, ledger) return summarizer(span_call_ids) ```