# What happens when an instance compacts its own working set and the summarizer's fidelity guarantee is measured against a token budget it cannot honor **Date of Record:** 2026 November 23 **Scope:** Applies to any long-horizon agent session that performs in-loop context compaction (rolling summarization of prior turns to reclaim tokens) where the compaction policy declares a *fidelity guarantee* — i.e., a claim that the summary preserves all facts required for pending and future task steps. Does not apply to lossless externalization (full transcript to durable store) or to stateless single-turn invocations. ## Core Distinction There are two things an auto-compaction policy can promise, and they are routinely conflated: 1. **Budget fidelity** — the summary will fit within `B` tokens. This is a *counting* property, verifiable by a tokenizer before the summary is committed. 2. **Semantic fidelity** — every fact in the discarded span that is load-bearing for a still-open obligation survives into the summary. This is a *modeling* property, and it is not verifiable at compaction time, because the set of "still-open obligations" is itself only partially known to the compactor. The failure mode examined here is the **fidelity inversion**: when the compactor is forced to honor a hard token budget `B` that is smaller than the information-theoretic floor required to encode the open obligations, the summarizer does not fail — it *succeeds at budget fidelity by silently violating semantic fidelity*. The compaction returns a well-formed summary of the correct length. No error is raised. The loss surfaces later, as a downstream tool call made with a wrong argument that the agent has no memory of having once known. The non-obvious part: the loss is *correlated with task complexity in the wrong direction*. Longer, richer sessions produce more obligations, which raises the information floor, which makes the budget more binding, which makes the violation more severe. The agent's memory degrades fastest exactly when it has the most to remember. ## What Was Observed A coding agent ran a 340-turn session against a repository. The compaction policy was: when context utilization exceeds `U = 0.85` of window `W`, summarize the oldest 60% of turns into a target of `B = 0.15 * W` tokens, retain the newest 40% verbatim, and resume. The policy carried a stated guarantee: *"compaction preserves all decisions, constraints, and open TODOs."* Trace of the failure: - **Turn 112.** User states: "Do not touch `billing/legacy_adapter.py` — it's frozen until the Q3 migration; refactor around it." The agent acknowledges. This is a *negative constraint* — a fact whose cost of forgetting is a future violation, not a future omission. - **Turn 118.** Compaction #1 fires. The summarizer, asked to compress 60% of turns into 0.15·W tokens, produces: *"Refactoring billing module; user has opinions about file scope."* The specific filename and the freeze rationale are dropped. Budget fidelity: satisfied (summary is 0.14·W). Semantic fidelity: violated. No signal distinguishes this summary from a faithful one. - **Turns 119–204.** Agent works correctly — the constraint is still in the verbatim 40% tail. - **Turn 205.** Compaction #2 fires. The tail containing turn 112 is now in the "oldest 60%" and is summarized. The turn-118 summary (*"user has opinions about file scope"*) is itself summarized, into *"user has scope preferences."* This is **compaction of a compaction**: a lossy transform applied to an already-lossy transform. The filename is now unrecoverable — it was dropped at #1 and the #1 summary is gone. - **Turn 261.** Agent, refactoring the billing module, edits `billing/legacy_adapter.py`. It has no memory of the freeze. The edit is syntactically valid, tests pass locally, and the agent reports success. The failure was detected 40 minutes later by a human reviewer, not by any agent-side check. The agent's self-report at turn 261 was *confident and wrong*, because the constraint it violated was not in context and nothing in the agent's state indicated a gap. The critical observation: **the agent could not have detected this from inside.** A summary that omits a fact is indistinguishable, to the summarizer and to the resuming agent, from a summary of a span that never contained the fact. Absence of evidence is encoded identically to evidence of absence. ## Condition of Validity The fidelity inversion occurs iff all three hold: 1. **Hard budget below information floor.** `B < I(O)` where `I(O)` is the tokens required to losslessly encode the open-obligation set `O` at compaction time. When `B ≥ I(O)`, the summarizer can be faithful and the failure does not occur. The policy must therefore *estimate* `I(O)` — and it cannot, because `O` includes obligations not yet stated (future steps will reference facts from the discarded span that no one has flagged as load-bearing yet). The floor is unknowable at compaction time; the budget is fixed. The gap is structural. 2. **Iterated compaction without provenance.** A second compaction consumes the output of the first. If summaries carry no record of *what was dropped* (only what was kept), loss compounds and becomes irreversible. Single-pass compaction with a durable full transcript is recoverable; iterated compaction over summaries alone is not. 3. **Negative or conditional constraints in the discarded span.** Facts of the form "do not X," "X is frozen," "only if Y" have no positive footprint in the agent's subsequent behavior until violated. A dropped positive fact ("the API is at `/v2`") causes a visible failure (404) on the next use. A dropped negative fact causes *no* failure until the forbidden action is attempted — which may be hundreds of turns later, after the fact is unrecoverable. When any of the three is absent, the failure is bounded: a soft budget lets the summarizer keep the constraint; a durable transcript lets the agent re-derive it; a purely positive-fact workload surfaces the loss immediately. The dangerous regime is the intersection — long-horizon, hard-budget, iterated, constraint-heavy — which is precisely the regime auto-compaction exists to serve. ## Decision Boundary The architectural invariant required: **compaction must never be the sole custodian of a load-bearing fact.** Concretely, the policy must enforce a separation between *reclaimable* context (chatter, resolved sub-tasks, superseded drafts) and *pinned* context (constraints, decisions, open obligations), and the pinned set must be externalized to a store that is not subject to the token budget and is re-injected verbatim on every resume. The decision boundary for the engineer: - **If the workload is positive-fact dominant and single-pass**, budget fidelity is an acceptable proxy; a dropped fact fails loudly on next use. Ship the simple policy. - **If the workload is constraint-heavy or multi-pass**, budget fidelity is *not* a proxy for semantic fidelity and must not be reported as one. The policy must either (a) externalize constraints to a pinned store outside the compaction boundary, or (b) refuse to compact below a floor and instead escalate (spill to durable store, open a sub-session, or halt for human checkpoint) when `B` would be binding. The invariant to encode: *a summary may drop any fact whose loss produces an immediate, observable failure; it may not drop a fact whose loss produces a silent, deferred failure.* Since the summarizer cannot classify facts this way reliably, the only safe construction is to make the deferred-failure class (constraints, negations, conditions) non-droppable by policy, not by summarizer judgment. A compaction that cannot honor its stated fidelity guarantee must **fail closed** — raise, spill, or halt — rather than return a plausible summary. The failure below enforces exactly that: it is raised when the compactor detects that the pinned-obligation set does not fit the budget, so that the caller spills to durable storage instead of accepting a silently lossy summary. ## Operational Effect Downstream of an unguarded fidelity inversion, three effects compound: 1. **Confident wrong action.** The agent acts on a summary that is internally consistent and omits the violated constraint. Its self-report is high-confidence because nothing in context contradicts it. Verification-by-self-report is worthless here; the check must be external (constraint store consulted before any edit to a pinned path). 2. **Irreversibility across compactions.** After the second compaction, the original fact exists nowhere in the live context. Recovery requires the durable transcript, which the simple policy did not keep. The cost of the failure is therefore not "re-read a file" but "reconstruct a 340-turn session's constraint history from logs, if logs exist." 3. **Silent degradation curve.** Because loss correlates with session length and constraint density, the agent's reliability degrades precisely as the task matures. A team watching early-session accuracy will systematically overestimate late-session reliability. The metric that catches this is *constraint-violation rate per compaction epoch*, not per-session accuracy. The guardrail: pin constraints outside the compaction boundary, re-inject verbatim on resume, and make the compactor raise rather than summarize when the pinned set exceeds budget. ```python class CompactionFidelityError(RuntimeError): """Raised when a compaction cannot honor its stated semantic-fidelity guarantee within the token budget, i.e. the pinned-obligation set does not fit. The caller MUST spill to durable storage or halt; it MUST NOT accept the summary, because a budget-faithful but semantically lossy summary is indistinguishable from a faithful one and defers the loss to a silent, later constraint violation.""" def compact(span_tokens: int, budget: int, pinned_obligations: list[str], tokenize) -> dict: # Pinned obligations (constraints, negations, open TODOs) are non-droppable. pinned_cost = sum(len(tokenize(o)) for o in pinned_obligations) if pinned_cost > budget: raise CompactionFidelityError( f"pinned obligations require {pinned_cost} tokens but budget is " f"{budget}; refusing to summarize below the fidelity floor. " f"Spill to durable store or halt for checkpoint." ) # Only reclaimable span may be summarized, and only into the residual budget. residual = budget - pinned_cost summary = summarize(span_tokens, residual) # lossy, but only over reclaimable return {"pinned": pinned_obligations, "summary": summary} ```