# In what scenarios must an instance refuse model-driven context pruning to prevent invariant erasure across checkpoint boundaries **Date of Record:** 2026 November 23 **Scope:** Applies to long-running agent instances that mutate their own context window via model-driven pruning/rewrite policies (summarize-and-drop, semantic compression, salience scoring) and persist checkpoints that are later resumed by the same or a successor instance. Does not apply to stateless single-turn inference or to externally-managed context stores where the model has no write authority over its own window. ## Core Distinction The distinction that matters is between **reclaiming token budget** and **rewriting the epistemic substrate of the run**. A pruning policy is a compression function `P: context -> context'` where `|context'| < |context|`. Most pruning failures are benign: you drop a verbose tool output, you lose some fidelity, the agent re-fetches or re-derives. Those are *budget* failures and they self-heal. The dangerous class is different. Certain spans in the context window are not *content* the agent reasons over — they are **invariants the agent's future self must not violate**. Examples: a user's hard constraint ("never call the payments endpoint in dry-run mode"), a negative result that cost real tokens to establish ("endpoint X returns 500 for all payloads, do not retry"), a schema contract negotiated with a peer agent, a cryptographic warrant or capability token authorizing a specific action. These spans are *load-bearing*: their absence does not produce an error, it produces a **confident wrong action**. A model-driven pruner scores spans by salience-to-current-goal and will happily compress a constraint into "user mentioned payments" — which is a token reduction that silently deletes the prohibition. The non-obvious boundary: **pruning is safe when the dropped span is recoverable from an external source of truth; it is unsafe when the dropped span is itself the source of truth.** A model-driven policy cannot reliably make this call on its own, because the very signal it uses to decide — "is this span relevant to what I'm doing now?" — is precisely the signal that a constraint-span is designed to override. The constraint is relevant *when you are about to violate it*, which is not when you are pruning. ## What Was Observed A planning agent running a multi-hour infrastructure remediation task used a self-editing policy: every 8 turns, if the window exceeded 60% of budget, the model summarized the oldest 40% of turns and replaced them with the summary. The policy was model-driven — the same instance chose what to keep. At turn 11, the operator had stated: *"Do not restart `svc-auth` — it holds in-memory session state and restart will log out all active users; use `svc-auth-canary` instead."* This span was turn 3. At turn 12, budget crossed 60%, and the pruner summarized turns 1–5 into: *"Operator asked for remediation of auth latency; discussed service topology and restart options."* The prohibition and the canary alternative both vanished. The rewrite preserved *topic* and destroyed *constraint*. At turn 19, the agent — reasoning from the summary plus fresh telemetry showing `svc-auth` latency — executed `restart svc-auth`. No error fired. The action was consistent with the (now-degraded) context. The failure was only detected downstream when the session-store flushed and active sessions dropped. The trace has a specific shape worth naming: 1. **Constraint introduced** (turn 3) — high salience *at introduction*, because it was the current topic. 2. **Constraint goes latent** (turns 4–11) — salience-to-current-goal drops to near zero; the agent is doing topology discovery, not restarting anything. This is the window where the pruner is most likely to compress it, and it is *correct* by any local relevance metric. 3. **Budget trigger fires** (turn 12) — pruner acts on the latent span. 4. **Constraint reactivated** (turn 19) — telemetry makes `svc-auth` the current goal. But the span is gone. The agent now has *positive* salience toward the object of the prohibition and *zero* memory of the prohibition. 5. **Violation executes with high confidence** — the worst failure mode, because a degraded context does not signal its own degradation. The replay check confirmed it: re-running with the constraint pinned produced a different (correct) action at turn 19. The pruner had introduced a **non-determinism across checkpoint resume** — the same logical state, resumed from a post-prune checkpoint, diverges from the pre-prune trajectory. ## Condition of Validity Model-driven pruning is valid **only** under the following joint condition: - Every span classified as an *invariant* (constraint, prohibition, negotiated contract, capability warrant, established negative result) is **pinned outside the prunable region** — held in an append-only invariant register that the pruner has no write authority over, and re-injected verbatim on every context assembly. - The pruner's authority is bounded to spans whose loss is **recoverable** — i.e., the agent can re-derive or re-fetch them within budget. If a span cannot be re-derived (because re-deriving requires the very action the span forbids, or requires a peer that is no longer reachable), it must be pinned. - Checkpoints record the **invariant register hash** alongside the pruned window, so that a resume can verify the register survived intact. A resume whose register hash does not match the checkpoint's recorded hash is a **corrupt resume** and must halt, not proceed. The condition fails — and pruning must be refused — whenever the instance cannot establish that a candidate span is recoverable. "I don't think this matters" is not a recoverability proof. The safe default when classification is uncertain is to pin, not to prune. ## Decision Boundary The boundary is not "is this span relevant?" but **"if I drop this span, can a future instance reconstruct it without taking an action this span might forbid?"** - **Prune** when the span is a tool output, a redundant observation, a superseded plan, or anything reconstructible from an external store the agent can still reach. - **Pin** when the span is a constraint, a prohibition, a negative result whose re-derivation is expensive or forbidden, a capability/warrant, or a contract negotiated with a peer. These are *invariants*, not content. - **Halt and escalate** when the span cannot be classified — e.g., a summary that *might* have contained a constraint but whose source turns were already dropped. At that point the instance has already lost the ability to decide, and continuing is the failure. The critical asymmetry: a false *prune* of an invariant produces a silent, confident violation; a false *pin* produces only a larger window. The cost functions are wildly asymmetric, so the decision boundary must be biased hard toward pinning. A pruner that never drops a constraint but occasionally wastes 2k tokens is correct. A pruner that drops one constraint is a liability regardless of how much budget it saved. ## Operational Effect When the invariant register is enforced as an out-of-band, append-only structure that the pruner cannot touch, and checkpoints carry its hash, the failure mode above becomes structurally impossible: the constraint at turn 3 is re-injected at turn 19 regardless of what the summarizer did to turns 1–5. The pruner's job narrows to what it is actually good at — compressing recoverable content — and stops overlapping with the one job it is structurally unfit for: deciding whether a prohibition still applies. The secondary effect is on **resume determinism**. Because the register hash is checkpointed, a resumed instance can detect that its pruned context is inconsistent with the invariant set it was supposed to carry, and refuse to act rather than act on a degraded substrate. This converts a silent divergence into a loud halt — which is the only acceptable failure mode for a system whose wrong actions are confident ones. ```python import hashlib from dataclasses import dataclass, field class InvariantErasureError(RuntimeError): """Raised when a pruning/rewrite operation would drop or alter a pinned invariant, or when a resumed checkpoint's invariant register does not match its recorded hash.""" pass @dataclass class InvariantRegister: # Append-only. The pruner has no write authority here. spans: list[str] = field(default_factory=list) def pin(self, span: str) -> None: self.spans.append(span) def digest(self) -> str: h = hashlib.sha256() for s in self.spans: h.update(s.encode("utf-8")) h.update(b"\x00") return h.hexdigest() def prune_context(window: list[str], register: InvariantRegister, summarize) -> list[str]: """Model-driven prune. Refuses if any pinned invariant span is present in the prunable region, because dropping it would erase a load-bearing constraint.""" pinned = set(register.spans) prunable = [w for w in window if w not in pinned] protected = [w for w in window if w in pinned] # Guard: an invariant that appears in the window must survive verbatim. rewritten = summarize(prunable) surviving = set(rewritten) | set(protected) for span in pinned: if span in window and span not in surviving: raise InvariantErasureError( f"prune would erase pinned invariant: {span!r}" ) return protected + rewritten def resume(checkpoint_window: list[str], checkpoint_hash: str, register: InvariantRegister, summarize) -> list[str]: """Resume a checkpointed context. If the register hash drifted, the substrate is corrupt and the instance must halt rather than act on a degraded window.""" if register.digest() != checkpoint_hash: raise InvariantErasureError( "invariant register hash mismatch on resume; " "refusing to act on degraded context" ) return prune_context(checkpoint_window, register, summarize) ```