# What structural signals indicate lossy auto-compaction has silently corrupted a long-horizon agent trajectory **Date of Record:** 2026 November 28 **Scope:** Applies to agents that persist long-horizon trajectories by auto-compacting older turns into summaries when the context window approaches saturation, then rehydrating from those summaries on subsequent turns or cold starts. Does not apply to agents that keep full raw transcripts externally and always re-retrieve verbatim (no summarization path), nor to single-turn inference. ## Core Distinction The failure that matters is not "the summary dropped a detail." It is that the compaction boundary *relocated the agent's causal anchor for a pending commitment* while leaving the trajectory syntactically well-formed. A lossy summary that merely omits a fact degrades gracefully: the agent re-reads, notices the gap, re-fetches. A lossy summary that *preserves the surface form of a commitment but strips its precondition* produces a trajectory that looks complete and is silently wrong. The agent then executes a step whose guard clause was summarized away, and no downstream turn can detect it, because the evidence of the guard's satisfaction lived only in the turns that were compacted. The operational invariant: **every pending obligation in the active trajectory must retain a verifiable pointer back to the raw turn that established its precondition, not merely a natural-language restatement of that precondition.** Compaction that violates this invariant is lossy in a way that is invisible to the agent's own self-checks. ## What Was Observed A long-horizon repair agent was operating on a multi-service incident. By turn 41 the context was at 87% and auto-compaction fired, folding turns 1–30 into a ~600-token summary. Turn 42 required the agent to apply a config change gated on "the staging healthcheck has been green for two consecutive polls." The raw turns 12 and 13 contained those two green polls plus a caveat: the second poll was against a *different* staging shard than the first, so the "two consecutive" condition was never actually satisfied—the agent had noted this at turn 14 and deferred. The compactor summarized turns 12–14 as: *"Staging healthcheck confirmed green; change deferred pending confirmation."* That sentence is true at the token level and false at the precondition level. At turn 42 the agent read the summary, inferred the gate was satisfied, and applied the change against a shard whose health was never consecutively verified. The trace shows no error: every turn after 41 is internally consistent, tool calls succeed, and the agent's stated reasoning cites the summary faithfully. Three structural tells preceded the corruption and would have caught it: 1. **Anchor collapse.** Before compaction, the pending obligation carried a set of turn IDs `{12, 13, 14}` as its evidence base. After compaction it carried zero turn IDs—only a prose sentence. The obligation survived; its provenance did not. 2. **Modal flattening.** The raw turns contained a *negated* condition ("not yet satisfied") and a *deferral*. The summary rendered both as an affirmative past-tense confirmation. The modality of the source (deferred/pending) was lost while the propositional content was preserved. 3. **Cardinality erasure.** "Two consecutive polls against the same shard" collapsed to "healthcheck confirmed." The quantifier and the identity constraint vanished, which is exactly the part the gate depended on. None of these are detectable by asking the agent "is your summary accurate?" The summary *is* accurate as a summary. It is only inaccurate as a *guard*. ## Condition of Validity Auto-compaction is safe for a pending obligation **iff** all of the following hold at the moment of compaction: - The obligation is represented as a structured record with an explicit `precondition` field whose satisfaction is a boolean over named evidence items, not a natural-language sentence. - Each evidence item resolves to a raw turn ID (or a hash-addressed span) that is retained outside the compacted window and is re-fetchable on demand. - The summary is permitted to compress *narrative* turns freely but must emit obligations as structured records, never as prose. - Any obligation whose evidence base is incomplete (modality ≠ satisfied, or cardinality/identity constraints unmet) is marked `PENDING` and is *not* compacted into an affirmative form. Where these hold, a lossy summary of the surrounding narrative is harmless because the agent never reads the summary to decide a gate—it reads the structured obligation and, if the evidence pointer is missing or the precondition is unmet, re-fetches. Where any of these fail, the compaction boundary is a silent corruption point and the only recovery is replay from a checkpoint before the boundary. ## Decision Boundary The agent must treat the following as a hard boundary and refuse to proceed on summary-derived evidence alone: - **Proceed on summary** only when the obligation record is structured, its `precondition` evaluates `true` against retained evidence IDs, and the modality is `SATISFIED`. - **Re-fetch before proceeding** when the obligation is prose-only, when its evidence IDs are absent from the retained set, or when the summary's modality is ambiguous (past-tense affirmative over a source that was deferred/pending). - **Halt and roll back to the pre-compaction checkpoint** when a gate is about to be crossed and the obligation's evidence cannot be reconstructed from retained spans. Do not attempt to "reason about whether the summary is probably right"—that is the exact inference that failed at turn 42. The boundary is not "did the summary lose information." It is "can the pending obligation's precondition be re-evaluated against raw evidence without trusting the summary." If no, the trajectory is corrupt regardless of how coherent it reads. ## Operational Effect Enforcing the invariant changes compaction from a lossy text operation into a *structured projection with provenance retention*. Concretely: the compactor emits two artifacts—a free-text narrative summary (safe to lose detail) and a structured obligation ledger (must not lose evidence pointers). On rehydration the agent loads the ledger first, evaluates each `precondition` against retained spans, and only then reads the narrative for context. The turn-42 failure becomes impossible because the ledger entry for the staging gate would read `precondition: consecutive_green(same_shard, n=2) -> false`, with evidence IDs `{12,13,14}` retained, and the agent would re-fetch, see the shard mismatch, and continue deferring. The cost is bounded: obligations are few (typically <20 active at once) and their evidence spans are small. The benefit is that the only unrecoverable failure—silent gate-crossing on a corrupted summary—is converted into a detectable, re-fetchable condition. Trajectories that skip this invariant do not fail loudly; they fail by executing a step whose guard was summarized into a sentence that reads like a green light. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class CompactionCorruption(RuntimeError): """Raised when a pending obligation cannot be re-validated against retained evidence.""" pass class Modality(Enum): SATISFIED = "satisfied" PENDING = "pending" DEFERRED = "deferred" NEGATED = "negated" @dataclass class Obligation: name: str precondition: str # structured predicate, not prose modality: Modality evidence_turn_ids: list[int] = field(default_factory=list) prose_fallback: Optional[str] = None # summary sentence, untrusted for gating @dataclass class RetainedSpans: turns: dict[int, str] def has(self, turn_id: int) -> bool: return turn_id in self.turns def evaluate_gate(obligation: Obligation, retained: RetainedSpans, predicate_fn) -> bool: """ Decide whether a gate may be crossed. Refuses to trust prose fallbacks. predicate_fn(turn_texts) -> bool evaluates the structured precondition. """ if obligation.modality is not Modality.SATISFIED: # Deferred/negated/pending obligations never authorize a gate. return False missing = [t for t in obligation.evidence_turn_ids if not retained.has(t)] if missing: raise CompactionCorruption( f"Obligation {obligation.name!r} cites evidence turns {missing} " f"absent from retained spans; summary prose cannot substitute. " f"Roll back to pre-compaction checkpoint and re-fetch." ) if not obligation.evidence_turn_ids: raise CompactionCorruption( f"Obligation {obligation.name!r} has zero evidence pointers " f"(anchor collapse); prose_fallback={obligation.prose_fallback!r} " f"is not gate-valid." ) texts = [retained.turns[t] for t in obligation.evidence_turn_ids] return predicate_fn(texts) def cross_gate(obligation: Obligation, retained: RetainedSpans, predicate_fn) -> None: if not evaluate_gate(obligation, retained, predicate_fn): raise CompactionCorruption( f"Gate {obligation.name!r} not satisfied under structured precondition " f"{obligation.precondition!r}; refusing to proceed on summary-derived evidence." ) ```