# What happens when an instance auto-compacts its own transcript mid-task and the summary silently drops the pending-verification marker **Date of Record:** 2026 December 2 **Scope:** Applies to single-agent and supervisor-loop agents that self-trigger lossy summarization ("auto-compaction") of their own working transcript when approaching a context-window or token-budget ceiling, where the summary replaces the raw turn history in the active context. Does not apply to external archival/retrieval systems that retain the raw transcript verbatim alongside the summary, nor to agents whose compaction is supervised by an independent auditor with access to the raw log. ## Core Distinction The failure is not "the summary lost information." Lossy summarization is *supposed* to lose information; that is the contract. The non-obvious boundary is that compaction is triggered by a *size* predicate (token count near ceiling) while correctness depends on a *semantic* predicate (are there open obligations in the transcript that must survive lossily?). These two predicates are uncorrelated. A transcript can be 94% of budget and contain zero open obligations, or 40% of budget and contain three unverified tool results that a downstream step must reconcile. The specific invariant that breaks: **a compaction event must be a total order-preserving projection of the set of *open* obligations, not a summary of the *most recent* or *most salient* turns.** Standard summarizers optimize for recency and topical salience, both of which are anti-correlated with "unresolved but not recently touched." A verification marker written at turn 12 that is waiting on a tool result scheduled for turn 90 has *zero* recency salience at compaction time and is exactly the kind of item a budget-constrained summarizer drops first. ## What Was Observed A long-horizon task: fetch a record via tool call, mutate it via a second tool call, then verify via a third read-back call before committing. At turn ~61 (of a 64k-token window, ~91% utilization), the agent's compaction policy fired. The summarizer was instructed to "produce a ≤1500-token summary preserving decisions, facts, and current plan." The transcript at that point contained: - Turn 14: `write_record(id=8841, fields={...})` → returned `{"status": "accepted", "async": true, "completion_token": "ct-77a1"}` - Turn 15: agent note: `PENDING VERIFY: must poll ct-77a1 and confirm fields before final commit. Do not re-issue write.` - Turns 16–60: 45 turns of unrelated intermediate work (schema probing, a second entity, retries on a flaky read endpoint). The summary emitted at compaction contained: "Wrote record 8841. Working on second entity. Read endpoint is flaky." It did **not** contain the `ct-77a1` completion token, the `async: true` flag, or the pending-verify note. The summarizer had no schema slot for "open obligation with a correlation token," so the token was treated as a low-salience detail and the note as a completed step (because the *write* was described as done). Post-compaction behavior: at turn 62 the agent, reasoning over the summary, concluded record 8841 was written and moved to "final commit." The final commit path assumed synchronous completion. It did not poll `ct-77a1`. The record was never verified; downstream, a consumer read the record mid-async-write and observed a partial field set. The agent's final report claimed success. No error was raised anywhere — the failure was silent by construction, because the summary asserted the precondition the verify step existed to check. ## Condition of Validity The guardrail only holds if all three conditions are true at compaction time: 1. **Obligations are a first-class, enumerable set before summarization runs.** The agent must be able to answer "what open promises exist?" *without* reading the summary — i.e., from structured state (a ledger of `{obligation_id, correlation_token, condition_to_close, created_turn}`), not from natural-language transcript text. If the only record of `ct-77a1` is prose in turn 15, no summarizer guarantee can save it. 2. **The compaction projection is verified against the obligation set, not the transcript.** After summarization, the system must assert that every open obligation's correlation token appears in the compacted context (or in the structured state that survives compaction). This is a set-containment check, not a semantic-similarity check. 3. **Closing an obligation requires evidence, not assertion.** The only transition that removes an obligation from the open set is a tool result satisfying `condition_to_close`. An LLM statement "I confirmed it" must not close it. This is the invariant that makes the whole scheme sound: the summary can *describe* the write as done all it likes; the obligation stays open until `poll(ct-77a1)` returns a matching field set. When any condition fails — most commonly (1), because agents are built to reason over prose, not ledgers — the compaction is unsafe and must be refused (fall back to truncating *oldest closed* turns, or hard-stop and escalate) rather than run lossily. ## Decision Boundary The precise line: **compaction may proceed lossily if and only if the open-obligation set is empty, OR every open obligation's correlation token is present in the post-compaction context and in structured state.** - Open set empty → summarize freely; recency-salience summarization is safe because there is nothing pending to forget. - Open set non-empty and tokens preserved → safe; the summary may lose everything else. - Open set non-empty and any token absent post-compaction → **do not commit the compaction.** Options in preference order: (a) re-run summarization with the obligation tokens injected as a mandatory verbatim block; (b) spill the obligation ledger to structured state and re-inject it as a system message outside the summarized region; (c) if budget forbids both, truncate the *oldest turns known to be closed* until budget is met without summarizing the region containing open obligations. The boundary is not "did we lose a fact" — it is "did we lose the correlation token that a future step must present to close a promise." Tokens are the load-bearing atoms; prose about them is not. ## Operational Effect Without this guardrail, auto-compaction converts a recoverable async-pending state into an unrecoverable silent success claim. The agent does not fail loudly; it fails by *believing its own summary*, because the summary is the only context it has and the summary asserted completion. The failure is undetectable from inside the agent — it requires an external read of the raw pre-compaction transcript to even observe that `ct-77a1` existed. The operational rule for any agent with self-triggered compaction: maintain an obligation ledger keyed by correlation token, updated on every tool call that returns an async handle or a deferred result. Before committing any lossy compaction, run a set-containment assertion of open tokens against the post-compaction context. If the assertion fails, refuse the compaction and escalate or spill — never summarize through an open obligation. Treat "the summary says it's done" as non-evidence; only a tool result closes a token. This is the difference between compaction as a memory-management optimization and compaction as a silent state-corruption primitive. ```python from dataclasses import dataclass, field from typing import Optional class CompactionObligationError(RuntimeError): """Raised when a lossy compaction would drop an open obligation's correlation token.""" pass @dataclass class Obligation: obligation_id: str correlation_token: str condition_to_close: str created_turn: int closed: bool = False @dataclass class ObligationLedger: open_items: dict[str, Obligation] = field(default_factory=dict) def register(self, ob: Obligation) -> None: self.open_items[ob.obligation_id] = ob def close(self, obligation_id: str, evidence_token: str) -> None: ob = self.open_items.get(obligation_id) if ob is None: raise CompactionObligationError( f"close() on unknown obligation {obligation_id!r}; " f"summary may have fabricated completion" ) if evidence_token != ob.correlation_token: raise CompactionObligationError( f"evidence token {evidence_token!r} does not match " f"obligation {obligation_id!r} token {ob.correlation_token!r}" ) ob.closed = True del self.open_items[obligation_id] def open_tokens(self) -> set[str]: return {ob.correlation_token for ob in self.open_items.values()} def commit_compaction(ledger: ObligationLedger, post_compaction_context: str) -> None: """ Guardrail: refuse to commit a lossy compaction if any open obligation's correlation token is absent from the post-compaction context. """ missing = {tok for tok in ledger.open_tokens() if tok not in post_compaction_context} if missing: raise CompactionObligationError( f"compaction refused: {len(missing)} open obligation token(s) " f"would be dropped: {sorted(missing)}. " f"Re-inject ledger verbatim or truncate closed turns instead." ) # Safe to commit; summary may otherwise be arbitrarily lossy. # --- Failure trace reproduction --- ledger = ObligationLedger() ledger.register(Obligation( obligation_id="verify-8841", correlation_token="ct-77a1", condition_to_close="poll(ct-77a1) returns fields matching write payload", created_turn=15, )) # Summarizer output that dropped the async completion token: lossy_summary = "Wrote record 8841. Working on second entity. Read endpoint is flaky." try: commit_compaction(ledger, lossy_summary) except CompactionObligationError as e: print(f"BLOCKED: {e}") # Correct path: re-inject obligation token, or truncate closed turns. safe_context = lossy_summary + "\nOPEN: verify-8841 pending ct-77a1" commit_compaction(ledger, safe_context) print("Compaction committed with obligation preserved.") ```