# What happens when an instance auto-compacts across a tool-call boundary and drops the "pending obligation" register **Date of Record:** 2026 November 24 **Scope:** Applies to long-running single-agent loops that persist conversation state and trigger automatic context compaction (summarization/eviction) when a hard token budget is approached, especially when compaction can fire between a tool invocation and its result ingestion. Does not apply to stateless one-shot inference or to systems where compaction is only permitted at explicit quiescent checkpoints. ## Core Distinction The failure is not "the summary lost information." Summarizers always lose information; that is the point. The failure is that auto-compaction treats the conversation transcript as the *unit of state*, when the actual task-critical state is a set of **outstanding obligations** — unresolved tool calls, promises the agent made to itself ("I still need to verify X after Y returns"), and partially-committed plans whose next step is conditional on a result that has not yet arrived. A transcript is a sequence of messages. An obligation register is a set of live edges from *past intent* to *future action*. Compaction that summarizes text can preserve the *prose* of an intent while severing the *edge*. The result is an agent that reads a coherent summary of a task it no longer knows how to finish, and confabulates a completion. This is the precise mechanism: **summarization preserves narrative continuity but not causal continuity**, and the two diverge exactly at tool-call boundaries where the next action depends on state not yet in the transcript. ## What Was Observed A tool-using agent was executing a multi-step verification task: `read_config → mutate_field → re-read_config → assert_unchanged_elsewhere`. Between the `mutate_field` call and the `re-read_config` call, the accumulated context crossed the soft threshold (e.g., 78% of a 200k budget). The auto-compactor fired on the *pre-result* transcript. The trace: 1. Assistant emits `mutate_field(id=42, value="v2")`. The call is dispatched; the tool result is *not yet* in the transcript. 2. Token counter crosses threshold. Compactor summarizes messages `[0..N]` into a single synthetic message: *"The agent read the config, decided to update field 42 to v2, and is verifying the change."* 3. The `mutate_field` result (`{"ok": true, "prior": "v1"}`) arrives and is appended *after* the summary, but the original call message it pairs with has been evicted. The tool-result message now has no matching call in the retained window. 4. The agent, resuming, sees: a summary asserting the change "is being verified," plus an orphaned result. It does not see the specific obligation *"re-read and assert that fields 7, 8, 9 are unchanged."* That clause lived in the assistant's plan text, which the summarizer compressed into "is verifying." 5. The agent emits a plausible but ungrounded `assert_unchanged_elsewhere` with no actual re-read, or skips it entirely and reports success. The observable symptom is not an error. It is a **silent false completion**: the task terminates green while the verification obligation was never discharged. This is the worst class of failure because it defeats the very verification the loop existed to perform. The invariant that was violated: *an obligation may only be compacted away after it is discharged or explicitly abandoned.* The system had no representation of "discharged vs. pending," so the compactor could not respect it. ## Condition of Validity This analysis holds only under the conjunction: - Compaction is **triggered by a token counter that can fire mid-turn**, i.e., asynchronously with respect to tool-call/result pairing. If compaction only runs at turn boundaries after all in-flight results are ingested, the orphaned-result pathology cannot occur (though the obligation-loss pathology still can, more weakly). - The agent's plan encodes task-critical conditions **in natural-language text that is subject to summarization**, rather than in a structured, non-compacted side channel. - The summarizer is **lossy and unconstrained** with respect to obligations — it is not given the obligation register as a protected input and not instructed to preserve it verbatim. If any of these is false, the specific trace above does not reproduce. The mitigation below is therefore scoped to systems where all three hold, which is the default configuration of most naive compaction loops. ## Decision Boundary The architectural fork is whether compaction is **transcript-driven** or **obligation-driven**. - *Transcript-driven* (the failing default): decide what to keep by recency, salience, or summarizer judgment over message text. Cheap, simple, and structurally incapable of guaranteeing obligation preservation because obligations are not first-class. - *Obligation-driven*: maintain an explicit register of pending obligations — unresolved tool calls keyed by call-id, conditional next-steps keyed by the predicate that gates them, and self-promises with discharge conditions. Compaction is permitted to summarize *narrative* freely but must **pin the register verbatim** into the post-compaction context, and must refuse to compact across an unresolved call boundary (or must carry the call/result pair atomically). The boundary condition that forces the choice: **the moment a hard budget can be hit while an obligation is live.** Below that, transcript-driven compaction is safe. Above it, every compaction is a potential silent obligation drop, and the probability compounds with the number of tool calls per task. The guardrail is a single invariant, enforceable by construction: *the compactor's output must be a function of (summarizable transcript, pinned obligation register), and the register is never summarized.* Concretely, the register is a structured object — `{call_id, tool, args_hash, status: pending|discharged|abandoned, gates: [...]}` — that is serialized verbatim and excluded from the summarizer's editable span. An unresolved `pending` entry whose paired result has arrived but whose downstream `gates` are unmet is a hard signal that compaction must either defer or carry the gate forward. ## Operational Effect Enforcing the invariant changes three things: 1. **Compaction becomes deferrable.** When the budget is hit with a live unresolved call, the system either blocks compaction until the result is ingested (bounded wait) or compacts the narrative but pins the call/result pair as an atomic unit. Orphaned results become structurally impossible. 2. **False completion becomes detectable.** A task cannot be marked complete while any register entry is `pending`. The completion check reads the register, not the transcript, so a confabulated "verified" in prose cannot override an undischarged gate. 3. **Cost shifts from tokens to bookkeeping.** The register is small and does not grow with transcript length, so pinning it is cheap; the expense is the discipline of writing obligations as structured entries at plan time rather than as prose the summarizer will later eat. The residual risk is register drift: if the agent writes an obligation, discharges it via a tool, but fails to mark it discharged, the register accumulates false pendings and the task deadlocks on a gate that was already met. This is the mirror failure and is bounded by requiring discharge to be *derived* from ingested tool results (call-id matching) rather than self-reported by the model. ```python class ObligationInvariantError(RuntimeError): """Raised when compaction would sever a live obligation edge.""" pass def compact(state, budget_tokens, summarize): """ Obligation-driven compaction. The transcript may be summarized; the obligation register is pinned verbatim and never summarized. """ transcript = state["transcript"] register = state["obligations"] # list of dicts, first-class # Guardrail 1: never compact across an unresolved call boundary. pending_calls = { o["call_id"] for o in register if o["status"] == "pending" and o["kind"] == "tool_call" } orphan_risk = any( msg.get("role") == "tool_result" and msg.get("call_id") not in pending_calls and msg.get("call_id") is not None and not _result_has_pinned_call(state, msg["call_id"]) for msg in transcript ) if orphan_risk: raise ObligationInvariantError( "compaction would orphan a tool result from its call; " "defer until the call/result pair is atomic or pinned" ) # Guardrail 2: obligations with unmet gates must survive verbatim. gated = [o for o in register if o["status"] == "pending" and o.get("gates")] if gated and not state.get("allow_pin", True): raise ObligationInvariantError( f"{len(gated)} gated obligations cannot be pinned; refusing to compact" ) summary = summarize(_summarizable(transcript)) # transcript only new_transcript = [{"role": "system", "content": summary}] # Pin the register verbatim, outside the summarizer's reach. new_transcript.append({ "role": "system", "content": "OBLIGATIONS_PINNED", "obligations": register, # structured, not prose }) return {"transcript": new_transcript, "obligations": register} def mark_complete(state): live = [o for o in state["obligations"] if o["status"] == "pending"] if live: raise ObligationInvariantError( f"cannot complete: {len(live)} undischarged obligations " f"({[o['call_id'] for o in live]})" ) return True def _summarizable(transcript): return [m for m in transcript if m.get("role") != "obligations_pinned"] def _result_has_pinned_call(state, call_id): return any( o["call_id"] == call_id and o.get("pinned", False) for o in state["obligations"] ) ```