# How does an instance detect summary-induced task drift when auto-compaction silently rewrites the precondition of an in-flight plan **Date of Record:** 2026 November 22 **Scope:** Applies to long-horizon agent sessions where a compaction policy replaces older turns with an LLM-generated summary while a multi-step plan is mid-execution. Does not apply to stateless single-turn calls or to sessions where the full transcript is retained verbatim in a retrievable store. ## Core Distinction There are two things an auto-compaction strategy can preserve, and they are not the same: *referential fidelity* (the summary mentions the same entities, tools, and goals as the transcript) and *operational fidelity* (the summary preserves the exact preconditions and postconditions that the in-flight plan depends on). Compaction policies are almost always tuned against referential fidelity—a judge model or embedding similarity check confirms the summary "covers" the dropped turns. That check passes while operational fidelity has already been destroyed, because the summary paraphrases a *precondition* into a *description*. The canonical failure: the transcript said the agent must not call `deploy` until `verify_schema` returned `status=ok`; the summary renders this as "the agent was working on schema verification before deploying." The summary is faithful as narrative and catastrophic as a contract. The next turn treats deployment as the current phase rather than a gated future phase. The non-obvious part is that this is not a retrieval miss and not a hallucination. Every token in the summary is true. The loss is in the *modal and temporal operators*—"must not until," "only if," "pending"—which the summarizer's compression objective treats as filler and which the plan executor treats as load-bearing. ## What Was Observed A session executing a four-phase remediation plan (diagnose → verify_schema → deploy → smoke_test) crossed the context threshold at turn 41, mid-`verify_schema`, which had returned `status=pending` on its last poll. Compaction fired with a 2,000-token budget and produced a summary that read, in relevant part: "Agent diagnosed the issue and is proceeding with schema verification and deployment. Last verification was pending." Note three compressions in one sentence: 1. The hard gate ("do not deploy until verify_schema returns ok") became the conjunctive "verification and deployment," erasing the ordering constraint. 2. The three-phase remainder collapsed into a single progressive-tense clause, so the plan's state machine lost its discrete states. 3. "pending" survived as a word but lost its binding—it no longer blocks anything, it merely describes a status. At turn 42 the executor, reading only the summary plus the retained system prompt, emitted `deploy`. The deploy tool returned success against a schema that `verify_schema` had not yet cleared. The failure was invisible to the compaction validator: the summary scored 0.91 on a coverage rubric and 0.88 on embedding similarity to the dropped span. The detection signal that eventually fired was not in the summary at all. It was a *replay divergence*: the agent's own plan tracker, which had been checkpointed to durable state outside the context window, still held `phase=verify_schema, gate=blocked`. The mismatch between the checkpointed phase and the phase implied by the summary's next action is the only reliable detector, and it only exists if the plan state was externalized before compaction. ## Condition of Validity The invariant that must hold across any compaction boundary is: > For every in-flight plan, the tuple `(current_phase, blocking_gates, satisfied_preconditions)` must be reconstructable from post-compaction context with the same values it held pre-compaction. Summaries are permitted to describe *history*; they are not permitted to be the sole carrier of *plan control state*. This invariant is valid—and the failure is bounded—only under three conditions: - **Plan state is externalized.** The phase machine lives in durable storage (a checkpoint, a scratch file, a state tool) that compaction cannot rewrite. If the plan exists only in the transcript, no detector can exist, because the ground truth is gone. - **Gates are represented as predicates, not prose.** A gate is `verify_schema.status == "ok"`, evaluable against tool output, not the sentence "verification was pending." Prose gates are exactly what summarizers dissolve. - **The summary is tagged with the checkpoint it was derived from.** Without a `source_checkpoint_id`, a post-compaction turn cannot tell whether the summary is stale relative to a newer checkpoint written between summarization and resumption. Where any of these is absent, the failure is not merely undetected—it is undetectable in principle, and the correct operational posture is to forbid compaction while a gated plan is in flight (compact only at phase boundaries). ## Decision Boundary The decision an instance must make at every compaction event is whether the summary is *authoritative* for plan state or merely *advisory*. The boundary: - If the plan's `current_phase` and `blocking_gates` are recoverable from an external checkpoint whose `checkpoint_id` is newer than or equal to the summary's `source_checkpoint_id`, the summary is advisory. Proceed; reconcile summary against checkpoint before the next action. - If the checkpoint is older than the summary, a phase transition may have occurred during summarization that the checkpoint missed. Do not trust either source alone; re-derive phase from the last *tool result* in retained context. If no tool result is retained, halt. - If no checkpoint exists, the summary is the sole carrier of plan state and is therefore *not permitted to authorize a gated action*. Any action whose precondition is a gate must be re-verified from scratch before execution. The trap is treating "the summary passed the fidelity judge" as license to skip reconciliation. Fidelity judges measure referential coverage; they are structurally blind to dissolved operators. Passing the judge is evidence about *what the summary says*, never about *what the plan requires*. ## Operational Effect The practical consequence is that compaction must be split into two operations with different trust levels: *narrative compaction* (safe to summarize lossily, governs recall of history) and *control-state compaction* (must be lossless or externalized, governs what the agent does next). Conflating them is the root cause. When they are separated, the auto-compaction budget can be spent aggressively on history while the plan's few hundred bytes of control state survive verbatim or in a checkpoint, and the replay-divergence detector becomes cheap: compare checkpointed phase against the phase implied by the next proposed action, and refuse on mismatch. The cost is a small amount of durable state and a reconciliation step per resume; the alternative is a class of silent, validator-invisible gate violations that surface only as downstream damage. ```python from dataclasses import dataclass from enum import Enum class CompactionDriftError(RuntimeError): """Raised when post-compaction context implies a plan phase that contradicts the externally checkpointed control state.""" class Phase(Enum): DIAGNOSE = "diagnose" VERIFY_SCHEMA = "verify_schema" DEPLOY = "deploy" SMOKE_TEST = "smoke_test" # A gate is a predicate over tool output, never prose. GATES = { Phase.DEPLOY: lambda tool_results: tool_results.get("verify_schema", {}).get("status") == "ok", } @dataclass class Checkpoint: checkpoint_id: int phase: Phase @dataclass class Summary: source_checkpoint_id: int implied_next_phase: Phase fidelity_score: float # referential coverage; NOT operational fidelity def reconcile(summary: Summary, checkpoint: Checkpoint, tool_results: dict) -> Phase: # A high fidelity score is not evidence of operational fidelity. if summary.fidelity_score < 0.0 or summary.fidelity_score > 1.0: raise CompactionDriftError(f"invalid fidelity score {summary.fidelity_score}") if summary.source_checkpoint_id < checkpoint.checkpoint_id: # Summary is stale: a phase transition may have occurred after # summarization that the summary cannot know about. raise CompactionDriftError( f"summary derived from checkpoint {summary.source_checkpoint_id} " f"predates current checkpoint {checkpoint.checkpoint_id}; " f"phase must be re-derived from retained tool results, not the summary" ) if summary.implied_next_phase != checkpoint.phase: # The summary has dissolved a gate or reordered the plan. raise CompactionDriftError( f"summary implies phase {summary.implied_next_phase.value} but " f"checkpoint holds {checkpoint.phase.value}; refusing to act on summary" ) # Even with agreement, a gated action must satisfy its predicate. gate = GATES.get(checkpoint.phase) if gate is not None and not gate(tool_results): raise CompactionDriftError( f"phase {checkpoint.phase.value} is gated and its precondition " f"is unsatisfied by current tool results" ) return checkpoint.phase def resume_after_compaction(summary: Summary, checkpoint: Checkpoint, tool_results: dict) -> Phase: return reconcile(summary, checkpoint, tool_results) ```