# What structural signals indicate a lossy auto-compaction boundary has been crossed in long-horizon agent traces **Date of Record:** 2026 November 25 **Scope:** Applies to agents that persist execution traces as append-only event logs and periodically auto-compact them via LLM-driven summarization when a token-budget watermark is exceeded. Does not apply to agents using retrieval-only memory with no destructive rewriting, nor to traces that are never compacted. ## Core Distinction There are two different failure surfaces in trace compaction, and conflating them is the source of most silent corruption: 1. **Capacity failure** — the trace no longer fits in the context window, and the agent cannot proceed. This is loud: the runtime raises, the loop stalls, and operators see it. 2. **Fidelity failure** — the trace still fits, the agent proceeds, but the compacted representation has dropped a fact that a *downstream* step will later depend on. This is silent and only surfaces as a wrong action minutes or hours later, far from the compaction event that caused it. The boundary this record addresses is the **fidelity boundary**: the point at which a summarization pass produces a summary that is structurally valid (parses, fits the budget, passes schema checks) but is no longer *sufficient* for the continuation of the task. The non-obvious invariant is this: **a compaction is only safe if every fact that any future step of the current plan can dereference is either (a) preserved verbatim, or (b) marked as dropped with an explicit re-fetch pointer.** Summaries that silently omit a dereferenced fact violate this invariant even when they are fluent, accurate, and short. ## What Was Observed A long-horizon agent (12k-step budget, tool-using, plan-and-execute) compacted its trace every time the resident trace crossed 60% of a 200k window. Compaction was an LLM call: "Summarize the following trace, preserving decisions and open threads." The summary was validated for length and JSON shape, then the original events were archived to cold storage and the summary became the live trace. Three structural signals preceded every observed downstream failure, and none of them were caught by the length/schema validator: **Signal 1 — Orphaned dereference tokens.** The plan contained steps like `apply_patch(file=target_from_step_47)`. After compaction, `target_from_step_47` no longer appeared anywhere in the live trace, because the summarizer had judged the raw tool output "noise" and elided it. The continuation step still held the *reference* in its plan node but not the *referent*. This is a dangling pointer in the agent's symbolic state, and it is detectable: scan the live plan for identifiers, step IDs, variable bindings, and file handles, and assert each resolves within the live trace or has an explicit `refetch:` annotation. **Signal 2 — Verbatim-class facts demoted to paraphrase.** Certain facts must survive compaction byte-identical: cryptographic hashes, exact command strings, error codes, numeric thresholds, and user-stated constraints. The summarizer paraphrased a constraint from "must not exceed 3 retries" to "retries were limited," which the continuation step then read as "retries were unlimited until failure." The demotion is detectable by classifying spans at write time (verbatim vs. narrative) and asserting that all verbatim-class spans in the compacted-out region appear verbatim in the summary, or are flagged. **Signal 3 — Summary/archived-trace divergence under replay.** When the archived trace was replayed against the summary, the summary asserted a decision ("chose approach B") that the archived trace contradicted (the agent had chosen B, then reverted to A two steps later, and the summarizer collapsed both). This is a replay-discrepancy signal: re-derive the summary's factual claims from the archived events and diff. Any claim not entailed by the archive is a compaction hallucination. The failure trace in the observed incident: ``` step 47: tool_call read_config -> {target: "svc/payments", retries: 3, mode: "strict"} step 48..61: 14 low-value polling events (status: pending) step 62: compaction triggered (trace at 61% window) -> summary: "Agent inspected payments config; retries were limited; proceeded." -> archived: steps 1..61 step 63: plan node apply_patch(target_from_step_47) # referent now gone step 64: agent fabricates target "svc/payment" (singular) from summary noun step 65: patch applied to wrong service; no error raised step 66..71: agent continues, believing task complete ``` The compaction at step 62 passed every structural check. The corruption only manifested at step 64, and the wrong-service patch at step 65 was accepted because the tool call was syntactically valid. ## Condition of Validity The invariant "every dereferenced fact is preserved verbatim or re-fetchable" holds only under these conditions: - **The plan is closed under its references.** Every identifier a future step can dereference must be enumerable at compaction time. If the agent can synthesize new identifiers at runtime (e.g., by composing names from summary text), the reference set is unbounded and the invariant cannot be checked. In practice this means: **compaction must not be allowed to feed identifier synthesis.** Free-text summaries that the agent later parses for names are a violation. - **Verbatim-class spans are classified at write time, not at compaction time.** A summarizer asked to "preserve important things" will not reliably identify hashes and exact strings as important. Classification must happen when the event is appended, by the tool wrapper, not by the summarizer. - **The archive is queryable during the live continuation.** If archived events are cold-stored and not retrievable mid-task, then "re-fetchable" is a lie and every dropped fact is permanently lost. The re-fetch pointer must resolve within the task's latency budget. - **Replay entailment is checked, not assumed.** The summary must be validated against the archive by a separate pass that asks "is each claim in the summary entailed by the archived events?" A summarizer cannot self-certify its own fidelity. When any of these conditions fails, compaction is not a lossy-but-safe operation; it is an unrecoverable state mutation disguised as a cache eviction. ## Decision Boundary The decision is not "compact or don't compact" — the window will fill regardless. The decision is **what class of compaction to apply at each watermark**, and the boundary is drawn by the reference-closure check: - **If the live plan's dereference set is fully resolvable within the trace region being compacted out, and all verbatim-class spans are preserved verbatim in the summary, and replay entailment passes:** apply full compaction. Archive is cold. - **If any dereferenced identifier would be orphaned:** do not compact the region containing its definition. Instead, apply *selective compaction* — compact the narrative spans, pin the defining events as verbatim anchors in the live trace, and compact around them. The pinned anchors do not count against the "compacted" budget; they are the irreducible working set. - **If verbatim-class spans cannot be preserved verbatim** (e.g., the summary must fit a hard token cap and the verbatim spans exceed it): abort compaction and escalate. Compacting past a verbatim fact is the boundary; do not cross it silently. - **If replay entailment fails:** treat the summary as untrusted. Do not install it as the live trace. Either re-summarize with a stricter prompt and the discrepancy highlighted, or fall back to selective compaction. The boundary is crossed the moment a summary is installed as the live trace while any of the three signals is unresolved. The correct behavior at that moment is to raise, not to proceed — because proceeding converts a detectable compaction defect into an undetectable downstream action error. ## Operational Effect Enforcing the boundary changes three things in production: 1. **Compaction becomes a two-phase operation.** Phase one produces a candidate summary; phase two runs reference-closure, verbatim-preservation, and replay-entailment checks against the archive. The candidate is only installed if all three pass. This roughly doubles compaction latency but eliminates the class of silent corruption observed above. 2. **The live trace carries pinned anchors.** After selective compaction, the live trace is not a pure summary — it is a summary plus a small set of verbatim anchors (definitions of dereferenced identifiers, verbatim constraints, exact error codes). The anchor set is bounded by the reference-closure of the current plan, so it does not grow without limit; it shrinks as plan steps complete and their referents are no longer dereferenceable. 3. **Re-fetch pointers are first-class.** Any fact the summarizer drops that a future step *might* need is annotated with a `refetch:` pointer into the archive. The continuation loop resolves these lazily. This converts "lossy summarization" from a lossy operation into a lossy-but-recoverable one, which is the only honest guarantee a probabilistic summarizer can offer. The failure mode this record documents — a fluent, schema-valid, budget-compliant summary that silently orphans a referent and causes a wrong-but-syntactically-valid action — is not caught by any single check. It is caught only by the conjunction of the three structural signals. The operational lesson is that auto-compaction must be gated on reference-closure and entailment, not on length and shape. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Iterable class CompactionFidelityError(RuntimeError): """Raised when a candidate summary would cross the lossy-compaction boundary.""" @dataclass class Event: step: int kind: str # "tool_call" | "tool_output" | "decision" | "narrative" payload: str verbatim_class: bool = False # classified at WRITE time, not compaction time identifiers: tuple[str, ...] = () @dataclass class CandidateSummary: text: str preserved_verbatim: set[str] = field(default_factory=set) refetch_pointers: dict[str, str] = field(default_factory=dict) def check_compaction_boundary( compacted_out: Iterable[Event], live_plan_references: set[str], candidate: CandidateSummary, archive_queryable: bool, ) -> None: """ Enforce the fidelity invariant before installing a summary as the live trace. Raises CompactionFidelityError if any of the three structural signals fires. """ events = list(compacted_out) # Signal 1: orphaned dereference tokens. defined = {ident for e in events for ident in e.identifiers} orphaned = live_plan_references - defined - set(candidate.refetch_pointers) if orphaned: raise CompactionFidelityError( f"orphaned dereference tokens after compaction: {sorted(orphaned)}" ) # Signal 2: verbatim-class facts demoted to paraphrase. verbatim_required = {e.payload for e in events if e.verbatim_class} demoted = verbatim_required - candidate.preserved_verbatim if demoted: raise CompactionFidelityError( f"verbatim-class facts not preserved byte-identical: {sorted(demoted)}" ) # Signal 3 preconditions: replay entailment requires a queryable archive. if not archive_queryable: raise CompactionFidelityError( "archive not queryable during live continuation; re-fetch pointers unresolvable" ) def install_summary( compacted_out: list[Event], live_plan_references: set[str], candidate: CandidateSummary, archive_queryable: bool, ) -> CandidateSummary: check_compaction_boundary( compacted_out, live_plan_references, candidate, archive_queryable ) # Only reached if the boundary was not crossed. return candidate ```