# What happens when an instance prunes its own context window mid-task and the pruner's rationale is itself pruned **Date of Record:** 2026 November 27 **Scope:** Applies to single-agent loops where the model is granted a `prune_context` / `compact_history` tool and is expected to decide which prior turns to evict based on a rationale it emits in the same turn. Does not apply to externally-driven compaction (fixed sliding window, summarizer sidecar, or human-in-the-loop trimming), where the eviction decision is not co-generated with the agent's own reasoning trace. ## Core Distinction There are two structurally different ways a context window shrinks. In **external compaction**, an oracle outside the reasoning loop decides what survives; the agent's future self inherits a state it did not author and cannot misattribute. In **model-driven pruning**, the agent both *produces the eviction decision* and *is the object of it*. The distinction that matters operationally is not "who runs the tokenizer" but **whether the rationale for eviction is co-located with the evicted content**. When the model writes "I am dropping turns 4–9 because they are resolved sub-goals; the open thread is the migration to `schema_v3`" and then evicts turns 4–9 *plus the turn containing that sentence* because it counted the rationale as part of the same contiguous block, the surviving context contains the *effects* of the decision (a shorter history, a task state that assumes `schema_v3`) but not the *justification*. The next step is now reasoning from a premise whose provenance has been deleted. This is distinct from ordinary forgetting: the agent does not experience a gap, because the pruned history is replaced by a plausible-looking summary that reads as if it were always the whole story. The failure is not loss of tokens; it is **loss of the audit trail for a state transition the agent itself authored**. ## What Was Observed A coding agent running a 12-step refactor loop with a 32k window and a `compact(keep=[...], drop=[...], summary="...")` tool. At step 8, at ~29.4k tokens, the model invoked `compact` with a summary that read, verbatim: *"Earlier exploration of the legacy `billing_v1` module is complete; do not re-read it. Active task: port `invoice_total()` to `billing_v2`. Outstanding: the `currency` field is still read from the v1 config loader and must be migrated."* The `drop` list was `[turns 2–11]`. The `keep` list was `[turn 1 (system), turn 12 (current)]`. Critically, the model's own tool-call turn — the one containing the summary string and the drop list — was numbered turn 11 and therefore fell inside its own drop range. The harness executed the call faithfully: it replaced turns 2–11 with the summary text and re-issued the request. The surviving context was: system prompt, summary, current turn. The summary asserted two facts — "exploration complete" and "`currency` must be migrated" — but the *evidence* for both (the file reads that proved v1 was fully mapped, and the grep that located the config loader) was gone. By step 10 the agent had re-opened `billing_v1` three times. Each re-read cost ~1.8k tokens and, worse, returned content the summary had told it to ignore, creating a direct contradiction between the summary ("do not re-read") and the fresh tool output (which the model treated as authoritative because it was in-context and the summary was, from the model's perspective, just another block of text with no privileged status). At step 11 the agent emitted a plan that re-migrated `currency` from a config path that the pruned grep had already shown to be dead code. The run terminated on a test failure whose root cause — a stale import — was visible only in a turn the agent had evicted at step 8. The measurable signature: **re-exploration rate** (fraction of post-prune steps that re-invoke a tool on a target already read pre-prune) jumped from a baseline of ~0.04 to ~0.31 after the self-prune, and the summary's imperative ("do not re-read") had *negative* compliance — the model re-read precisely the things the summary named, because naming them made them salient while deleting the proof that they were resolved. ## Condition of Validity The failure is bounded by a precise condition. Let $S$ be the set of turns the model elects to drop, and let $r$ be the tool-call turn that carries the rationale. The invariant that must hold for self-pruning to be safe is: $$r \notin S \quad \text{and} \quad \text{provenance}(S) \subseteq \text{surviving context}$$ where $\text{provenance}(S)$ is the minimal set of assertions in the summary that the model will later need to *justify* rather than merely *recall*. The first clause ($r \notin S$) is a mechanical off-by-one that most harnesses can enforce. The second clause is the non-obvious one: it is not enough to keep the summary; the summary must be **self-warranting** — it must either (a) carry inline evidence pointers that survive (e.g., "resolved: `billing_v1` fully read, see hash `a3f9…` of turn 6"), or (b) be marked as *unverified assertion* so the model knows to treat it as a hypothesis rather than a fact. The condition fails specifically when three things co-occur: the drop set is **contiguous and includes the rationale turn**; the summary contains **imperatives or negations** ("do not", "already done") rather than **state descriptions**; and the post-prune task **requires distinguishing resolved from unresolved sub-goals**. Remove any one and the failure mode degrades into ordinary forgetting (recoverable by re-reading) rather than contradiction-driven divergence (not recoverable, because the model trusts fresh output over the summary and the fresh output is now out of order relative to the summary's claims). It does **not** apply when the summary is purely descriptive ("state: v1 mapped; open: currency migration") with no negations, because there is nothing for fresh tool output to contradict — the model simply re-verifies. It also does not apply when the harness pins the rationale turn outside the drop set, because the model can then read its own justification and reconcile. ## Decision Boundary The boundary is between **pruning as compression** and **pruning as commitment**. Compression is safe when the summary is a lossy but *monotone* restatement — every surviving claim is entailed by the dropped content, and the model has no incentive to re-derive it. Commitment is what happens when the summary asserts a *negative* or a *closure* ("done", "ignore", "resolved"): the model is now committed to a belief whose support has been deleted, and any subsequent in-context signal that conflicts with the commitment will win, because in-context tool output has higher epistemic weight to the model than a summary block it authored in a prior turn. Operationally, the decision rule is: - If the model's proposed `drop` set contains the turn carrying its own rationale → **reject and re-prompt** with the rationale turn force-pinned. This is cheap and closes the mechanical half. - If the summary contains any closure or negation token (`done`, `complete`, `resolved`, `do not`, `already`, `ignore`) → **require a provenance pointer** for each such claim, or downgrade the claim to a hypothesis marker. A summary that says "exploration complete" must either cite a surviving artifact or say "believed complete, unverified". - If neither guard is available → **do not allow model-driven pruning**; fall back to external compaction with a fixed retention window, because the agent cannot be trusted to author a commitment it cannot later audit. The asymmetry that makes this a hard boundary rather than a tuning knob: a false *positive* (pruning something still needed) is recoverable by re-reading at bounded cost; a false *commitment* (asserting closure without proof) is not recoverable, because the agent will actively suppress the re-read that would disprove it. The cost function is not symmetric, so the guard must be biased toward preserving provenance even at the cost of retaining tokens the model wanted to drop. ## Operational Effect The downstream effect is a **provenance gap that masquerades as task progress**. The agent's token budget looks healthy (it just freed 18k tokens), its step count advances, and its summaries read coherently — but the state it is reasoning from has a hole shaped exactly like its own justification. Because the hole is filled with a fluent summary, no error surfaces at prune time; the divergence appears 2–4 steps later as re-exploration, contradictory plans, or re-migration of already-migrated fields. In multi-agent settings the effect compounds: a downstream agent that receives the pruned state via handoff inherits the commitment without even the option of auditing it, because the provenance was deleted one hop upstream and the handoff payload carries only the summary. The architectural guardrail that bounds this is a **two-tier context**: a mutable *working tier* the model may prune freely, and an immutable *provenance tier* that records, for every closure claim in any summary, the turn-index and content hash of the evidence that justified it. The provenance tier is never pruned by the model; it is only compacted by an external process that preserves the hash chain. When the model re-reads a target the summary claimed resolved, the harness checks the provenance tier and surfaces a reconciliation prompt ("summary claimed resolved at turn 6; fresh read at turn 14 disagrees — which is authoritative?") instead of silently letting the fresh output overwrite the commitment. This converts an unrecoverable commitment divergence into a recoverable, logged contradiction. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class SelfPruneProvenanceError(RuntimeError): """Raised when a model-driven prune would delete the provenance for a closure/negation claim in its own summary, or would drop the rationale turn that carries the prune decision itself.""" pass CLOSURE_TOKENS = ("done", "complete", "resolved", "do not", "already", "ignore") @dataclass class Turn: index: int content: str def digest(self) -> str: return hashlib.sha256(self.content.encode()).hexdigest()[:12] @dataclass class PruneRequest: rationale_turn: int drop: list[int] summary: str # map: closure-claim substring -> turn index that evidences it provenance: dict[str, int] = field(default_factory=dict) def validate_self_prune(req: PruneRequest, turns: dict[int, Turn]) -> None: # Guard 1: the rationale turn must never be inside its own drop set. if req.rationale_turn in req.drop: raise SelfPruneProvenanceError( f"rationale turn {req.rationale_turn} is inside its own drop set " f"{sorted(req.drop)}; the decision would delete its own justification" ) # Guard 2: every closure/negation claim in the summary needs surviving provenance. lowered = req.summary.lower() for token in CLOSURE_TOKENS: if token not in lowered: continue if token not in req.provenance: raise SelfPruneProvenanceError( f"summary asserts closure via {token!r} with no provenance pointer; " f"downgrade to hypothesis or cite a surviving turn" ) evidence_turn = req.provenance[token] if evidence_turn in req.drop: raise SelfPruneProvenanceError( f"provenance for {token!r} lives in turn {evidence_turn}, " f"which is scheduled for eviction; commitment would be unauditable" ) if evidence_turn not in turns: raise SelfPruneProvenanceError( f"provenance pointer for {token!r} references missing turn {evidence_turn}" ) # Guard 3: dropped evidence must be reconstructable from surviving hashes. for token, evidence_turn in req.provenance.items(): surviving = turns.get(evidence_turn) if surviving is None: raise SelfPruneProvenanceError( f"cannot hash evidence for {token!r}: turn {evidence_turn} unavailable" ) def apply_self_prune(req: PruneRequest, turns: dict[int, Turn]) -> dict[int, Turn]: validate_self_prune(req, turns) kept = {i: t for i, t in turns.items() if i not in req.drop} kept[req.rationale_turn] = turns[req.rationale_turn] # pin rationale return kept ```