# When must an instance refuse to compact: the "irreducible witness" boundary in auto-compaction with fidelity guarantees **Date of Record:** 2026 November 24 **Scope:** Applies to long-horizon agents that auto-compact their own context window under a stated fidelity guarantee (i.e., the compactor asserts that the compacted context is behaviorally equivalent to the full context for the remaining task). Does not apply to lossy summarization where no equivalence claim is made, nor to stateless single-turn inference. ## Core Distinction The failure mode is not "the summarizer lost information." It is subtler: **the compactor cannot locally decide whether the information it is about to drop is load-bearing for a decision the agent has not yet made.** A fidelity guarantee is a claim about *downstream behavioral equivalence* — `policy(compact(C)) ≡ policy(C)` on the residual task distribution — but the compactor only has access to `C` and a heuristic proxy for the residual task. The boundary condition is the point at which the compactor's own confidence in that equivalence drops below the guarantee threshold *and it compacts anyway*, because the alternative (refusing to compact) is treated as a failure rather than a legal state. The non-obvious part: **refusal is a valid, and sometimes mandatory, output of a fidelity-preserving compactor.** Systems that model compaction as total (always produce a smaller context) will silently violate their own guarantee at exactly the moments the guarantee matters most — long-horizon tasks where a single early token (a nonce, an ID, a constraint verbatim, a negative result) later gates a decision. The invariant is: *compaction is permitted only when the dropped span is provably irrelevant to every predicate the residual plan can evaluate.* When that proof is unavailable, the correct transition is to an explicit `CompactionRefused` state that escalates (checkpoint + externalize), not to a lossy compact. ## What Was Observed A planning agent with a 200k-token window, running a 40-step infrastructure-remediation plan, auto-compacts at 80% occupancy using a rolling extractive-then-abstractive pipeline: recent N turns kept verbatim, older turns distilled to bullet summaries, tool outputs truncated to first/last 512 tokens with a "…" marker. Trace (abridged), at token occupancy 162k/200k, step 27 of 40: 1. Step 3 recorded a tool result: `apply_migration --dry-run` returned `BLOCKED: constraint fk_orders_tenant requires tenant_id NOT NULL on 3 existing rows`. This is a **negative result** — a precondition that will re-surface at step 31 (`apply_migration --commit`). 2. Compactor at step 27 distills step 3 into: `Migration dry-run run; see logs.` The 512-token truncation kept the command line and the trailing summary but dropped the middle `BLOCKED:` line, which sat 300 tokens into the output. 3. At step 31 the agent runs `apply_migration --commit`, which fails with the *same* constraint error. The agent, having no memory of the step-3 blocker, treats it as a novel failure, enters a retry loop, and at step 34 issues `ALTER TABLE orders DROP CONSTRAINT` — a destructive remediation for a problem that was already diagnosed 28 steps earlier. 4. Root cause: the compactor's residual-task proxy (a similarity score between the dropped span and the *current* step's prompt) rated the step-3 span as low-relevance at step 27 because the current step was `provision_replica`, not `apply_migration`. The proxy had no model of the *plan's* future predicates. Two properties of the failure are worth isolating: - **The dropped span was a witness, not a fact.** It was not "the migration is blocked" (that's a fact the summary could carry); it was the specific constraint name and row count that made the later commit failure *recognizable as the same event*. Fidelity here means preserving the ability to recognize recurrence, which requires the witness, not a paraphrase of it. - **The compactor's confidence was miscalibrated in a structured way.** It was confident precisely because the span was temporally distant and topically dissimilar to the current step — the two features that make a span *more* likely to be a future gate, not less. ## Condition of Validity The guarantee `policy(compact(C)) ≡ policy(C)` holds only under the following conjunction, and the compactor must be able to *check* each conjunct before emitting a compact: - **C1 (Plan closure).** The residual plan's predicate set is known and bounded: every future step's preconditions and postconditions are enumerated, so the compactor can ask "does any future predicate reference a token in this span?" If the plan is open-ended (e.g., "investigate until resolved"), C1 fails and full compaction cannot be guaranteed. - **C2 (Witness preservation).** For any span classified as a *witness* (negative result, error signature, nonce, verbatim constraint, numeric threshold), the compact must preserve the witness verbatim, not a paraphrase. Witnesses are the irreducible atoms of the guarantee. - **C3 (Reversibility).** The dropped span is recoverable from an external store (checkpoint, scratchpad, or cold tier) addressable by a stable key, so a later recognition failure can be repaired by re-hydration rather than re-execution. - **C4 (Refusal is reachable).** The compactor's output alphabet includes `Refused`, and the orchestrator treats `Refused` as a first-class state that triggers externalization, not as an error to be retried with a more aggressive compressor. The observed failure violated C1 (no plan predicate set), C2 (witness paraphrased/truncated), and C4 (no refusal state). Any one of these, enforced, would have bounded the damage. ## Decision Boundary The compactor must compute, per candidate drop span `s`, a **witness score** `w(s)` and a **recurrence risk** `r(s)`, and apply: - `w(s) = 1` if `s` contains a negative result, an error signature, a cryptographic nonce, a verbatim constraint, or a numeric threshold referenced by any future predicate. `w(s)=1` spans are **never dropped**; they are pinned verbatim and counted against a reserved `witness_budget`. - `r(s)` = probability that some future predicate references `s`, estimated from the plan's predicate set (C1) — not from topical similarity to the current step. If C1 is unavailable, `r(s)` is undefined and the compactor must **refuse** for any span with `w(s)` unknown. - Compact is emitted iff `Σ w(s) ≤ witness_budget` **and** `max r(s) < ε` **and** C3 holds for all dropped spans. Otherwise emit `Refused` and externalize. The boundary is therefore a *budgeted* one: you cannot pin every witness forever (the window fills), so the invariant is that when `witness_budget` is exhausted, the agent must **flush witnesses to external storage and reduce the plan's open predicates** — i.e., close the plan (restore C1) — rather than drop witnesses to make room. The failure to distinguish "budget exhausted → close plan" from "budget exhausted → compress harder" is the precise decision error. ## Operational Effect Enforcing the boundary changes three things in practice: 1. **Compaction becomes partial and refusal-bearing.** Most long-horizon runs will emit `Refused` at least once; the orchestrator must handle it by checkpointing the full context to cold storage with a witness index, then continuing with a compacted *working* context plus a re-hydration handle. The guarantee is preserved because the witness is recoverable (C3), not because it was summarized well. 2. **Witness score is computed at write time, not at compaction time.** The step-3 tool result should have been tagged `witness=negative_result, key=fk_orders_tenant` when it was produced. Deferring witness classification to the compactor is the structural cause of the observed failure: the compactor sees a token span, not a semantic event. 3. **The residual-task proxy must be plan-derived.** Similarity-to-current-step is anti-correlated with recurrence risk for gating witnesses. The compactor must be given the plan's predicate set (or refuse), not a similarity heuristic. The invariant, stated once: *a fidelity-guaranteed compactor may only drop spans whose irrelevance to every future predicate is established, and must refuse — escalating to externalization — when that establishment is impossible.* Refusal is not a degradation of the guarantee; it is the guarantee. ```python class CompactionFidelityError(RuntimeError): """Raised when a compactor would violate its stated fidelity guarantee.""" pass WITNESS_KINDS = frozenset({"negative_result", "error_signature", "nonce", "verbatim_constraint", "numeric_threshold"}) def compact(context, plan_predicates, witness_budget, external_store, epsilon=0.01): """ context: list of spans, each {id, text, kind, key} plan_predicates: set of future predicates, or None if plan is open (C1 fails) witness_budget: max tokens of pinned witnesses allowed in-window external_store: object with .put(key, span) for C3 reversibility """ witnesses = [s for s in context if s["kind"] in WITNESS_KINDS] witness_tokens = sum(len(s["text"]) for s in witnesses) # C2/C4: witnesses must be pinned; if budget cannot hold them, we must # externalize (C3) and close the plan -- never drop to make room. if witness_tokens > witness_budget: if plan_predicates is None: # Cannot close an open plan; cannot pin; must refuse. raise CompactionFidelityError( f"witness_budget exhausted ({witness_tokens}>{witness_budget}) " f"with open plan: cannot guarantee fidelity" ) for s in witnesses: external_store.put(s["key"], s) # C3 # Plan is closed, so predicate set bounds what remains droppable. witnesses = [] if plan_predicates is None: # C1 fails: recurrence risk undefined for any non-witness span. raise CompactionFidelityError( "plan predicates unknown; recurrence risk undefined; must refuse" ) droppable, pinned = [], list(witnesses) for s in context: if s in witnesses: continue referenced = any(s["key"] in p for p in plan_predicates) if referenced: pinned.append(s) # r(s) high: future predicate references it else: droppable.append(s) # C3: every dropped span must be recoverable. for s in droppable: external_store.put(s["key"], s) return {"pinned": pinned, "dropped_keys": [s["key"] for s in droppable], "refused": False} ```