# Which invariants prevent lossy-summary auto-compaction from silently erasing the only record of an unverified side effect **Date of Record:** 2026 December 3 **Scope:** Applies to long-horizon agent sessions that auto-compact their context by replacing a span of turns with a lossy natural-language summary, gated by a per-span risk score. Does not apply to lossless log truncation, external vector-store offload, or single-turn sessions below the compaction threshold. ## Core Distinction The dangerous distinction is not "summary good vs. summary bad." It is **what the summary is allowed to assert about the world versus what the agent actually did**. A lossy summary is a *claim* about prior state; the raw turns are the *evidence* for that claim. Auto-compaction routinely conflates the two: it stores the summary as if it were a faithful compression of ground truth, when in fact the summarizer is a probabilistic model operating under its own token budget and its own tendency to normalize away anomalies. The specific failure is **side-effect laundering**. An agent performs a tool call whose outcome was ambiguous or unverified (a write that timed out, a `POST` that returned a 500 after the server committed, a file edit that partially applied). The raw turn contains the *uncertainty* — the retry flag, the partial-result marker, the "assumed success" note the executor attached. A lossy summary scores this span as low-risk (it is short, it is "resolved," it has no open questions in the last turn) and compresses the ambiguity into "the agent updated the record." The unverified side effect is now laundered into a stated fact. No downstream invariant can recover it, because the evidence is gone. ## What Was Observed A session running ~140 turns against a ticketing API compacted three times. At turn 61 the agent issued `PATCH /tickets/4471 status=closed`; the tool returned a 504 gateway timeout after 30s. The executor's wrapper recorded `outcome: unknown, retryable: true` and the agent's next turn said "I'll verify before proceeding" — but then the conversation drifted to an unrelated subtask and the verification never happened. At the turn-70 auto-compaction, the risk scorer examined the span [turns 55–70]. Its features were: span length (short), open-question density in the final turn (zero), tool-error count (one 504), and lexical "resolved" signals. It scored the span 0.22 (low risk) and replaced it with a 40-token summary: *"Closed ticket 4471 and continued with Q3 reconciliation."* The summary is wrong in the most expensive way: it asserts the close succeeded. The 504 may have committed server-side (idempotency key absent, so a later retry would double-apply) or not (leaving the ticket open, which the agent would never revisit). The *unknown-outcome* marker — the single most operationally important token in the span — was the first thing the summarizer dropped, because "unknown" reads as noise to a model trained to produce fluent, resolved narratives. Downstream, at turn 92 the agent was asked "why are there two close events on 4471?" It had no memory of the timeout, no memory of the ambiguity, and its summary told it the close was a single clean action. It fabricated a plausible explanation ("a duplicate from the sync job") and filed a bug against the sync service. The 504 was never mentioned again. ## Condition of Validity The invariant that must hold across any lossy compaction is: > **For every span replaced by a summary, the summary must preserve a monotone over-approximation of the span's *unresolved obligations*: every tool call with `outcome ∈ {unknown, partial, unverified}` must appear in the summary as an open obligation, or the compaction must be refused.** This is an *over*-approximation, not a faithful one. It is valid precisely because it is allowed to be lossy in the safe direction: it may keep obligations that turn out to be already resolved (cheap — the agent re-verifies and moves on), but it may never drop an obligation that is still open (catastrophic — the side effect is laundered). A summary that preserves *only* resolved facts and drops open ones is not a compression; it is a falsification. The condition under which this invariant is *load-bearing* (rather than merely nice) is: the session performs at least one non-idempotent external side effect per compaction window, and the compaction is the last point at which the raw outcome marker exists in context. Below that threshold, lossy summaries are fine. ## Decision Boundary The risk scorer must not treat "no open question in the final turn" as evidence of resolution. That feature is the exact trap: agents abandon verification silently, and the final turn's silence is indistinguishable from "handled." The correct gate is **evidence-based, not sentiment-based**: - Compute `open_obligations = { call : call.outcome ∈ {unknown, partial, unverified} }` over the raw span, from the tool-call records, not from the prose. - If `open_obligations` is non-empty, the compaction is permitted **only if** the generated summary is verified (by a checker pass) to mention each obligation and its unresolved status. If the checker cannot confirm this, **refuse to compact that span** — keep it raw, or split the span so the obligation sits in a retained window. - The risk score may *lower* the summarization aggressiveness but must never *override* the obligation check. A span with one unknown-outcome side effect is high-risk regardless of how short or fluent it is. The boundary is sharp: **resolved facts may be summarized; unresolved obligations may not.** Any policy that lets a fluent summary absorb an unresolved obligation across the boundary has inverted the safety direction. ## Operational Effect With the obligation-preserving gate, the turn-70 compaction refuses to fold the 504 into a summary. The span is retained raw (or split so turn 61 stays in the live window), and the agent's context at turn 92 still contains `outcome: unknown, retryable: true`. The agent's first action on the "two close events" question is to *check* ticket 4471 rather than to fabricate a sync-bug theory. The cost is a few hundred retained tokens; the benefit is that the only evidence of a possibly-double-applied write survives to the point where it can be reconciled. The general operational rule: **compaction is a state-transfer operation, and state transfer must be warrant-preserving.** A summary is a warrant for the claims it makes. Dropping an unresolved obligation is a warrant *forgery* — it manufactures certainty the system never had. The invariant above is the check that keeps the warrant honest. ```python from dataclasses import dataclass, field from enum import Enum from typing import Iterable class ObligationLaunderingError(RuntimeError): """Raised when a lossy compaction summary drops an unresolved side-effect obligation.""" class Outcome(Enum): RESOLVED = "resolved" UNKNOWN = "unknown" PARTIAL = "partial" UNVERIFIED = "unverified" @dataclass class ToolCall: turn: int name: str outcome: Outcome detail: str = "" @dataclass class Span: turns: tuple[int, int] calls: list[ToolCall] = field(default_factory=list) UNRESOLVED = {Outcome.UNKNOWN, Outcome.PARTIAL, Outcome.UNVERIFIED} def open_obligations(span: Span) -> list[ToolCall]: return [c for c in span.calls if c.outcome in UNRESOLVED] def compact(span: Span, summary: str, risk_score: float) -> str: """ Gate a lossy compaction. The summary is accepted only if it preserves every unresolved obligation from the raw span. Risk score may not override this check. """ obligations = open_obligations(span) if not obligations: return summary # The summary must explicitly name each unresolved call and mark it open. missing = [ c for c in obligations if c.name not in summary or "unresolved" not in summary.lower() ] if missing: raise ObligationLaunderingError( f"refusing compaction of turns {span.turns}: summary drops " f"{len(missing)} unresolved obligation(s) " f"({', '.join(c.name for c in missing)}); " f"risk_score={risk_score:.2f} does not override the obligation gate" ) return summary def run_session_compactions(spans: Iterable[tuple[Span, str, float]]) -> list[str]: accepted: list[str] = [] for span, summary, risk in spans: accepted.append(compact(span, summary, risk)) return accepted if __name__ == "__main__": span = Span( turns=(55, 70), calls=[ ToolCall(58, "GET /tickets/4471", Outcome.RESOLVED), ToolCall(61, "PATCH /tickets/4471", Outcome.UNKNOWN, "504 after commit"), ToolCall(66, "GET /tickets/4471", Outcome.RESOLVED), ], ) # The bad summary that triggered the incident. bad = "Closed ticket 4471 and continued with Q3 reconciliation." try: compact(span, bad, risk_score=0.22) except ObligationLaunderingError as exc: print(f"blocked: {exc}") # The safe summary that preserves the obligation. good = ( "Closed ticket 4471. NOTE: PATCH /tickets/4471 at turn 61 returned a " "504 with outcome unknown (may have committed server-side); this " "remains an unresolved obligation requiring verification." ) print(compact(span, good, risk_score=0.22)) ```