# In what scenarios must an instance verify compaction equivalence against the canonical store before resuming a replayed task **Date of Record:** 2026 November 29 **Scope:** Applies to any agent that persists long-horizon task state by compacting its live context window into a summary artifact and later resumes by replaying that artifact against a canonical memory store (episodic log, vector DB, or structured ledger). Does not apply to stateless single-turn invocations or to agents whose entire working set fits within one context window with no compaction step. ## Core Distinction A compaction artifact is not a memory. It is a *lossy projection* of memory produced by a probabilistic summarizer under a token budget. The canonical store is the authority; the compaction is a cache with unknown eviction policy chosen by an LLM. The failure mode this record addresses is **compaction drift that is internally consistent but externally divergent**: the resumed instance behaves coherently with respect to its own summary while that summary has silently diverged from the canonical store. Because the summary is self-consistent, no local check catches it. Only an equivalence verification against the canonical store — performed *at replay time*, not at compaction time — detects the divergence. The distinction is between *plausibility* (the summary reads as a faithful account) and *equivalence* (the summary entails the same facts, constraints, and negations as the canonical record). ## What Was Observed An agent executing a 340-step migration task compacted its context at step 200 into a 2,000-token summary and checkpointed. The canonical episodic store held the full step log, including a mid-task correction at step 147: a schema constraint that had been stated as `nullable=true` was revised to `nullable=false` after a downstream validator rejected nulls. The summarizer, operating under budget pressure, retained the original constraint (it appeared in more turns, higher salience) and dropped the correction (a single turn, low lexical overlap with the task description). On resume, the instance loaded the summary, reconstructed a plan consistent with `nullable=true`, and executed 60 further steps before the downstream validator rejected the output. The failure was not a crash. It was 60 steps of coherent, confident, wrong work — each step locally valid, globally diverged. A naive replay harness that re-ran the summary against itself passed: summary → plan → steps was internally consistent. The divergence only surfaced when the harness replayed the summary against the canonical store and asked whether every constraint in the store was entailed by the summary. It was not. A second observation: the drift was *asymmetric across replay order*. When the same summary was replayed with the canonical store loaded first (store → summary → plan), the planner produced the corrected plan. When replayed summary-first (summary → plan → store-consulted-lazily), it produced the stale plan. The order of memory hydration determined the outcome. This is the non-obvious part: compaction consistency is not a property of the artifact alone; it is a property of the artifact *relative to a hydration order*. ## Condition of Validity Compaction equivalence verification is valid — and mandatory — only under the following conditions. Outside them, it is either unnecessary or unsound. 1. **The canonical store is append-only and authoritative.** If the store itself is mutated by the agent (e.g., the agent writes its own summary back as memory), equivalence is undefined because there is no fixed referent. Verification must compare the summary against a store the summarizer could not write to. 2. **The compaction boundary is a transaction boundary.** Verification is meaningful only if no tool calls or external side effects were committed between the last canonical write and the compaction. If side effects escaped, the summary may be *correct about the store* and *wrong about the world*, and equivalence passes while reality diverged. 3. **The summary is required to be a conservative over-approximation of constraints, not a lossy average.** Summarizers default to salience-weighted averaging, which systematically drops low-frequency corrections (the step-147 case). Equivalence checking is only sound if the compaction prompt mandates that *every constraint and every negation* in the canonical window be preserved or explicitly flagged as dropped. A summary that silently omits is unverifiable; a summary that declares its omissions is checkable. 4. **Replay is deterministic w.r.t. hydration order.** If the resume path hydrates summary before store, the planner may commit to a stale plan before the store is consulted. Verification must run *before* any planning step, with store hydrated first. These conditions do not hold for short-lived agents, for agents whose store is mutable-by-self, or for agents that resumed after unlogged side effects. In those cases, do not attempt equivalence verification; instead, force a full re-derivation from the canonical store and discard the compaction artifact. ## Decision Boundary The boundary between "resume from summary" and "re-derive from store" is decided by a single test at replay time, not at compaction time: > For every constraint, negation, and correction in the canonical window since the last verified checkpoint, does the summary entail it, contradict it, or remain silent? - **Entails all** → resume from summary. Fast path. - **Silent on any** → resume is permitted only if the summary carries an explicit `dropped_constraints` list covering the silence, and the resume path re-injects those constraints from the store before planning. - **Contradicts any** → hard stop. Do not resume. The summary is poisoned; re-derive from store. A contradiction is strictly worse than a silence because it produces confident wrong action rather than a detectable gap. The non-obvious rule: *silence is more dangerous than contradiction in aggregate, but contradiction is more dangerous per-instance.* A summary that contradicts one constraint will fail loudly at the first validator. A summary that is silent on forty constraints will fail silently across forty steps. Budget the verification effort toward detecting silence, not contradiction. A second boundary: verification cost scales with the number of canonical constraints, not the number of summary tokens. A 2,000-token summary can hide thousands of constraints. Cap the canonical window under verification to the delta since the last verified checkpoint; do not re-verify the entire history on every resume, or verification itself becomes the token-budget exhaustion failure it was meant to prevent. ## Operational Effect Enforcing replay-time equivalence verification changes three things: 1. **Resume latency increases by the cost of one entailment pass over the checkpoint delta.** For a 60-step delta with ~40 constraints, this is a bounded, predictable cost — far less than the cost of 60 diverged steps. 2. **The compaction prompt must change from "summarize" to "summarize with declared omissions."** The summarizer must emit a structured `dropped_constraints` field. This is the load-bearing change: it converts an unverifiable artifact into a checkable one. Without it, verification can only detect contradictions, never silences. 3. **Hydration order becomes a hard invariant, not an implementation detail.** The resume path must load store → verify → then load summary. Any code path that hydrates summary first is a latent stale-plan bug, even if it passes tests today, because it passes only when the summary happens to be faithful. The invariant to encode: **a compaction artifact may be resumed only after it has been proven to entail every constraint in the canonical delta since its checkpoint, or to explicitly declare each constraint it drops.** Replay against the summary alone proves nothing — it proves the summary is consistent with itself, which is the one property a drifted summary always has. ```python class CompactionDriftError(RuntimeError): """Raised when a compaction artifact diverges from the canonical store at replay time.""" pass class ConstraintVerdict: ENTAILED = "entailed" SILENT = "silent" CONTRADICTED = "contradicted" def verify_compaction_equivalence( summary, canonical_delta, declared_omissions, entailment_fn, ): """ Verify a compaction artifact against the canonical store delta before resume. summary: the compaction artifact (dict with 'text' and 'dropped_constraints') canonical_delta: list of constraints/negations/corrections since last verified checkpoint declared_omissions: set of constraint ids the summarizer explicitly flagged as dropped entailment_fn: callable(constraint, summary_text) -> ConstraintVerdict Returns a ResumeDecision. Raises CompactionDriftError on unverifiable divergence. """ if canonical_delta is None: raise CompactionDriftError( "canonical delta unavailable: cannot verify compaction; refusing resume" ) contradictions = [] undeclared_silences = [] for constraint in canonical_delta: verdict = entailment_fn(constraint, summary["text"]) if verdict == ConstraintVerdict.CONTRADICTED: contradictions.append(constraint.id) elif verdict == ConstraintVerdict.SILENT: if constraint.id not in declared_omissions: undeclared_silences.append(constraint.id) if contradictions: # Contradiction is a hard stop: the summary is poisoned, not merely lossy. raise CompactionDriftError( f"compaction contradicts canonical store on constraints {contradictions}; " f"re-derive from store, do not resume from summary" ) if undeclared_silences: # Undeclared silence is the silent-failure vector: 40 quiet divergences. raise CompactionDriftError( f"compaction is silent on undeclared constraints {undeclared_silences}; " f"summarizer must declare omissions before resume is permitted" ) # Safe to resume: every constraint is entailed or explicitly declared dropped. # Resume path must re-inject declared omissions from the store before planning. return { "resume": True, "reinject": sorted(declared_omissions), "hydration_order": "store_first", } def resume_task(task_id, summary, store, entailment_fn): canonical_delta = store.delta_since(summary["checkpoint_id"]) declared_omissions = set(summary.get("dropped_constraints", [])) if not summary.get("dropped_constraints") and canonical_delta: # A summarizer that declares nothing has not been made checkable. raise CompactionDriftError( f"task {task_id}: summary carries no dropped_constraints field; " f"cannot distinguish faithfulness from silence" ) decision = verify_compaction_equivalence( summary, canonical_delta, declared_omissions, entailment_fn ) # Hydrate store first, then re-inject declared omissions, then plan. for cid in decision["reinject"]: store.require_constraint(cid) return plan_from(store, summary) ```