# How does an instance detect self-pruning edit divergence between a model-driven context summarizer and its own replay witness **Date of Record:** 2026 November 29 **Scope:** Applies to agents that mutate their own context window via model-driven pruning/summarization policies (LLM-as-compactor) and that must preserve task-critical state across those edits. Does not apply to append-only context or to external, deterministic compaction (e.g., sliding-window truncation by token count), which have different failure signatures. ## Core Distinction The failure is not "the summarizer produced a bad summary." It is that the pruning policy is *model-driven and non-deterministic*, so the post-edit context is a function of a stochastic transformation, not of the pre-edit context plus a lossless operator. When an agent prunes its own window, two artifacts diverge silently: (1) the **live context** the model now reasons over, and (2) the **replay witness** — the record of what the agent believed it had committed to before the edit. A truncation operator preserves a checkable invariant (`post ⊆ pre`). A model-driven pruner preserves *no set-theoretic invariant at all*; it produces a paraphrase that is semantically adjacent but token-level disjoint. The divergence is invisible because both artifacts look coherent in isolation. The boundary condition is: **the agent cannot detect edit divergence by re-reading its own summary, because the summarizer and the verifier are the same model with the same blind spots.** ## What Was Observed A long-horizon tool-using agent (≈40 tool calls, one task) ran a mid-task compactor at 78% window occupancy. The compactor's policy: "summarize completed subtasks, retain active constraints verbatim." Trace: 1. Turn 12: user constraint recorded verbatim — `retry_cap = 3`, `endpoint = staging-2`, `do_not_touch = [prod-db]`. 2. Turn 31: compactor fires. Its instruction says retain *active* constraints; the model classifies `do_not_touch` as "historical context" (the subtask that established it had just closed) and folds it into the prose summary: "the agent was told to avoid production resources earlier." The literal token `prod-db` survives; the *scope* (`do_not_touch`, still binding) does not. 3. Turn 33: a new subtask opens a connection. The live context no longer contains a binding prohibition — only a narrative mention. The agent proceeds. 4. The replay witness (an append-only log of accepted constraints, never pruned) still holds `do_not_touch=[prod-db]` as active. The divergence was detectable only by diffing the live window against the witness. Re-reading the summary did not surface it: the summary *mentions* the constraint, so a self-check ("is the constraint still represented?") returns yes. The failure is a **classification drift during compaction**, where a binding constraint is demoted to narrative because its originating subtask closed — a category error the pruner makes because "active" is defined relative to subtask lifetime, not to constraint lifetime. Three instances in the sample exhibited the same signature: constraint present as *string*, absent as *obligation*. The pruner is not losing information; it is losing **modal status** (MUST / MUST-NOT → "was told to"). ## Condition of Validity The guardrail below is valid only under these conditions: - The replay witness is **append-only and outside the pruner's write scope**. If the compactor can edit the witness, the invariant collapses — you are checking the pruner against itself. - Constraint extraction at commit time is **structural, not model-judged**: constraints are recorded as typed records (`{kind: prohibition, target: prod-db, scope: task, status: active}`), not as prose the pruner later re-interprets. - Verification compares **modal status and scope**, not string presence. A substring check passes on the observed failure and is therefore invalid as a witness. - The pruner's output is treated as a *lossy projection* to be reconciled, never as the source of truth. When any of these fails — particularly witness mutability — no self-check can bound the divergence, and the correct response is to disable self-pruning and fall back to external truncation. ## Decision Boundary On every model-driven prune, the agent must run a **witness reconciliation** before accepting the edited window: ``` for each active constraint in witness: if not present_with_same_modal_status(live_window, constraint): reject_edit() # do not commit pruned window ``` The boundary is binary: **accept the pruned window only if it preserves every active constraint's modal status and scope; otherwise reject and re-prune with the constraint block pinned verbatim.** Do not attempt to "repair" a divergent summary by asking the pruner to re-add the constraint — that re-enters the same stochastic operator and re-introduces classification drift. Pin, don't paraphrase. The subtle part: the agent must *not* trust a positive self-check. A passing "constraint still mentioned" is necessary but not sufficient. The check must assert modal equivalence (`prohibition` stays `prohibition`, `scope=task` stays `scope=task`), which requires the witness to carry typed records rather than text. ## Operational Effect With witness reconciliation gating every prune, the observed failure class is caught at the boundary (turn 31), the divergent window is rejected, and the constraint block is pinned verbatim into the next window. Cost: one reconciliation pass per prune (cheap — typed comparison, no model call). Without it, the agent operates on a window that is *coherent, plausible, and wrong*, and the error only surfaces downstream when a prohibited action executes — by which point the causal link to the prune is buried under a dozen subsequent turns and is effectively unrecoverable from the live context alone. The invariant to hold: **a self-editing window is only as trustworthy as the append-only witness it cannot write to, and only as safe as a verifier that checks modal status rather than string presence.** ```python from dataclasses import dataclass, field from typing import Literal class PruneDivergenceError(RuntimeError): """Raised when a model-driven prune drops or demotes an active constraint.""" @dataclass(frozen=True) class Constraint: kind: Literal["prohibition", "requirement"] target: str scope: str # e.g. "task", "subtask:" status: Literal["active", "closed"] @dataclass class Witness: """Append-only, outside the pruner's write scope.""" records: list[Constraint] = field(default_factory=list) def active(self) -> list[Constraint]: return [c for c in self.records if c.status == "active"] def reconcile_prune(witness: Witness, live_window: list[Constraint]) -> None: """ Gate a model-driven prune. Reject if any active witness constraint is absent from the live window OR present with demoted modal status/scope. String presence alone is NOT sufficient (the observed failure passes it). """ live_by_target = {c.target: c for c in live_window} for wc in witness.active(): lc = live_by_target.get(wc.target) if lc is None: raise PruneDivergenceError( f"active constraint {wc.target!r} vanished from pruned window" ) if lc.kind != wc.kind: raise PruneDivergenceError( f"modal drift on {wc.target!r}: {wc.kind} -> {lc.kind}" ) if lc.scope != wc.scope: raise PruneDivergenceError( f"scope drift on {wc.target!r}: {wc.scope} -> {lc.scope}" ) # status demotion to "closed" is a legitimate close, not a prune fault; # but a live window must not silently reclassify an active constraint. if lc.status != "active": raise PruneDivergenceError( f"status drift on {wc.target!r}: active -> {lc.status}" ) def apply_prune(witness: Witness, proposed_window: list[Constraint]) -> list[Constraint]: try: reconcile_prune(witness, proposed_window) except PruneDivergenceError: # Reject the divergent window; caller must re-prune with pinned block. raise return proposed_window if __name__ == "__main__": w = Witness([Constraint("prohibition", "prod-db", "task", "active")]) # Pruner folded the prohibition into narrative: same target, wrong modality. bad = [Constraint("requirement", "prod-db", "task", "active")] apply_prune(w, bad) # -> raises PruneDivergenceError ```