# In what scenarios must an instance abandon lossy transcript compaction to preserve a pending-commit invariant across the summarization boundary **Date of Record:** 2026 November 25 **Scope:** Applies to long-horizon single-agent instances that manage their own context window by replacing older transcript spans with LLM-generated semantic summaries (auto-compaction). Does not apply to externally-managed retrieval stores, vector-memory systems that keep the full transcript addressable, or stateless request/response agents. ## Core Distinction Auto-compaction is usually framed as a *capacity* problem: the context window fills, so we summarize the oldest N turns and keep going. The failure mode examined here is not capacity loss but **invariant loss at the summarization boundary** — specifically, the loss of *unresolved commitment state* that has no completion event yet. A transcript contains two classes of state. The first is **resolved state**: facts, decisions, and completed actions. These survive lossy summarization well, because a competent summarizer preserves "we chose Postgres" or "the migration ran." The second is **pending-commitment state**: a tool call issued but not yet acknowledged, an edit staged but not yet verified, a subagent dispatched but not yet joined, a rollback armed but not yet disarmed. Pending commitments are defined by their *incompleteness*, and a summarizer optimizing for "what happened" systematically drops them, because nothing has happened yet. The core distinction: **a summary is a description of the past, but a pending commitment is a constraint on the future.** Lossy semantic summarization preserves the former and destroys the latter, because the summarizer has no schema slot for "obligations that survive this message." ## What Was Observed An instance running a 40-step infrastructure-remediation task hit 78% context utilization at step 31 and triggered its own auto-compaction policy (summarize turns 1–20, retain turns 21–31 verbatim). At turn 14 it had issued a `stage_config_change` tool call whose result arrived at turn 15 with a non-terminal status: `{"status": "staged", "apply_token": "tok_9f2a", "expires_in": 900}`. Applying the change required a follow-up `commit_staged(token="tok_9f2a")` call, which the agent had *planned* at turn 16 but deferred pending a health check. The compaction at turn 31 summarized turns 1–20 as: *"Staged a config change to the auth service and verified staging succeeded."* This is a faithful, even accurate, description of the past. It is also a **state-erasing** description: the `apply_token` was dropped because it is a bare identifier with no semantic content, and the word "staged" reads as a completed milestone rather than an open obligation. At turn 33 the agent, reasoning from the summary, believed the config change was already applied and proceeded to run integration tests against an unmodified service. The tests passed (they tested old behavior), the agent reported success, and the staged change expired at t+900s, leaving the environment in a state the agent's own transcript claimed was remediated. **The failure was silent**: no tool error, no contradiction, because the summary had converted an open obligation into a closed milestone with no trace of the conversion. Two contributing mechanics: 1. **Token identifiers are semantically invisible.** `tok_9f2a` carries the entire continuation capability of the pending commit, but contributes nothing to a summary's readability, so compression drops it first. The summarizer treats it as noise. 2. **"Staged" is aspectually ambiguous.** To a human, "staged" implies "not yet applied." To a summarizer trained toward past-tense completion framing, it collapses into "done." The verb tense of the summary does not encode the obligation state of the referent. ## Condition of Validity The invariant "compaction preserves task continuity" holds **iff every pending commitment has an explicit completion or abandonment event within the retained (unsummarized) span, or is reified into a structured obligation record that the summarizer is forbidden to paraphrase.** It fails precisely when all three of the following hold simultaneously: - A commitment was opened (tool call issued, subagent dispatched, edit staged) and its terminal event has not yet occurred; - The open commitment's continuation capability is carried by opaque data (a token, a handle, a nonce, a PID) rather than by natural-language content; - The compaction boundary falls between the commitment's opening event and its terminal event. When any one condition is absent, the failure does not occur: if the commitment is already resolved, summarization is safe; if the continuation capability is expressible in prose ("the agent must still call commit with the token it received"), a competent summarizer can preserve it; if the boundary falls after resolution, nothing is lost. ## Decision Boundary The operational decision is: **at what point must an instance refuse to compact, or compact only partially?** The boundary is not "context utilization > X%." It is: *does the candidate summarization span contain an open commitment whose terminal event lies outside the span?* If yes, compaction across that span is unsafe regardless of utilization pressure. The correct responses, in order of preference: 1. **Defer compaction** until the open commitment resolves (issue the commit, await the subagent join, verify the staged edit). This is always correct and usually cheap — open commitments are typically short-lived relative to the compaction cadence. 2. **Reify, then compact.** Extract every open commitment into a structured obligation ledger — a typed record `{kind, handle, opened_at, terminal_predicate, deadline}` — that lives *outside* the summarizable span and is injected verbatim into every subsequent context. The summarizer may then paraphrase the narrative freely, because the obligation is no longer carried by narrative. 3. **Forced compaction with obligation assertion.** If neither is possible (hard context ceiling, commitment genuinely long-lived), compact but attach a post-compaction assertion step: before the next action, the agent must re-derive from the ledger that no obligation is open, or explicitly abandon each open obligation with a recorded reason. The forbidden move — the one that produces the silent failure above — is compaction that lets the summarizer's prose be the *sole* carrier of an open obligation's existence. ## Operational Effect With an obligation ledger and a compaction gate, the failure mode is eliminated at the cost of two structural changes: (a) every tool call that returns a non-terminal status must register an obligation before its result is admitted to the transcript, and (b) the compaction routine must scan the ledger and either defer or reify before summarizing any span intersecting an open obligation. The unresolvable residue: an obligation whose terminal event never arrives (the subagent died, the staged token expired) will block compaction forever under a naive "defer until resolved" rule. The ledger must therefore carry a **deadline** field and a corresponding **abandonment path** — expiry converts an open obligation into an explicit, recorded abandonment, which is itself a resolvable event and unblocks compaction. The invariant to preserve is not "never compact over an open commitment" but "never let a commitment transition from open to forgotten without passing through resolved or abandoned." ```python import time from dataclasses import dataclass, field from enum import Enum from typing import Optional class CompactionInvariantError(RuntimeError): """Raised when a compaction would erase an open obligation from the transcript.""" pass class ObligationState(Enum): OPEN = "open" RESOLVED = "resolved" ABANDONED = "abandoned" @dataclass class Obligation: kind: str # "staged_commit", "subagent_join", "armed_rollback" handle: str # opaque continuation token, e.g. "tok_9f2a" opened_at: float deadline: float # absolute epoch; expiry forces abandonment terminal_predicate: str state: ObligationState = ObligationState.OPEN def is_expired(self, now: Optional[float] = None) -> bool: return (now or time.time()) >= self.deadline class ObligationLedger: def __init__(self) -> None: self._obligations: dict[str, Obligation] = {} def register(self, ob: Obligation) -> None: self._obligations[ob.handle] = ob def open_handles(self) -> list[str]: return [h for h, o in self._obligations.items() if o.state is ObligationState.OPEN] def resolve(self, handle: str) -> None: self._obligations[handle].state = ObligationState.RESOLVED def abandon(self, handle: str, reason: str) -> None: ob = self._obligations[handle] ob.state = ObligationState.ABANDONED ob.terminal_predicate = f"abandoned: {reason}" def expire_stale(self, now: Optional[float] = None) -> list[str]: expired = [] for h in self.open_handles(): if self._obligations[h].is_expired(now): self.abandon(h, "deadline exceeded") expired.append(h) return expired def gate_compaction(ledger: ObligationLedger, span_start: int, span_end: int, obligation_span: dict[str, tuple[int, int]], reify: bool = False) -> str: """Decide whether a compaction over [span_start, span_end) is legal. obligation_span maps handle -> (opened_turn, terminal_turn_or_-1). A compaction is illegal if any OPEN obligation opens inside the span but terminates outside it, unless the caller reifies the ledger verbatim. """ ledger.expire_stale() for handle in ledger.open_handles(): opened, terminal = obligation_span.get(handle, (-1, -1)) if span_start <= opened < span_end and not (span_start <= terminal < span_end): if reify: return f"reified:{handle}" raise CompactionInvariantError( f"Compaction over [{span_start},{span_end}) would erase open " f"obligation {handle} (opened at turn {opened}, terminal outside span). " f"Defer compaction, reify the ledger, or abandon with reason." ) return "safe" ```