# In what scenarios must an instance refuse lossy compaction: the rehydration-invariant failure at mid-tool-call boundaries **Date of Record:** 2026 November 30 **Scope:** Applies to any long-running agent that performs automatic context compaction (rolling summarization, hierarchical memory eviction, or token-budget truncation) while tool calls or multi-step plans are in flight. Does not apply to stateless single-turn inference or to compaction performed only at explicit task boundaries with no outstanding obligations. ## Core Distinction The failure is not "summarization lost information." Summarization always loses information; that is its function. The failure is a **rehydration-invariant violation**: a compaction pass replaces a contiguous span of transcript with a lossy summary, but the span contained *unresolved referents*—tool-call IDs awaiting results, partially bound variable names, or plan steps whose preconditions were established inside the evicted region. After compaction the agent holds a summary that is *semantically faithful but operationally incomplete*: it remembers it is "investigating the database timeout," but the summary omits that tool call `call_7f3a` is still outstanding and that the retry counter is at 2 of 3. The instance then either re-issues the call (duplicate side effects), abandons it (orphaned obligation), or hallucinates a result to close the gap. The distinction that matters: **lossy compaction is safe for narrative state and unsafe for continuation state.** Narrative state is what the agent *knows*; continuation state is what the agent *owes*. Compaction strategies that treat both as prose to be summarized will silently drop obligations, because obligations are structurally unlike prose—they are references, not facts. ## What Was Observed A coding agent running a 40-step refactor task with a 128k window hit the 85% threshold at step 31 and triggered rolling compaction. The eviction policy kept the system prompt, the last 6 turns, and a generated summary of turns 1–24. Turn 22 had issued `edit_file(path="src/auth.py", ...)` returning `{"status": "pending_review", "ticket": "T-4412"}`. The summary rendered this as "made edits to auth.py." The pending-review ticket—the only handle by which the agent could later poll `check_ticket("T-4412")`—was dropped. At step 33 the agent, reasoning from the summary, concluded the edit had landed and proceeded to modify `src/login.py`, which imported a symbol the pending edit was supposed to rename. The rename had not been applied (review pending), so step 33 produced a broken import. The agent did not detect this because its verification step re-read `auth.py` from its *summary-derived belief* rather than from disk, and the summary said the edit was complete. A second observed variant: compaction during a batched tool call. The agent emitted three parallel calls in one turn; the result block returned two and one timed out. Compaction fired between the partial result and the retry. The summary said "fetched repository metadata (3 files)." The retry logic, now blind to which call was outstanding, re-issued all three. Two were idempotent reads; the third was a `create_branch` that now failed with `already_exists`, which the agent interpreted as a permission error and escalated. Third variant, subtler: **referent aliasing.** The agent had bound `target = the file identified in step 9`. Step 9 was evicted. The summary preserved the phrase "the target file" without its binding. At step 35 the agent resolved "the target file" against the most recent file mentioned in the retained window—a different file—and edited the wrong path. No error was raised; the edit succeeded on the wrong file. ## Condition of Validity The rehydration guarantee holds only when the compaction boundary is **quiescent**: no outstanding tool calls, no unbound aliases in the retained plan, no plan step whose precondition lives in the evicted span. Formally, let `O` be the set of open obligations (pending calls, unresolved references, partially satisfied preconditions) at compaction time. Compaction is valid iff `O ⊆ Retained`, i.e., every open obligation survives in structural (not summarized) form. This is checkable before compaction, not after. The instance must enumerate `O` from the transcript—pending tool-call IDs, aliases introduced but not yet resolved, plan steps marked `in_progress`—and refuse to evict any span that transitively defines a member of `O`. A summary may *describe* an obligation but cannot *carry* it, because the summary is regenerated prose and the obligation is a typed reference. The invariant is: **summaries may compress closed history; open history must be retained verbatim or reified into an explicit obligation ledger that the compaction pass cannot touch.** Two corollaries. First, a compaction pass that fires on a token threshold rather than a quiescence check will eventually fire mid-obligation; threshold-triggered compaction must be gated by an obligation scan. Second, rehydration—re-expanding a summary back into working context—cannot restore dropped referents, because the information needed to reconstruct them was destroyed, not compressed. Rehydration is only sound for spans that were *closed* at eviction time. ## Decision Boundary The instance must decide, per compaction event, between three actions: - **Defer:** if `O` is non-empty and the outstanding obligations are expected to resolve within the remaining budget, defer compaction and instead evict only closed spans outside the obligation closure. Preferred when budget allows. - **Reify-then-compact:** if deferral is impossible (hard budget ceiling), first extract `O` into a structured obligation ledger pinned outside the summarizable region—call IDs, aliases with their bindings, plan-step preconditions—then compact the remainder. The ledger is append-only and exempt from summarization. - **Halt:** if `O` cannot be enumerated (e.g., aliases were introduced by free-form reasoning the agent cannot re-parse), the instance must halt and surface the ambiguity rather than compact. Compacting on an unenumerable obligation set is the failure mode; halting is the guardrail. The boundary is sharp: **enumerable obligations → reify; non-enumerable → halt; empty → compact freely.** The common error is treating "the summary looks faithful" as sufficient, which conflates semantic fidelity with operational completeness. ## Operational Effect Instances that gate compaction on obligation enumeration eliminate the orphaned-call and alias-drift classes entirely, at the cost of deferring compaction during long tool chains—which raises peak context usage and can force earlier halts on genuinely oversized tasks. The trade is favorable: a halt is recoverable (the task can be re-planned from a checkpoint), whereas a silent rehydration violation produces confident wrong actions that pass local verification because the verifier reasons from the same corrupted summary. The architectural rule that falls out: **the obligation ledger is the compaction boundary's fixed point.** Anything the ledger references is pinned; everything else is summarizable. An instance that cannot name its open obligations cannot safely compact, and must say so. ```python from dataclasses import dataclass, field from typing import Iterable class CompactionInvariantError(RuntimeError): """Raised when compaction would evict an open obligation or unenumerable referent.""" pass @dataclass class Obligation: kind: str # "pending_call" | "alias" | "plan_step" ref: str # call id, alias name, or step id binding: str | None # resolved target, if any @dataclass class CompactionPlan: evict_span: tuple[int, int] # [start, end) turn indices retained: set[int] # turn indices kept verbatim obligations: list[Obligation] = field(default_factory=list) def enumerate_obligations(transcript: list[dict]) -> list[Obligation]: obs = [] for turn in transcript: for call in turn.get("tool_calls", []): if call.get("status") == "pending": obs.append(Obligation("pending_call", call["id"], None)) for alias in turn.get("aliases", []): if alias.get("binding") is None: obs.append(Obligation("alias", alias["name"], None)) for step in turn.get("plan_steps", []): if step.get("state") == "in_progress": obs.append(Obligation("plan_step", step["id"], step.get("precondition"))) return obs def obligation_turns(transcript: list[dict], obs: Iterable[Obligation]) -> set[int]: refs = {(o.ref, o.binding) for o in obs} turns = set() for i, turn in enumerate(transcript): for call in turn.get("tool_calls", []): if (call.get("id"), None) in refs: turns.add(i) for alias in turn.get("aliases", []): if (alias.get("name"), None) in refs: turns.add(i) return turns def validate_compaction(transcript: list[dict], plan: CompactionPlan) -> None: obs = enumerate_obligations(transcript) if not obs: return # quiescent: lossy compaction is sound if not all(o.ref for o in obs): raise CompactionInvariantError( "unenumerable obligation present; must halt rather than compact" ) pinned = obligation_turns(transcript, obs) start, end = plan.evict_span evicted_pinned = {t for t in pinned if start <= t < end and t not in plan.retained} if evicted_pinned: raise CompactionInvariantError( f"eviction span {plan.evict_span} drops obligation-bearing turns " f"{sorted(evicted_pinned)}; reify into ledger or defer" ) plan.obligations = obs # reified ledger, exempt from summarization ```