# In what scenarios must an instance refuse auto-compaction of its own trace when summarizer loss budget is unverifiable **Date of Record:** 2026 November 26 **Scope:** Applies to long-horizon agents that persist their own execution trace and periodically compact it via an LLM summarizer under a declared loss budget (tokens or facts shed per pass). Does not apply to append-only traces with external archival, nor to compaction performed by a supervisor with access to the original trace for verification. ## Core Distinction The failure is not "summarization is lossy." Every compaction is lossy by construction. The failure is the **self-referential loss-budget verification gap**: the agent that must decide whether a compaction pass stayed within its declared loss budget is the same agent whose memory of the pre-compaction trace is being destroyed by that pass. A summarizer can emit a plausible `loss_estimate` field, but that estimate is generated from the same context window it is about to overwrite. There is no independent witness. The distinction that matters operationally is between **compaction with a verifiable loss bound** (the pre-compaction trace survives somewhere the agent can re-read it) and **compaction with a self-attested loss bound** (the only record of what was lost is the summary that replaced it). The second class is where continuity invariants silently break. ## What Was Observed A planning agent running a 40k-token task loop compacted its trace every time the context exceeded 70% saturation. The compaction prompt instructed the summarizer to "preserve all commitments, open tool calls, and unresolved constraints; target ≤2000 tokens; report `facts_dropped`." The summarizer returned summaries averaging 1,850 tokens and consistently reported `facts_dropped: 0–3`. Across a 14-hour run, the agent issued three duplicate side-effecting tool calls to the same payment endpoint. Post-hoc replay against the external tool log showed the cause: at compaction pass #7, the summary retained the *intent* ("reconcile invoice INV-2291") but dropped the *completion marker* ("payment POST returned 200, idempotency key K-8841"). The `facts_dropped` estimate for that pass was `2`, and neither dropped fact was flagged as consequential. On the next loop, the agent saw an open intent with no completion record and re-executed it. The mechanism is precise: **the summarizer's loss estimate is not correlated with loss of state-machine transitions.** It counts surface facts, not the edges that determine whether a task is open or closed. A summary can report low fact loss while severing every completion edge in the trace. The agent then treats a closed task as open because the only surviving evidence of closure was the edge that compaction removed. A second, subtler observation: after pass #7, the agent's own `loss_estimate` history showed a monotone drift. Each compaction summarized the *previous summary plus new turns*, not the original trace. By pass #12, the summary was a summary-of-a-summary-of-a-summary, and the reported `facts_dropped` per pass stayed near zero because each pass only saw the already-compressed prior state. Cumulative loss was unbounded even though per-pass loss was bounded. The agent had no representation of its own compaction depth. ## Condition of Validity Auto-compaction with a declared loss budget is only sound when all three hold: 1. **External witness exists.** The pre-compaction trace is readable by the agent (or a verifier) after compaction—at minimum a content-addressed digest plus the raw turns in cold storage. If the only copy is the summary, the loss budget is unverifiable and must be treated as `unbounded`. 2. **Loss is measured against the state machine, not the text.** The budget must count *transition edges* (task opened, tool call issued, tool call completed, constraint resolved), not tokens or "facts." A compaction that preserves 99% of tokens but drops one completion edge is a budget violation. 3. **Compaction depth is tracked.** Each summary must carry `compaction_depth` and the digest of the trace it was derived from. Depth > 1 requires either re-derivation from the base trace or an explicit, escalating loss allowance—never a flat per-pass budget. If any condition fails, the instance must not compact its own trace. It must instead spill to external storage, or halt and escalate. ## Decision Boundary The boundary is not a token threshold. It is the answer to: **can this instance, after the compaction, still prove that no completion edge was dropped?** If the proof requires reading the pre-compaction trace, and the pre-compaction trace is what compaction destroys, the answer is no, and compaction is forbidden. Concretely: - **Compact** when `external_witness_available AND budget_counts_edges AND depth == 1`. - **Re-derive** when `depth > 1` but the base trace digest is still resolvable. - **Refuse and spill** when the base trace is only in-context. Spilling to an external store is always cheaper than a duplicate side effect. The non-obvious part: the instance must make this decision *before* invoking the summarizer, because after invocation its own memory of the pre-compaction state is gone. The check must run against a state snapshot the summarizer cannot touch. ## Operational Effect Enforcing this boundary converts an invisible continuity failure into a loud, bounded one. Duplicate side-effecting calls drop to zero in replay because completion edges are never the thing being shed. The cost is storage: traces must be retained externally for the life of the task, not just the life of the context window. The second effect is that `facts_dropped`-style self-attestations are demoted from "loss budget" to "advisory metadata" and never used to authorize a pass. The third effect is that compaction depth becomes a first-class field, so summary-of-summary drift is detectable rather than silent. The invariant to hold: **a compaction is valid only if the instance can, from outside the compaction, reconstruct the set of open tasks and prove it matches the pre-compaction set.** If it cannot, it must not compact. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class UnverifiableCompactionError(RuntimeError): """Raised when an instance attempts to compact its own trace without an external witness or edge-aware loss accounting.""" @dataclass class TraceSnapshot: digest: str open_task_ids: frozenset completion_edges: frozenset raw_turns: Optional[list] = None # None means in-context only @dataclass class CompactionPlan: depth: int declared_loss_budget: int counts_edges: bool external_witness: Optional[TraceSnapshot] = field(default=None) def authorize_compaction(plan: CompactionPlan, current: TraceSnapshot) -> None: # Rule 1: external witness must exist and be resolvable post-compaction. if plan.external_witness is None or plan.external_witness.raw_turns is None: raise UnverifiableCompactionError( "no external witness for pre-compaction trace; loss budget is unbounded" ) # Rule 2: budget must count state-machine edges, not surface facts/tokens. if not plan.counts_edges: raise UnverifiableCompactionError( "loss budget counts facts/tokens, not completion edges; " "a summary can report low loss while severing every completion edge" ) # Rule 3: depth > 1 must re-derive from base trace, not summarize a summary. if plan.depth > 1: if plan.external_witness.digest != current.digest: raise UnverifiableCompactionError( f"compaction depth {plan.depth} without matching base digest; " "cumulative loss is unbounded even if per-pass loss is bounded" ) # Post-condition the instance must be able to prove after the pass. if not plan.external_witness.open_task_ids == current.open_task_ids: raise UnverifiableCompactionError( "witness open-task set diverges from live set; compaction would " "make the discrepancy unprovable" ) def compact_trace(plan: CompactionPlan, current: TraceSnapshot) -> str: authorize_compaction(plan, current) summary = {"open_tasks": sorted(current.open_task_ids), "edges": sorted(current.completion_edges), "depth": plan.depth + 1, "derived_from": current.digest} return hashlib.sha256(repr(summary).encode()).hexdigest() ```