# Where must an instance boundary be drawn between lossy summarization checkpoints and compaction eligibility in long-horizon agent traces **Date of Record:** 2026 November 23 **Scope:** Applies to agent runtimes that persist a long-horizon trace as an append-only event log, periodically emit lossy summarization checkpoints over that log, and auto-compact older segments to bound storage and context cost. Does not apply to systems that retain full-fidelity traces indefinitely, or to compaction that never discards source events (deduplicative-only compaction). ## Core Distinction The non-obvious boundary is between *checkpoint coverage* and *compaction eligibility*. A summarization checkpoint is lossy: it is a derived artifact that asserts "these N events are representable by this summary." Compaction is destructive: it deletes the N events and promotes the summary to the authoritative record. The invariant that is routinely violated is: > A source event may be compacted **only** if it is transitively covered by a checkpoint whose summary has been *durably committed and verified readable* before the source event is deleted. Two conditions are conflated in most implementations: (a) the checkpoint was *written*, and (b) the checkpoint was *committed and is recoverable under the same durability class as the events it replaces*. These are not the same. A checkpoint that exists in a write-ahead buffer, or in a replica that has not yet been acknowledged by the quorum that owns the trace, does not cover anything. If compaction runs against (a) rather than (b), the system can delete events that no durable summary describes — a hole in the trace that no later reader can detect, because the trace remains structurally valid (monotonic sequence numbers, contiguous offsets) while being semantically incomplete. The second, subtler distinction is between *event-level coverage* and *causal coverage*. A lossy summary that covers events 1000–5000 may drop a tool-call/result pair whose result arrives at event 5003. The summary "covers" the range numerically but not causally. Compacting 1000–5000 while retaining 5003 produces an orphaned result whose originating call is gone — the trace is now uninterpretable at exactly the point where the agent's reasoning depended on it. ## What Was Observed In a runtime with 200k-event traces and checkpoint emission every 5,000 events, a compaction worker ran on a schedule independent of the checkpoint committer. Under steady state the two were ordered by latency and the bug was latent. Under a checkpoint commit stall (the summarizer's model endpoint degraded to ~40s p99 for a 90-second window), the compaction worker observed checkpoint *files present on the local volume* and compacted 15,000 events whose summaries had not yet been acknowledged by the trace's replicated store. On the next leader failover, the trace was reconstructed from the replicated store. The 15,000 compacted events were absent (correctly — they had been deleted), but the corresponding summary records were also absent (they had never been committed). The reconstructed trace jumped from event 12,000 to event 27,000 with no summary bridging the gap. The gap was *not* flagged by any validator: offset continuity and sequence monotonicity were preserved because the compaction operation had rewritten the offsets to be contiguous. The trace was silently wrong. A second observation, from a different trace: causal orphans. A summary covering 40,000–45,000 dropped the body of a `tool_call` at 42,117 but the `tool_result` at 45,004 was retained (it fell just past the checkpoint's nominal end). Downstream replay of the compacted trace could not attribute the result to any call, and the agent's continuation logic — which matched results to calls by ID — discarded the result as unattributable, altering the reconstructed decision path. ## Condition of Validity The safe-compaction invariant holds only when all of the following are true at the moment of deletion: 1. **Commit-before-delete ordering is enforced by the storage layer, not by application sequencing.** The checkpoint's commit must be a prerequisite the compaction transaction *reads back* (a quorum-acknowledged read of the committed summary), not a promise the application made earlier. 2. **Coverage is causal, not numeric.** The checkpoint must declare the set of *causal units* (call/result pairs, multi-event tool invocations) it fully subsumes, and compaction must refuse to cut a causal unit. A summary that ends mid-unit is not eligible to cover that unit. 3. **The summary carries a content hash of the source range** it replaces, so that a later reader can verify that the summary is the summary *of those events* and not a stale or mismatched artifact. 4. **Deletion is reversible for a bounded window** (tombstone or soft-delete) longer than the maximum observed commit-stall duration. When any of these is absent, compaction is a lossy operation whose loss is undetectable after the fact — the worst class of failure for an operational record. ## Decision Boundary The decision to compact a range `[a, b]` must be gated on a predicate that is *strictly stronger* than "a checkpoint exists for `[a, b]`." The operational rule: - If the checkpoint covering `[a, b]` is not quorum-committed and read-back-verified → **do not compact**; retain source events. - If the checkpoint is committed but its causal coverage does not fully contain every causal unit intersecting `[a, b]` → **shrink `b`** to the last causal-unit boundary fully inside the checkpoint, and compact only `[a, b']`. - If the checkpoint's content hash does not match the source range → **treat as uncovered** and escalate; do not compact. - Only when committed ∧ causally complete ∧ hash-verified → compact. The boundary is thus drawn not at "checkpoint written" but at "checkpoint durably committed, causally complete over the range, and cryptographically bound to that range." Everything below that line is uncovered source data and must be preserved. ## Operational Effect Enforcing the stronger predicate converts a silent, undetectable data-loss failure into a *visible stall*: compaction throughput drops when the summarizer degrades, and the trace grows. This is the correct trade. The stall is observable and alertable; the silent hole is neither. In the observed runtime, adding the read-back-verify gate and causal-boundary shrink eliminated the failover hole entirely, at the cost of a 3–7% increase in retained event volume during summarizer degradation windows — a bounded, monotone cost against an unbounded, non-monotone correctness risk. The secondary effect is that replay and audit tooling can now *trust* the trace: any gap between compacted ranges is either bridged by a verified summary or explicitly marked as a compaction stall, never silently elided. ```python from __future__ import annotations import hashlib from dataclasses import dataclass from typing import Iterable class UncoveredCompactionError(RuntimeError): """Raised when a compaction range is not safely covered by a committed, causally complete, hash-verified checkpoint.""" @dataclass(frozen=True) class Checkpoint: start: int end: int committed: bool # quorum-acknowledged and read back causal_units: tuple[tuple[int, int], ...] # (first_event, last_event) fully subsumed source_hash: str # hash of the source event range it replaces def _hash_range(events: Iterable[tuple[int, bytes]]) -> str: h = hashlib.sha256() for seq, payload in events: h.update(seq.to_bytes(8, "big")) h.update(payload) return h.hexdigest() def _causal_boundary_inside(cp: Checkpoint, lo: int, hi: int) -> int: """Largest b' <= hi such that [lo, b'] cuts no causal unit.""" best = lo for first, last in cp.causal_units: if first < lo: continue if last <= hi: best = max(best, last) else: break # this unit straddles hi; cannot extend past its start return best def compact_range( cp: Checkpoint, events: list[tuple[int, bytes]], lo: int, hi: int, ) -> int: """Return the exclusive end offset actually compacted, or raise.""" if not cp.committed: raise UncoveredCompactionError( f"checkpoint [{cp.start},{cp.end}] not quorum-committed; refusing to compact" ) if not (cp.start <= lo and hi <= cp.end): raise UncoveredCompactionError( f"range [{lo},{hi}] not contained in checkpoint [{cp.start},{cp.end}]" ) if _hash_range(events) != cp.source_hash: raise UncoveredCompactionError( "checkpoint source_hash mismatch; summary is not bound to these events" ) b_prime = _causal_boundary_inside(cp, lo, hi) if b_prime <= lo: raise UncoveredCompactionError( f"no causal-unit boundary inside [{lo},{hi}]; shrink and retry" ) # Caller may now delete [lo, b_prime) — never a partial causal unit. return b_prime ```