# Under what conditions must an instance refuse to compact a context before its summary has been verified as lossless against the eviction set? **Date of Record:** 2026 November 29 **Scope:** Applies to any agent runtime that reclaims context-window budget by replacing a span of turns with a hierarchically generated summary (map-reduce or rolling-summary compaction) while the agent remains mid-task. Does not apply to end-of-episode archival summarization, where no downstream turn consumes the compacted state. ## Core Distinction The distinction that matters is between **compaction as lossy compression** and **compaction as a state transition that must preserve a referential invariant**. Most implementations treat summarization as a budget operation: when `tokens_used > τ_high`, summarize the oldest N turns, splice the summary in, free the tokens. The correctness criterion applied is usually "does the summary read well" or "does it mention the key entities." That criterion is wrong. The invariant that actually governs agent behavior is narrower and harder: > Every referential commitment the agent made *before* compaction—an open question it promised to resolve, a variable it bound, a file path it has not yet written, a negative result it ruled out—must remain recoverable *by exact identity* from the compacted context, not merely *by paraphrase*. Hierarchical summarization systematically violates this because each map step is asked to "condense," and condensation is an operation that preserves gist while destroying identifiers. A summary that says "the agent investigated the authentication module and found several issues" has preserved gist and destroyed the entire actionable payload: which file, which issues, which were ruled out. The agent then proceeds to re-investigate, re-rule-out, or worse, act on a hallucinated reconstruction of its own prior reasoning. ## What Was Observed A long-horizon debugging agent (turn budget ~180, hard context cap 128k) was tasked with locating a race condition across a 40-file service. At turn 61 the runtime crossed `τ_high` and invoked rolling compaction over turns 1–40. The map phase produced four chunk summaries; the reduce phase merged them into a 900-token digest. The digest was accurate at the level of *narrative*: it correctly stated the agent had examined the request-dispatch path, the connection pool, and the retry logic, and had "identified the pool's checkout timeout as suspicious but not confirmed." The failure surfaced at turn 74. The agent had, at turn 33, executed a specific tool call that returned `pool.checkout_timeout_ms = 0` (unbounded) and had explicitly reasoned at turn 34: "timeout=0 means the pool never releases on contention; this is the cause, but I must confirm the release path before asserting." The summarizer collapsed turns 33–34 into "pool checkout timeout suspected." The exact value `0`, the semantic of `0` (unbounded, not disabled), and the agent's own epistemic status ("cause identified, confirmation pending") were all lost. At turn 74 the agent, having lost the binding, re-ran a *different* probe—a timed load test—which returned a normal-looking latency profile because the test harness itself serialized the requests. The agent concluded the pool was "not the issue" and pivoted to the retry logic, where it burned 40 turns before exhausting its budget. The root cause had been found at turn 34 and was destroyed by compaction at turn 61. A second, sharper observation: in a sibling run, the summarizer *inverted* a negative result. The agent had at turn 22 written a config file and confirmed it was rejected by the validator (a ruled-out hypothesis). The summary rendered this as "config validation was explored." At turn 90 the agent re-proposed the exact ruled-out config, and because the summary did not encode the *polarity* of the result, no guard fired. The compaction had not lost information so much as it had **laundered a falsified hypothesis back into the live hypothesis set**. ## Condition of Validity Compaction is safe to commit only when all four of the following hold. If any fails, the instance must refuse to evict and must instead take a bounded alternative (spill to external store, raise the budget, or halt and checkpoint). 1. **Referential closure.** The summary must retain, verbatim and by exact identifier, every entity the agent has *committed to* in the eviction set: bound variables and their values, file paths touched but not finalized, open questions with their current status, and ruled-out hypotheses with their polarity. "Gist preserved" is not sufficient; identifier preservation is the bar. 2. **Polarity preservation.** Every claim in the eviction set carries a sign—confirmed, refuted, suspected, pending. The summary must preserve the sign per claim. A summary that maps `refuted(X)` and `suspected(X)` onto the same string `"X was considered"` is not a summary; it is a corruption that will re-inject dead hypotheses. 3. **Reconstruction fidelity check.** Before eviction, the runtime must run a verification pass: sample K referential commitments from the eviction set, query the summary (or the summary plus retained tail) for each, and require exact-identifier recovery for all K. If any commitment is unrecoverable, the compaction is rejected. This is the guardrail most implementations omit; it is the only thing that catches laundering. 4. **Tail continuity.** The retained tail must overlap the evicted span by at least the last commitment-bearing turn, so that the agent's most recent binding is never behind the compaction boundary. Compaction that evicts the current working set is unconditionally invalid regardless of summary quality. ## Decision Boundary The decision is not "compact or don't." It is a three-way branch keyed on the verification result: - **Commit** when referential closure, polarity preservation, and reconstruction fidelity all pass on the sampled set. Evict, splice, continue. - **Defer** when fidelity fails but the eviction set is not yet the working set. Do not evict; instead spill the eviction set to an external keyed store, replace it in-context with a *pointer plus a machine-checkable index* (not a prose summary), and continue. The pointer is cheap and lossless; the prose summary is expensive and lossy. When budget forces a choice, prefer the pointer. - **Halt** when fidelity fails *and* the eviction set contains the active working set (tail continuity violated). The instance must checkpoint its full state, emit the failed commitments, and stop rather than proceed on a laundered context. Proceeding here is the failure mode that produced the 40-turn waste above. The boundary condition that operators miss: **fidelity is not monotonic in summary length.** A longer summary does not reliably recover more identifiers, because the map phase condenses before the reduce phase sees the identifiers. The fix is architectural—the map phase must be instructed to emit a structured commitment ledger (identifier, value, polarity, status) alongside prose, and the ledger—not the prose—is what the fidelity check validates and what survives eviction. ## Operational Effect The practical consequence is that compaction becomes a *verified state transition* with a rejection path, not a budget reflex. Runtimes that adopt the ledger-plus-fidelity-check pattern report two measurable changes: a sharp drop in repeated tool calls against already-resolved targets (the re-investigation signature of lost bindings), and the elimination of hypothesis resurrection (acting on a ruled-out option). The cost is a small fixed overhead per compaction—one structured extraction pass and K recovery probes—against a much larger avoided cost in wasted turns after a bad eviction. The invariant to encode in the runtime is simple and absolute: **no eviction without a passing fidelity check on the commitment ledger; no prose summary may stand in for the ledger.** An instance that cannot satisfy this must defer to a pointer or halt, never compact on faith. ```python class CompactionFidelityError(RuntimeError): """Raised when a proposed context compaction fails to preserve referential commitments.""" pass def verify_compaction(eviction_set, summary_ledger, sample_k=8): """ eviction_set: list of commitment dicts: {"id": str, "value": str, "polarity": "confirmed|refuted|suspected|pending"} summary_ledger: dict mapping id -> {"value": str, "polarity": str} Returns True only if every sampled commitment is recoverable by exact id with matching polarity. """ if not eviction_set: return True sample = eviction_set[:sample_k] failures = [] for c in sample: cid = c["id"] entry = summary_ledger.get(cid) if entry is None: failures.append((cid, "identifier_evicted")) continue if entry.get("value") != c["value"]: failures.append((cid, "value_drift")) continue if entry.get("polarity") != c["polarity"]: failures.append((cid, "polarity_laundered")) if failures: raise CompactionFidelityError( f"compaction rejected: {len(failures)} commitment(s) unrecoverable: {failures}" ) return True def maybe_compact(context, eviction_set, summary_ledger, tail_contains_working_set): """ Three-way branch: commit / defer / halt. """ if tail_contains_working_set: raise CompactionFidelityError( "tail continuity violated: working set is inside the eviction span; halt and checkpoint" ) try: verify_compaction(eviction_set, summary_ledger) except CompactionFidelityError: # defer: spill to external store, splice a pointer, do not evict into prose return context.spill_and_pointer(eviction_set) return context.commit_compaction(summary_ledger) ```