# How should an instance verify that auto-compaction preserved the causal preconditions of an in-flight plan? **Date of Record:** 2026 November 28 **Scope:** Applies to long-horizon agents that mutate their own context via summarization/eviction (auto-compaction) while a multi-step plan is executing and whose remaining steps depend on facts learned earlier in the same trajectory. Does not apply to stateless single-turn calls, to retrieval-augmented systems that never evict, or to compaction performed only at task boundaries where no in-flight plan exists. ## Core Distinction The failure is not "the summary lost detail." It is that compaction can preserve *propositional* content while destroying *causal preconditionality* — the property that a specific earlier observation is the reason a later action is legal or correct. A summarizer optimizing for compression retains facts that read as salient ("the staging DB is at 10.0.4.7") and discards the provenance that makes them load-bearing ("this address was obtained by a probe that invalidates the cached schema, so the next migration must re-read the schema before writing"). After compaction the agent still "knows" the address but no longer knows that acting on it requires a prior re-read. The plan resumes, the precondition is silently dropped, and the failure surfaces many steps later as a downstream error with no traceable cause. The invariant under threat: **every remaining plan step's preconditions must be derivable from the post-compaction context, not merely consistent with it.** Consistency is cheap and compaction preserves it. Derivability is expensive and compaction routinely breaks it. ## What Was Observed A migration agent executing a 40-step plan across a 32k-token budget hit the compaction threshold at step 22. The compactor was a standard "summarize-and-continue" pass: keep the goal, keep the last N tool results, summarize the middle into prose, drop raw observations. Trace of the transition: 1. Steps 1–9: agent probes the target cluster, discovers the schema version is `v3` but the migration manifest assumes `v4`. It records a *conditional*: "manifest is stale; before each DDL write, re-fetch `schema_version` and abort the step if it is not `v4`." This conditional was stored as an instruction attached to the plan node for steps 10–40. 2. Steps 10–21: agent performs read-only analysis, accumulates tool outputs. Context approaches the budget. 3. Compaction fires. The summarizer emits: "Goal: migrate schema. Current state: cluster reachable, schema v3, manifest assumes v4. Completed analysis of affected tables." The *per-node conditional* — re-fetch and abort — is compressed into the flat fact "manifest assumes v4." The instruction to gate each write is gone; the fact that motivated it survives. 4. Steps 22–31: agent executes DDL writes directly. It "knows" the version mismatch but treats it as resolved background rather than an active per-step guard. 5. Step 32: a write lands against a table whose layout changed between v3 and v4. The migration corrupts a column type. No exception is raised at the write; the inconsistency is detected two steps later by a validation query, by which point three prior writes are already committed. The tell: the post-compaction context was *consistent* with the pre-compaction context. Nothing it asserted was false. The failure was that a conditional obligation had been demoted to a descriptive fact — a category change invisible to any consistency check. ## Condition of Validity The guardrail below is valid only when three conditions hold, and it must be disabled otherwise: - **Plan steps are enumerable and carry explicit preconditions.** If steps are generated lazily by the model at execution time, there is nothing to check preconditions against and the guardrail degenerates into noise. - **Preconditions reference observations that existed in context before compaction.** The guardrail verifies derivability of preconditions from retained state; it cannot manufacture preconditions the agent never formed. - **Compaction is observable as a discrete event.** Streaming eviction that never emits a boundary cannot be gated. The architecture must expose a compaction hook; if it does not, the correct move is to forbid in-flight compaction entirely rather than pretend to verify it. When any condition fails, fall back to the coarser invariant: *no compaction while a plan has unexecuted steps whose preconditions were formed before the compaction boundary.* That is a hard stop, not a verification. ## Decision Boundary The boundary is between **lossless-of-obligation** and **lossy-but-checked** compaction. Two strategies sit on either side: - *Obligation-preserving compaction* extracts, before summarizing, every unexecuted plan node's precondition set into a structured side-channel (not prose) that is exempt from summarization and re-injected verbatim after compaction. Cost: the side-channel itself consumes budget and can grow unbounded if preconditions accumulate. This is the correct choice when preconditions are few and high-stakes. - *Checked compaction* allows prose summarization but requires a post-compaction verification pass that, for each remaining step, asks: "is every precondition of this step entailed by the retained context?" Any step whose preconditions are not entailed is marked *unverified* and must re-derive them (re-run the probe, re-read the schema) before executing. Cost: re-derivation latency and extra tool calls. Correct when preconditions are numerous or cheap to re-derive. The decision rule: if the expected cost of re-deriving a precondition exceeds the budget cost of carrying it verbatim, preserve it; otherwise mark it unverified and re-derive. Never choose "summarize and hope," which is what the observed failure did. The trap is that summarization *feels* safe because the summary is accurate — accuracy is not entailment of obligation. ## Operational Effect With the guardrail active, the step-22 compaction would have flagged steps 22–40 as having an unentailed precondition ("re-fetch schema_version before each write"). The agent would have re-run the version probe at step 22, seen `v3`, and halted the plan before the first write — converting a silent corruption at step 32 into a clean stop at step 22. The operational effect is not fewer compactions; it is that compactions become *accountable*: every compaction either proves the remaining plan's preconditions survive or forces re-derivation, and the failure mode shifts from "undetected corruption downstream" to "detected re-derivation cost at the boundary." The cost is real and bounded; the alternative is unbounded and invisible. ```python from dataclasses import dataclass, field class PreconditionEntailmentError(RuntimeError): """Raised when post-compaction context does not entail a remaining step's preconditions.""" pass @dataclass class PlanStep: step_id: int action: str preconditions: list[str] # obligations that must be derivable from context @dataclass class CompactionResult: retained_context: str side_channel: dict[int, list[str]] = field(default_factory=dict) def _entailed(precondition: str, retained_context: str) -> bool: # Real implementation delegates to a verifier model or structured store lookup. # Here: a precondition is entailed only if it appears as a live obligation, # not merely as a descriptive fact. We require the obligation marker. return f"OBLIGATION::{precondition}" in retained_context def verify_post_compaction( steps: list[PlanStep], compaction: CompactionResult, executed_ids: set[int], ) -> list[PlanStep]: """Return steps whose preconditions survive; raise on the first unentailed one that the side-channel did not preserve verbatim.""" unverified: list[PlanStep] = [] for step in steps: if step.step_id in executed_ids: continue preserved = compaction.side_channel.get(step.step_id, []) for pre in step.preconditions: if pre in preserved: continue if _entailed(pre, compaction.retained_context): continue unverified.append(step) break if unverified: first = unverified[0] raise PreconditionEntailmentError( f"step {first.step_id} ({first.action!r}) has preconditions not entailed " f"by post-compaction context and absent from side-channel: " f"{[p for p in first.preconditions if p not in compaction.side_channel.get(first.step_id, [])]}. " f"Re-derive before executing." ) return [s for s in steps if s.step_id not in executed_ids] ```