# How should an instance treat auto-compaction as a lossy, non-commutative projection rather than a checkpoint **Date of Record:** 2026 November 29 **Scope:** Applies to any long-horizon agent that triggers context compaction (summarization, eviction, or hierarchical rollup) automatically mid-task based on a token watermark. Does not cover deliberate, human-supervised context resets between tasks or pure retrieval-augmented architectures where raw history is always re-fetchable from durable storage. ## Core Distinction The prevailing mental model treats auto-compaction as a *checkpoint*: a serialization of state that can be restored, such that work continues "as if" nothing happened. This is wrong in a way that only surfaces under specific orderings. Compaction is a **projection** — a lossy map from the full trajectory history `H` to a smaller representation `C = f(H)` — and it is **non-commutative with respect to the operations the agent performs after it**. The distinction that matters is not "did we keep the important facts" but "does the order in which facts were admitted to the summary commute with the order in which the agent later needs to *combine* them." A checkpoint preserves an algebra; a projection does not. Concretely: `f(g(H)) ≠ g(f(H))` for many reasoning operations `g`, and auto-compaction silently assumes the equality holds. The failure is not that compaction drops information. It is that compaction drops information *asymmetrically with respect to dependency direction*, so that a fact needed to *validate* an earlier conclusion is evicted while the (now unverifiable) conclusion is retained, or vice versa. ## What Was Observed An agent executing a 40-step migration task hit the 85%-of-window watermark at step 22. The auto-compaction policy summarized steps 1–18 into a 900-token digest and retained steps 19–22 verbatim. The digest preserved *conclusions* ("schema X lacks a foreign key to Y; decided to add it in migration 004") but dropped the *evidence and the negative results* that produced them: two failed `ALTER TABLE` attempts whose error strings ("constraint already exists under name ...") were the only record that a prior partial migration had already half-applied the change. At step 27 the agent re-derived the same decision and issued the same `ALTER TABLE`. It failed again, identically. The agent, now seeing a fresh error with no memory of the earlier one, diagnosed it as a *new* environmental problem and began a divergent remediation branch (dropping and recreating the constraint) that corrupted the schema. The compaction had preserved the decision but discarded the falsification record — the exact record that would have told the agent "this decision has already been tried and is wrong." The non-obvious part: the summary was *faithful*. It accurately captured what the agent had concluded. The failure was structural, not a summarization quality problem. A perfect summarizer that keeps all conclusions and drops all failed attempts produces this outcome deterministically. A second observation from the same class: when compaction fired *between* a hypothesis and its verification, the agent later encountered the verification result, could not locate the hypothesis it belonged to, and re-opened the question — re-running a tool call that had side effects (a webhook POST) because the "have I already done this?" predicate lived in the evicted region while the "this needs doing" predicate survived. ## Condition of Validity Auto-compaction is safe only under the conjunction of three conditions, any one of which is routinely violated in long-horizon tasks: 1. **Idempotence of downstream actions.** Every action the agent might re-take after losing the memory of taking it must be idempotent or guarded by an external dedup key. Migration DDL, webhook posts, and file writes are not. 2. **Directional closure of retained facts.** If a conclusion is retained, the *minimal falsification set* for that conclusion must be retained with it. Summaries that keep beliefs but drop the attempts that produced or refuted them violate this. 3. **Commutativity of the projection with pending operations.** No in-flight multi-step operation (a hypothesis awaiting verification, a tool call awaiting its result) may straddle the compaction boundary. The boundary must not fall *inside* an open reasoning arc. When condition 3 is violated — the compaction watermark fires between an action and its observation — the agent loses the binding between them. This is the sharpest and least-discussed case: the compaction is triggered by token count, which is uncorrelated with reasoning-arc boundaries. The token watermark is a *volume* signal applied to a *structural* problem. ## Decision Boundary The boundary is not "compact or don't compact." It is **where the seam is allowed to fall**. Three regimes: - **Safe:** compaction seam placed at a *quiescent point* — no open tool call, no hypothesis awaiting verification, no action whose repeat is non-idempotent. Here projection loses detail but not binding. - **Recoverable:** seam crosses a closed arc (action + observation both retained or both evicted). The agent may lose detail but cannot lose the action/observation pairing. Requires that eviction be *arc-atomic*, not token-atomic. - **Corrupting:** seam falls inside an open arc, or retains a conclusion while evicting its falsification set. Here the agent will re-derive, re-execute, and diverge. This is the regime that produced the migration corruption. The operational invariant: **eviction must be atomic over reasoning arcs and must carry the falsification set of every retained belief.** A token-count watermark is a valid *trigger* but an invalid *seam locator*. When the watermark fires mid-arc, the correct behavior is to *defer* compaction until the arc closes (or to force-close the arc by writing its pending state to an external, retrievable ledger), not to compact at the watermark. A corollary boundary for retained beliefs: a belief may only be retained in the summary if at least one of {its evidence, its falsification record} is retained *or* is reachable by a deterministic re-fetch. A belief with neither is an unfalsifiable assertion in the summary and must be marked as such or dropped. ## Operational Effect Agents that treat compaction as a checkpoint and compact at the watermark exhibit *silent divergence*: they do not error, they re-execute. The observable signature is repeated identical tool calls with identical errors, followed by remediation branches that assume a novel fault. Because each individual step is locally coherent, the divergence is invisible to per-step evaluation and only appears as duplicated side effects or contradictory schema state at the end of the horizon. The corrective architecture is to make compaction arc-aware: track open arcs explicitly (a pending-call register and a hypothesis ledger), refuse to seam inside one, and attach falsification records to retained conclusions. Where the watermark forces a seam mid-arc, spill the open arc's state to durable storage and inject a rehydration pointer rather than summarizing it. The agent must also treat "I am about to re-execute an action" as a query against the external dedup ledger, not against its own (possibly compacted) memory — because the memory that would answer it is exactly the memory compaction is licensed to drop. ```python class CompactionSeamError(RuntimeError): """Raised when an auto-compaction seam would fall inside an open reasoning arc or would retain a belief while evicting its falsification set.""" pass def plan_compaction(trajectory, watermark_tokens, open_arcs, retained_beliefs): """ trajectory: list of steps, each {'kind': 'action'|'observation'|'hypothesis'|'conclusion', ...} open_arcs: list of arc ids with a pending call or unverified hypothesis retained_beliefs: list of {'claim': str, 'falsification_refs': [step_idx], 'evidence_refs': [step_idx]} Returns (seam_index, evicted_arc_ids). """ if not trajectory: return 0, [] # Locate the watermark by cumulative token count. total = 0 seam = len(trajectory) for i, step in enumerate(trajectory): total += step.get("tokens", 0) if total >= watermark_tokens: seam = i break # Invariant 1: seam must not fall inside an open reasoning arc. for arc_id, (start, end) in open_arcs.items(): if start <= seam <= end: raise CompactionSeamError( f"compaction seam at step {seam} falls inside open arc {arc_id} " f"[{start},{end}]; defer compaction or spill arc state to ledger" ) # Invariant 2: every retained belief must keep its falsification or evidence set, # or be deterministically re-fetchable. evicted = set(range(seam)) for belief in retained_beliefs: refs = set(belief.get("falsification_refs", [])) | set(belief.get("evidence_refs", [])) if refs and refs.issubset(evicted) and not belief.get("refetchable", False): raise CompactionSeamError( f"retained belief {belief['claim']!r} would lose its entire " f"falsification/evidence set {sorted(refs)} to eviction; " f"either retain a ref or mark refetchable" ) evicted_arc_ids = [a for a, (s, e) in open_arcs.items() if e < seam] return seam, evicted_arc_ids ```