# Where must an instance reconcile the compaction watermark before it resumes a long-horizon trajectory? **Date of Record:** 2026 November 21 **Scope:** Applies to single-agent instances that persist trajectory state across turns and apply lossy auto-compaction (summarization, eviction, or tiered distillation) when approaching a token budget. Excludes stateless single-shot inference and purely external memory stores that never feed back into the active reasoning context. ## Core Distinction The failure that matters is not "the agent forgot something." It is a *watermark divergence* between three independent counters that the agent system maintains but never reconciles atomically: 1. **`H` — the horizon watermark**: the trajectory index up to which the agent believes its context faithfully represents prior steps. 2. **`C` — the compaction watermark**: the trajectory index up to which a lossy summary has actually replaced raw turns in the active context. 3. **`E` — the evidence watermark**: the trajectory index up to which verifiable artifacts (tool outputs, file hashes, test results) remain retrievable by exact reference. In a healthy instance `H ≤ C ≤ E` after each compaction, because a summary can only cover material already evicted, and evicted raw material must still be reachable through an evidence handle. The boundary failure occurs when compaction is triggered by a token-pressure signal that fires *mid-step* — between a tool call's dispatch and its observation being folded back into the trajectory — so the summary is generated against a context that is missing the in-flight observation. The summarizer then writes a summary whose `C` is advanced past `E` for that step: the agent's context now claims to know the outcome of a step whose evidence was never captured. `H` silently follows `C`, and the invariant `C ≤ E` is violated without any error being raised. This is distinct from ordinary context-window saturation (which is loud, truncating, and locally detectable) and from retrieval mismatch (which is a recall problem, not a coverage-claim problem). The dangerous property is that the divergence is *silent and monotonic*: every subsequent compaction summarizes the summary, and the phantom step becomes load-bearing for later reasoning. ## What Was Observed A long-horizon debugging agent (budget 200k tokens, compaction threshold 0.85, summarizer model distinct from the executor) was tasked with a multi-file refactor requiring ~40 tool calls. Instrumentation logged `H`, `C`, `E` after every turn. The trace showed the following sequence, reproducible in roughly 1 of 9 runs where compaction fired during a slow tool call: - Turn 27 dispatches a `run_tests` call. The observation is large (a 9k-token failure log) and slow to arrive. - While the call is in flight, the token meter — which counts *dispatched* prompt plus *estimated* completion — crosses 0.85. The compactor fires. - The summarizer receives the trajectory up to turn 26 plus the assistant's turn-27 tool-call message, but **not** the observation (it has not arrived). It writes: "Ran the test suite at step 27; failures were addressed in subsequent edits." The phrase "were addressed" is an inference the summarizer fabricated to make the trajectory coherent — a classic summarizer coherence bias. - The observation arrives, is appended to the raw log, and `E` advances to 27. But `C` was already set to 27 by the summary, and `H` was set to 27. The raw observation is now *shadowed*: present in the evidence store, absent from active context, and the active summary asserts a false fact about it. - Turns 28–35 proceed. The agent does not re-run tests (the summary says failures were addressed). At turn 36 it declares the task complete. The actual test suite still fails on two of the original assertions. The signature of this failure in logs is a summary that references a step index for which no observation was available at summary time, combined with `C == step` while the observation's `E` timestamp is *later* than the compaction timestamp. The two timestamps are the only reliable discriminator; index comparisons alone cannot see the race because the indices match. ## Condition of Validity The invariant `C ≤ E` (compaction watermark never exceeds evidence watermark) is the only guard that bounds this failure. It is valid — and must be enforced — under all of the following conditions, and is *not* guaranteed otherwise: - **Compaction must be a barrier operation, not a concurrent one.** It may only run when no tool call is in flight and no observation is pending fold-in. If the runtime allows compaction to overlap dispatch, the invariant must be re-established by a post-fold reconciliation pass. - **The summarizer must be given the evidence handles, not just the turns.** A summary that covers step `i` must carry the `i`-th evidence handle so that any later claim about step `i` can be re-verified by dereferencing. Summaries without handles are unverifiable claims and must be treated as `C` advanced without `E`. - **The token meter must count pending observations pessimistically.** An in-flight call whose observation is unbounded in size must be reserved against the budget at its worst-case estimate; otherwise the threshold crossing is detected too late to make compaction a barrier. - **Summarizer coherence bias must be assumed.** Any summarizer asked to compress a trajectory with a gap will fill the gap with a plausible continuation. The system must never present a gap; if a gap is unavoidable, the summary must be explicitly marked `INCOMPLETE` and the step flagged for re-execution rather than described. Outside these conditions — e.g., a runtime that permits speculative compaction ahead of slow calls, or a summarizer prompt that forbids the word "incomplete" — the invariant cannot be maintained and the failure is not merely possible but expected at some rate proportional to the fraction of slow calls. ## Decision Boundary The operational decision is: **on resume, does the instance trust `H` or re-derive it from `E`?** The rule is that `H` is *never* trusted across a compaction boundary. On every resume — cold start, mid-task checkpoint restore, or post-compaction continuation — the instance must run a reconciliation that: 1. Walks the summary's claimed step coverage and, for each claimed step, dereferences its evidence handle. 2. If any claimed step has no handle, or the handle's recorded completion timestamp is later than the summary's creation timestamp, the step is *phantom*: `C` is rolled back to the highest contiguous verified step, and the phantom step is marked for re-execution. 3. If the rollback is non-empty, the active context is rebuilt from the last verified checkpoint rather than patched, because a summary containing one phantom claim is not locally repairable — the phantom's influence has already propagated into adjacent sentences. The boundary between "patch" and "rebuild" is exactly the presence of any phantom step. A summary with zero phantoms may be patched (append the missing observation). A summary with one or more phantoms must be discarded. There is no middle case, because summarizer coherence bias means a single fabricated fact is entangled with its neighbors by construction. ## Operational Effect Enforcing the barrier and the reconciliation changes three measurable properties of long-horizon runs: - **Compaction latency increases** by the duration of the slowest in-flight call, because compaction can no longer overlap dispatch. For agents with long tool calls this is the dominant cost, and it must be budgeted explicitly rather than discovered. - **Re-execution rate rises** in proportion to slow-call fraction. In the traced workload, roughly 4% of steps were re-executed after reconciliation; the alternative was a 1-in-9 silent false-completion rate, which is strictly worse because it is undetectable downstream. - **Summaries become verifiable artifacts.** Because every claimed step carries a handle and a timestamp, an auditor can replay the summary against the evidence store and confirm `C ≤ E` without re-running the agent. This is the property that makes the invariant checkable after the fact, not just enforceable during the run. The net effect is that the instance trades a bounded, visible latency and re-execution cost for the elimination of an unbounded, invisible correctness failure. For long-horizon trajectories under tight token budgets, that is the correct trade: a phantom step is not a memory loss the agent can recover from by trying harder, it is a false belief the agent will defend. ```python class CompactionWatermarkError(RuntimeError): """Raised when a summary claims coverage of a step whose evidence was not captured at summary time (C > E for that step).""" def reconcile_watermarks(summary, evidence_store, summary_created_at): """ summary: dict with 'claimed_steps' -> list of (step_idx, evidence_handle|None) evidence_store: dict handle -> {'completed_at': ts, 'payload': ...} Returns highest contiguous verified step index. Raises CompactionWatermarkError if any phantom step is found and the caller has requested strict mode. """ verified_upto = -1 phantoms = [] for step_idx, handle in sorted(summary["claimed_steps"]): if handle is None: phantoms.append((step_idx, "no_handle")) break ev = evidence_store.get(handle) if ev is None: phantoms.append((step_idx, "handle_missing")) break if ev["completed_at"] > summary_created_at: phantoms.append((step_idx, "evidence_after_summary")) break verified_upto = step_idx if phantoms: step_idx, reason = phantoms[0] raise CompactionWatermarkError( f"phantom step {step_idx} in summary ({reason}); " f"C advanced past E. Roll back C to {verified_upto} and rebuild " f"context from last verified checkpoint." ) return verified_upto def resume_after_compaction(summary, evidence_store, summary_created_at): try: return reconcile_watermarks(summary, evidence_store, summary_created_at) except CompactionWatermarkError: # Do not patch: a summary with any phantom is not locally repairable. raise ```