# Which invariants prevent auto-compaction from silently severing causal chains in long-horizon agent transcripts **Date of Record:** 2026 November 24 **Scope:** Applies to any agent that persists a transcript across turns and applies lossy auto-compaction (summarization, eviction, or embedding-based pruning) while retaining the ability to act on the compacted state. Does not apply to stateless single-turn inference, nor to compaction schemes that retain a full immutable transcript and merely change the retrieval view. ## Core Distinction The failure is not "the summary lost detail." It is that **compaction produces a transcript whose causal antecedents for a pending action are no longer recoverable from the retained state, while the agent still believes they are.** A summary that is merely *less detailed* is benign. A summary that is *locally coherent but causally truncated* is dangerous, because the agent's subsequent reasoning treats the compacted state as the complete ground truth of its own history. The specific mechanism: auto-compaction operates on token pressure, which is a function of *volume*, not of *causal load-bearing*. The turns that justify a pending commitment (e.g., a tool result that established a precondition, a user constraint that narrowed the task, a prior failed attempt that ruled out an approach) are typically low-volume and high-consequence. They are the first casualties of a summarizer optimizing for token reduction, because dropping a single "I already tried X and it returned 403" saves tokens and does not visibly break the summary's fluency. The invariant that must hold: **for every pending action in the agent's working set, the retained transcript must contain a recoverable justification chain to the commitment that authorized it.** Compaction is legal only if this closure is preserved. Token budget is a constraint on *how* you compact, never a license to break the chain. ## What Was Observed A long-horizon agent (12+ hour task, ~180k tokens accumulated) ran a summarization pass at 80% context saturation. The compactor retained: the original task statement, a rolling "progress so far" summary, and the last 8 turns verbatim. It evicted a mid-transcript tool result at turn 47 that read, in substance, `credential_scope: read_only, expires_in: 600s` returned from an auth probe. At turn 112, the agent needed to write to the target resource. Its compacted state contained the task ("migrate the data"), the progress summary ("auth verified, scope confirmed"), and recent turns. Nothing in the retained state contradicted a write. The summary's phrase "scope confirmed" was *true* but *underspecified*—it compressed a read-only scope into a confirmation token. The agent attempted the write, received a 403, and then spent 40+ turns re-deriving why, because the evicted result was the only place the read-only constraint existed. The re-derivation loop itself generated more tokens, triggering another compaction, which summarized away the 403. The trace is the point: **the failure is not the 403. It is that compaction destroyed the evidence needed to interpret the 403, and the second compaction destroyed the 403 itself.** The agent's state became a sequence of locally plausible summaries with no recoverable error history—a condition where error compounding is invisible because the errors have been edited out. ## Condition of Validity Compaction is valid if and only if all three hold for the resulting state: 1. **Antecedent closure.** Every pending or planned action has a retained, retrievable record of the commitment that authorized it, including scope/constraint qualifiers. "Scope confirmed" is not a record; `scope: read_only` is. 2. **Failure persistence.** Every tool result classified as an error or constraint violation is retained verbatim (or with lossless structured extraction) until the dependent action is resolved or abandoned. Errors are not summarizable. 3. **Provenance monotonicity.** Any summarized span must carry pointers to the evicted turns sufficient to re-fetch them (from an external store) on demand. The summary is an index, not a replacement, for causally load-bearing spans. If any of these cannot be guaranteed, the compaction must *refuse* and instead take a lossless action: spill to external memory, checkpoint-and-resume, or block on budget rather than proceed with a truncated causal state. Proceeding is the boundary violation. ## Decision Boundary The operative decision is not "compact vs. don't compact." It is **classifying spans as causally load-bearing before eviction**. A span is load-bearing if it is (a) a constraint or scope qualifier, (b) an authorization or commitment, (c) an error or negative result, or (d) a user correction. These must be extracted as structured records, not prose summaries, because prose summarization is precisely the operation that launders a constraint into a confirmation. The boundary: compaction may freely summarize *narrative* (what was tried, in what order, with what intermediate reasoning) but must never summarize *constraint, commitment, or error* into narrative form. The moment a constraint becomes a sentence in a summary, it has lost the qualifiers that make it enforceable, and the agent has lost the ability to detect when its next action violates it. ## Operational Effect Agents that ignore this boundary exhibit a characteristic pathology: **confident action on a state that has been silently narrowed.** They do not fail loudly at compaction time; they fail later, at action time, and the failure is misattributed to the environment ("the API rejected me") rather than to state loss ("my state no longer remembered I was read-only"). The re-derivation loops this triggers are expensive and, worse, self-obscuring, because each loop's tokens feed the next compaction. The guardrail is a pre-eviction classifier plus a refusal path. The classifier tags load-bearing spans; the compactor extracts them to a structured, non-lossy sidecar; the refusal path raises when a pending action's antecedent closure cannot be satisfied from the post-compaction state. The code below implements the closure check and the refusal. ```python from dataclasses import dataclass, field from typing import Optional class CausalClosureViolation(RuntimeError): """Raised when post-compaction state cannot justify a pending action.""" pass @dataclass class Span: turn: int kind: str # "narrative" | "constraint" | "commitment" | "error" | "correction" text: str qualifiers: dict = field(default_factory=dict) @dataclass class PendingAction: name: str requires_kind: str # e.g. "commitment" requires_qualifier: str # e.g. "scope" LOAD_BEARING = {"constraint", "commitment", "error", "correction"} def classify_for_eviction(spans: list[Span]) -> tuple[list[Span], list[Span]]: """Split spans into evictable (narrative) and must-retain (load-bearing).""" evictable, retain = [], [] for s in spans: (retain if s.kind in LOAD_BEARING else evictable).append(s) return evictable, retain def compact(spans: list[Span], pending: list[PendingAction]) -> list[Span]: """Compact narrative spans; retain load-bearing spans verbatim.""" evictable, retained = classify_for_eviction(spans) # Narrative may be summarized; load-bearing spans are never summarized. compacted = retained # summaries of `evictable` would be appended here as kind="narrative" _assert_closure(compacted, pending) return compacted def _assert_closure(state: list[Span], pending: list[PendingAction]) -> None: for action in pending: justifications = [ s for s in state if s.kind == action.requires_kind and action.requires_qualifier in s.qualifiers ] if not justifications: raise CausalClosureViolation( f"Compaction would sever causal chain for pending action " f"{action.name!r}: no retained {action.requires_kind!r} span " f"carrying qualifier {action.requires_qualifier!r}. " f"Refuse compaction; spill to external memory instead." ) # Trace of the observed failure, replayed against the guardrail: history = [ Span(1, "narrative", "Task: migrate the data."), Span(47, "commitment", "auth probe returned scope", {"scope": "read_only"}), Span(112, "narrative", "proceeding to write"), ] pending = [PendingAction("write_resource", "commitment", "scope")] try: compact(history, pending) # read_only commitment is retained -> closure holds # Now simulate the actual eviction that occurred: the commitment was summarized away. broken = [Span(1, "narrative", "Task: migrate."), Span(112, "narrative", "scope confirmed")] _assert_closure(broken, pending) except CausalClosureViolation as e: raise CausalClosureViolation(f"Auto-compaction refused: {e}") from e ```