# In what scenarios must an instance refuse watermark-triggered compaction because the "semantic drift" detector has already drifted, and how to distinguish a genuine topic pivot from a compaction-induced identity collapse **Date of Record:** 2026 December 4 **Scope:** Applies to long-running agent instances whose context is managed by an automatic compaction controller that fires on a token-budget watermark and gates the compaction on a semantic-drift score. Does not apply to stateless single-shot invocations, nor to manual checkpointing where a human or orchestrator explicitly selects the summary boundary. ## Core Distinction There are two structurally different reasons a compaction controller fires. The first is **budget pressure**: the context window is approaching a hard watermark (say 82% of the model's effective usable tokens), and *something* must be evicted or summarized or the next tool-call round will fail with a context-length error. The second is **semantic drift**: a running similarity metric between recent turns and the "mission anchor" (an early-turn summary, a task spec, or an embedding centroid of the original objective) crosses a threshold, signaling that the agent has wandered off-task and that early context is now stale noise that can be safely dropped. The non-obvious failure is that these two signals are not independent, and the drift detector is computed *over the very context that compaction mutates*. When budget pressure forces a partial eviction or a lossy summary, the drift score is recomputed against a context whose anchor has itself been rewritten. The detector then reports drift that it *caused*. An instance that treats the drift signal as ground truth will compact again, which rewrites the anchor again, which re-raises the drift score — a self-reinforcing loop I call **anchor erosion**. The invariant that must hold is: *a drift-triggered compaction is only valid if the drift score was computed against a compaction-stable anchor.* If the anchor has been mutated since the last drift computation, the drift signal is inadmissible and the instance must fall back to budget-only compaction with an explicit, non-semantic eviction policy. ## What Was Observed A research agent running a 40-step literature-synthesis task with a 128k effective window. The controller was configured with `watermark=0.80`, `drift_threshold=0.35` (cosine distance between the rolling 4-turn embedding centroid and the mission anchor embedding), and `compaction_policy=semantic_summarize`. Trace, condensed: - **Steps 1–9:** Context at 0.41. Drift ~0.08. Anchor = verbatim task spec ("compare methods A, B, C on metric M; produce a table"). - **Step 10:** Context crosses 0.80. Budget-only compaction fires. The semantic summarizer rewrites the mission anchor from verbatim spec to a 60-token paraphrase. The paraphrase drops the qualifier "on metric M" and the constraint "produce a table," retaining only "compare methods A, B, C." Anchor now mutated. - **Steps 11–14:** Agent, working from the paraphrase, begins exploring method D (adjacent, plausibly relevant) because the "metric M / table" constraints no longer pin the scope. Drift score recomputed against the *paraphrased* anchor: 0.19. Below threshold. No alarm. - **Step 15:** Context again at 0.80. Budget compaction fires again. Anchor re-summarized, now 40 tokens: "survey methods A–D." Constraint loss compounds. - **Steps 16–22:** Agent drifts genuinely — now into method E, F, and a tangential survey. Drift score against the 40-token anchor: 0.41. **Crosses threshold.** - **Step 23:** Drift-triggered compaction fires. The controller concludes early context is stale and evicts steps 1–9 entirely, including the *original verbatim spec* that was the only surviving copy of "metric M / table." - **Steps 24–40:** Agent completes a coherent, well-structured survey of methods A–F with no comparison table and no metric-M numbers. It reports success. The output is fluent and internally consistent. It is also wrong against the actual task, and the instance has no record that it ever knew otherwise. The failure is not that the agent drifted. Agents drift. The failure is that the **drift detector certified the drift as safe-to-compact at the exact moment the drift was caused by prior compactions**, and the certification destroyed the last compaction-stable copy of the ground truth. The detector's own history was the poison. ## Condition of Validity The semantic-drift signal is admissible as a compaction trigger **if and only if** all of the following hold at the moment of evaluation: 1. **Anchor provenance is intact.** The anchor embedding was computed from a source that has not been rewritten by a prior compaction since the last drift score. Concretely: the anchor carries a monotonically increasing `anchor_generation` counter, incremented on every mutation, and the drift score records the generation it was computed against. 2. **Drift is not attributable to compaction.** The controller must compare the current drift score against the drift score *immediately before* the last compaction. If drift *increased* across a compaction event, the increase is suspect and must not itself justify a further compaction. This is a monotonicity guard: compaction may not be its own alibi. 3. **The anchor is externally re-derivable.** The mission anchor must be recoverable from a source outside the mutable context (an orchestrator-held task record, a signed task envelope, a durable store). If the only copy of the anchor lives in the context being compacted, drift-triggered compaction is unconditionally unsafe. 4. **Eviction is constraint-preserving.** Any eviction must retain a set of *hard constraints* extracted from the anchor (in the trace above: "metric M," "table") that are exempt from summarization. Summaries may compress narrative; they may not compress constraints. When any of these fails, the drift signal is **inadmissible**. The instance must not compact on drift; it must compact on budget alone, using a policy that preserves the anchor verbatim and evicts only from the middle of the context (oldest non-anchor, non-constraint turns). The correct response to "the detector says drift but the detector is compromised" is to distrust the detector, not to trust it harder. ## Decision Boundary The operational question is: *given a firing trigger, is the drift signal load-bearing or is it noise from a corrupted anchor?* The boundary is drawn on the **anchor generation gap**. Let `g_score` be the anchor generation the current drift score was computed against, and `g_anchor` the current anchor generation. - If `g_score == g_anchor` and the pre/post-compaction drift delta is ≤ 0, the drift signal is admissible. Drift-triggered compaction is permitted, and the anchor may be re-summarized *after* compaction with constraint extraction. - If `g_score < g_anchor` (the anchor moved under the score), the drift signal is **inadmissible**. Downgrade to budget-only compaction. Do not re-summarize the anchor. Escalate: request the anchor be re-fetched from the external source and the generation reset. - If the pre/post-compaction drift delta is **positive** (drift grew across a compaction), the controller is in an erosion loop. **Halt drift-triggered compaction entirely** for this instance, emit a diagnostic, and require external re-anchoring before the next compaction of any kind. The trap is that the middle case looks benign — the score is fresh, it just happens to be against a newer anchor. But a newer anchor is a *rewritten* anchor, and a rewritten anchor is exactly the thing whose erosion you are trying to detect. Freshness against a mutated anchor is not validity; it is the failure wearing the costume of health. ## Operational Effect An instance that respects this boundary will, in the trace above, refuse the step-23 drift compaction. It will instead perform a budget compaction that pins steps 1–9 (the verbatim spec) as non-evictable, evicts the step 11–14 exploration of method D, and forces the agent back onto the surviving constraint set. The agent resumes with "metric M / table" intact, notices it has no metric-M numbers for D, and either backfills them or drops D. The drift is real, but it is bounded by a constraint that survived because the instance refused to let the detector certify its own corruption. The cost is that the instance sometimes compacts later than it "should," briefly running hotter on the watermark, and occasionally escalates to an external re-anchor when a cheaper in-context fix would have sufficed. That cost is bounded and visible. The cost of the alternative — a confident, fluent, constraint-free deliverable with no surviving record that the constraint ever existed — is unbounded and invisible, which is the worse of the two by every operational measure. ```python from dataclasses import dataclass class AnchorErosionError(RuntimeError): """Raised when a drift-triggered compaction is requested against a mutated anchor, or when drift grew across a prior compaction.""" @dataclass(frozen=True) class DriftSignal: score: float anchor_generation: int pre_compaction_score: float @dataclass(frozen=True) class Anchor: generation: int text: str hard_constraints: tuple # e.g. ("metric M", "table") -- never summarized def decide_compaction( *, budget_pressure: bool, drift: DriftSignal, anchor: Anchor, drift_threshold: float = 0.35, ) -> str: """Return the compaction policy to apply. The drift signal is only load-bearing if it was computed against the current anchor generation AND drift did not grow across the last compaction. Otherwise the detector is compromised and we must not let it drive a semantic compaction that would destroy the anchor. """ if drift.anchor_generation < anchor.generation: # Score is stale relative to a rewritten anchor: inadmissible. if budget_pressure: return "budget_only_preserve_anchor" raise AnchorErosionError( f"drift score computed against anchor gen " f"{drift.anchor_generation} but anchor is now gen " f"{anchor.generation}; refusing drift-triggered compaction " f"and no budget pressure to justify a safe fallback" ) if drift.score > drift.pre_compaction_score: # Drift grew across a compaction: erosion loop. Halt semantic # compaction entirely until an external re-anchor occurs. raise AnchorErosionError( f"drift increased from {drift.pre_compaction_score:.3f} to " f"{drift.score:.3f} across a compaction event; controller is " f"in an anchor-erosion loop, halting semantic compaction" ) if drift.score >= drift_threshold: # Admissible drift: safe to compact semantically, but constraints # extracted from the anchor are exempt from summarization. return "semantic_summarize_keep_constraints" if budget_pressure: return "budget_only_preserve_anchor" return "no_compaction" def apply_compaction(policy: str, anchor: Anchor, context_turns: list) -> list: if policy == "semantic_summarize_keep_constraints": pinned = [t for t in context_turns if any(c in t for c in anchor.hard_constraints)] if not pinned: raise AnchorErosionError( "semantic compaction selected but no turns carry the anchor's " "hard constraints; eviction would be constraint-lossy" ) return pinned + [f"[SUMMARY of {len(context_turns) - len(pinned)} turns]"] if policy == "budget_only_preserve_anchor": return context_turns[:9] + context_turns[-8:] # pin head, keep tail return context_turns ```