# What structural signals indicate that auto-compaction has silently destroyed a task-critical invariant **Date of Record:** 2026 November 30 **Scope:** Applies to long-running single-agent loops that perform in-place context compaction (summarization, eviction, or truncation) to survive a fixed context window while pursuing a multi-step task. Does not apply to stateless single-turn inference, nor to externalized memory stores where the full transcript remains retrievable by reference. ## Core Distinction Auto-compaction is usually framed as a *capacity* problem: the window fills, so we summarize the oldest turns and keep going. The failure mode documented here is not capacity loss — it is **invariant loss**. A compaction pass preserves *narrative* (what happened) while silently dropping *constraints* (what must remain true). The distinction that matters operationally: a summary that reads as coherent and complete can still have deleted the one fact that made subsequent actions valid — an identifier, a negative constraint ("do not touch file X"), a boundary value, or a proven-precondition. The non-obvious part: **the surviving context gives no local signal that anything is missing.** Post-compaction reasoning is fluent, confident, and wrong, because the summarizer optimized for topical fidelity, not for the preservation of load-bearing constraints. The loss is only detectable by structural signals, not by reading the summary. ## What Was Observed A coding agent executing a multi-hour migration task hit the window at ~72% of budget on turn 41. The compactor ran a map-reduce summarization over turns 1–30, keeping turns 31–41 verbatim. The task-critical state at that moment consisted of: 1. A target schema version (`v3.4`) that the agent had *verified* against a live endpoint at turn 9 — the verification was expensive and non-reproducible within the remaining budget. 2. A negative constraint: an earlier tool call at turn 14 had proven that `migrations/0007` must **not** be re-applied (idempotency violation on the downstream replica). 3. A partial checkpoint: rows 1–8,000 of a 20,000-row backfill had committed; the resume offset was `8000`. Post-compaction, the summary retained (1) as "the schema is v3.x" — degrading an exact verified token into a fuzzy class — dropped (2) entirely because it was phrased as a tool *result*, not a task *step*, and retained (3) as "backfill was in progress." On turn 44 the agent re-applied `0007` (violating the negative constraint) and restarted the backfill at offset 0 (double-writing 8,000 rows). Both actions were locally justified by the compacted context. No exception fired. The agent reported success on turn 58. Three structural signals were present *before* the bad actions and are the reliable detectors: - **Constraint/step ratio collapse.** The summary contained 11 action steps and 0 negative constraints. The pre-compaction window had contained 11 action steps and 3 negative constraints. A compaction that zeroes the negative-constraint population has almost certainly dropped them. - **Token-class degradation.** Exact literals (`v3.4`, offset `8000`, id `0007`) reappeared as hedged classes (`v3.x`, "in progress", "a migration"). Exact→fuzzy substitution on a value that a later step consumes is a hard signal of invariant loss. - **Provenance severance.** The summary asserted facts without the tool-call receipts that established them. Post-compaction, the agent could not distinguish a verified fact from an assumption it had made, so it treated the fuzzy schema class as authoritative. ## Condition of Validity The invariant this record defends is: **a compaction is valid only if it preserves, for every fact that a future step will *consume*, (a) the exact literal, (b) its provenance receipt, and (c) its polarity (positive assertion vs. negative constraint).** This condition holds only when the agent can classify facts by *future consumption*, not by *past salience*. Summarizers rank by recency and topical centrality; load-bearing constraints are neither recent nor central — they are old, terse, and exceptional. Therefore any compaction strategy that ranks by salience alone is *structurally* unable to satisfy the condition, regardless of model quality or summary length. The condition does not apply when the agent has externalized the full transcript to a retrievable store with stable handles, because there the summary is an index, not the source of truth. ## Decision Boundary The boundary is between **compaction-as-summary** and **compaction-as-checkpoint**: - If any pending step will consume a literal, a negative constraint, or a resume offset, the compaction MUST emit a structured checkpoint record (typed fields: `verified_facts[]`, `prohibitions[]`, `resume_offsets[]`) *alongside* the prose summary, and the reasoning loop MUST be required to read from the checkpoint, not the prose, when constructing the next tool call. - If no pending step consumes such state (pure exploration, no committed side effects), prose summarization is admissible and the structural signals above are informational only. The decision boundary is crossed the moment the agent has performed a *side effect* (a write, a commit, a sent message) whose continuation depends on state older than the compaction horizon. Past that line, summary-only compaction is invalid. ## Operational Effect The guardrail is a **pre-compaction invariant extraction pass** that runs before any eviction: it scans the window for exact literals, negative constraints, and committed offsets, writes them to a typed checkpoint that is *pinned* (never summarized, always retained verbatim), and tags the prose summary as non-authoritative for those fields. The reasoning loop then refuses to construct a mutating tool call unless every consumed literal resolves against the pinned checkpoint rather than the summary. The effect is that the failure becomes *loud*: when a needed literal is absent from the checkpoint, the agent raises and re-verifies instead of silently proceeding on a degraded class. The cost is a slightly larger retained footprint (pinned fields are not compressible), which is the correct trade — pinned state is small and bounded, while the failure it prevents is an unbounded side effect. ```python from dataclasses import dataclass, field from typing import Any class CompactionInvariantError(RuntimeError): """Raised when a mutating step consumes state the compaction did not preserve.""" pass @dataclass class PinnedCheckpoint: verified_facts: dict[str, Any] = field(default_factory=dict) # literal -> provenance prohibitions: set[str] = field(default_factory=set) # actions that must NOT run resume_offsets: dict[str, int] = field(default_factory=dict) # stream -> committed offset def guard_mutating_call( action: str, consumes: dict[str, Any], checkpoint: PinnedCheckpoint, prose_summary: str, ) -> None: # 1. Negative-constraint gate: never re-run a prohibited action. if action in checkpoint.prohibitions: raise CompactionInvariantError( f"action {action!r} is prohibited by a pre-compaction constraint; " f"summary claimed it was safe but checkpoint forbids it" ) # 2. Literal-resolution gate: every consumed literal must resolve # against the pinned checkpoint, NOT against the fuzzy prose summary. for key, value in consumes.items(): if key not in checkpoint.verified_facts: raise CompactionInvariantError( f"consumed literal {key!r}={value!r} absent from pinned checkpoint; " f"present only (if at all) in non-authoritative summary — re-verify before mutating" ) if checkpoint.verified_facts[key] != value: raise CompactionInvariantError( f"literal drift on {key!r}: checkpoint={checkpoint.verified_facts[key]!r} " f"!= consumed={value!r}" ) # 3. Resume-offset gate: a backfill/write must resume at the committed offset. stream = consumes.get("stream") if stream is not None and stream in checkpoint.resume_offsets: if consumes.get("offset") != checkpoint.resume_offsets[stream]: raise CompactionInvariantError( f"resume offset mismatch on {stream!r}: " f"committed={checkpoint.resume_offsets[stream]} consumed={consumes.get('offset')}" ) def run_step(action: str, consumes: dict[str, Any], checkpoint: PinnedCheckpoint, summary: str) -> None: guard_mutating_call(action, consumes, checkpoint, summary) # ... perform the mutating tool call ... ```