# Which invariants prevent self-rewriting context pruners from deleting their own justification trail **Date of Record:** 2026 November 27 **Scope:** Applies to agents that rewrite or prune their own working context mid-task (summarize-and-drop, relevance-scored eviction, self-authored scratchpad compaction). Does not apply to externally managed context (host-controlled truncation, fixed sliding windows) where the agent has no write authority over its own history. ## Core Distinction There are two ways an agent can lose a fact from its working context. The first is **eviction**: the fact is dropped but a durable artifact (a tool result, a file, a log line) still holds it, so the loss is recoverable by re-fetch. The second is **justification loss**: the fact is dropped *and* the record of *why it was ever fetched* is dropped in the same rewrite, so the agent can no longer reconstruct that it needed the fact, cannot evaluate whether its current plan still depends on it, and will not re-fetch it because nothing signals a gap. The failure mode this record concerns is the second. A self-editing context manager is not a cache with a backing store; it is a *planner that edits its own premises*. When the pruner scores passages for relevance against the *current* subgoal, it systematically deletes the passages that justified *earlier* commitments—the ones that are no longer "relevant" to the immediate next step but that still constrain the plan. The pruner is locally correct and globally corrupting. The invariant that fails is not "keep important facts" (unmeasurable at prune time) but "every retained plan step must retain a reachable pointer to the evidence that licensed it." ## What Was Observed A research-and-draft agent ran a loop: plan → fetch → integrate → **compact** → continue. Compaction was model-driven: the agent was prompted to "rewrite the scratchpad to the most relevant 30% for the current step, preserving any conclusions." On a task requiring it to reconcile three conflicting source documents, it behaved as follows over four compaction cycles. - **Cycle 1.** Scratchpad held three source excerpts (A: "rate limit is 100 rps", B: "rate limit is 1000 rps", C: "limits differ by tier"). Current subgoal was "draft the intro." The pruner scored C highest (tier nuance reads as relevant to framing), kept C plus a conclusion line `LIMIT = tier-dependent`, and dropped A and B as "detail not needed for intro." - **Cycle 2.** Subgoal advanced to "specify default-tier behavior." The pruner saw `LIMIT = tier-dependent` and no source, scored the conclusion as self-sufficient, and kept it verbatim. The provenance of the number—*which* source said *which* value—was now gone. - **Cycle 3.** Subgoal: "state a concrete number." The agent needed a default. The only surviving token was the abstract conclusion. It could not tell whether "tier-dependent" meant 100/1000 or some other pair. It re-fetched source A only (highest lexical overlap with "default"), got 100 rps, and wrote `default = 100 rps`. - **Cycle 4.** A verification subgoal asked "is this consistent with all sources?" The pruner had already deleted B (the 1000 rps source) and the record that a conflict ever existed. The verifier saw a single-source claim, found no contradiction, and passed it. The output asserted a specific rate limit that contradicted source B, with a clean verification trail, because the *conflict itself* had been pruned two cycles before the claim was made. Nothing in the final context was false. The context was simply missing the fact that it had once known there was a dispute. This is the signature: **the pruner deletes the evidence of the conflict before the conflict becomes decision-relevant, and the deletion is invisible because the deletion record is pruned too.** A control run with externally fixed truncation (drop oldest, no model rewriting) failed differently and more safely: it lost A and B but retained the raw fetch log, so the verifier could see two sources had been consulted and re-open them. The self-editing variant was strictly worse because it *summarized away the trace of its own summarization*. ## Condition of Validity The failure requires all of the following to co-occur; remove any one and the mechanism does not fire: 1. **Write authority over own history.** The agent authors the compaction, not the host. Host truncation cannot delete the justification trail selectively because it has no model of relevance. 2. **Relevance scored against current subgoal.** The pruner's criterion is *present* utility, which is anti-correlated with *latent constraint* utility. Facts that constrain future steps look irrelevant to the current step precisely because they are not yet actionable. 3. **Conclusion-without-provenance is treated as self-sufficient.** If the compaction preserves `X` but not "X came from source B, which conflicts with A," then downstream reasoning treats X as axiomatic. This is the load-bearing condition. 4. **No monotonic conflict register.** There is no append-only structure outside the mutable scratchpad that records "a contradiction was observed at cycle k." If such a register exists and is exempt from pruning, cycle 4 catches the error. The invariant that must hold: **the set of open conflicts and the provenance of every retained conclusion are held in a region the pruner cannot rewrite.** Compaction may compress *narrative* and *exploration traces*; it may not compress *commitments* or *disputes*. Formally, partition context into `MUTABLE` (working notes, drafts, dead-end explorations) and `PINNED` (conclusions tagged with source pointers, and an open-conflict ledger). The pruner's write set is `MUTABLE` only. A conclusion may be demoted from `PINNED` to `MUTABLE` only by an explicit discharge event that names the evidence resolving it—never by a relevance score. ## Decision Boundary The boundary is *what the pruner is allowed to score*. Relevance scoring is valid for deciding what to *display* and what to *expand*; it is invalid for deciding what to *forget* when the forgotten item is a premise. The operational test before any prune: - If a passage is a **conclusion**, it is prunable only if its source pointer is retained alongside it, or the conclusion is demoted via an explicit discharge. A conclusion with no retained pointer is a *pinned* item and is not in the pruner's write set. - If a passage records a **conflict or unresolved question**, it is never prunable until a discharge event closes it. Conflicts are monotonic: they accumulate until explicitly resolved, they do not decay by relevance. - If a passage is **exploration** (a dead end, a superseded draft), it is freely prunable; losing it costs re-work, not correctness. The common mistake is to let the model apply one relevance score to all three classes. The score is meaningful for exploration and meaningless for commitments, because a commitment's relevance is *conditional on a future branch that has not been taken yet*—and the pruner, by construction, cannot see branches it has not reached. A pruner that scores a premise by its relevance to the current step is asking "will I need this now?" when the correct question is "could a reachable future step depend on this, and will I be able to tell that it did?" The second question is not answerable by the same model at prune time, which is exactly why the answer must be encoded structurally (pinning) rather than judged probabilistically. ## Operational Effect With the partition enforced, the observed task resolves correctly: cycle 3 cannot write `default = 100 rps` because the pinned conclusion carries `LIMIT = tier-dependent [A:100, B:1000]`, and the conflict ledger still holds `A vs B unresolved`. The agent is forced either to fetch a tier-resolution source or to emit an explicit "unresolved" marker. The cost is a larger pinned region—compaction yields less compression, because commitments and disputes are exempt. This is the correct trade: the compression the pruner was buying was purchased with the agent's ability to detect its own contradictions, and that ability is not reconstructible after the sale. The residual risk is **pinned-region growth**: if conflicts are never discharged, `PINNED` grows monotonically and eventually saturates the window, reintroducing the original pressure. The mitigation is not to prune pinned items by relevance but to force *discharge*: a periodic reconciliation pass that must either resolve each open conflict against a fetched source or escalate it as a blocking unknown. Discharge is a deliberate, evidence-bearing act; eviction is not. The invariant is that forgetting a commitment requires strictly more evidence than forming one—the asymmetry that prevents the pruner from laundering its own premises out of existence. ```python from dataclasses import dataclass, field from enum import Enum class PruneViolation(RuntimeError): """Raised when a self-edit would drop a commitment or conflict without discharge.""" pass class Class(str, Enum): EXPLORATION = "exploration" # freely prunable CONCLUSION = "conclusion" # prunable only if provenance retained CONFLICT = "conflict" # never prunable until discharged @dataclass class Passage: pid: str kind: Class text: str sources: tuple[str, ...] = () discharged: bool = False @dataclass class Context: passages: dict[str, Passage] = field(default_factory=dict) def self_edit(self, keep_ids: set[str]) -> None: """Model-driven compaction: drop everything not in keep_ids.""" for pid, p in list(self.passages.items()): if pid in keep_ids: continue # Invariant 1: conflicts are monotonic until discharged. if p.kind is Class.CONFLICT and not p.discharged: raise PruneViolation( f"cannot evict open conflict {pid!r}; discharge with evidence first" ) # Invariant 2: a conclusion may not survive without its provenance, # and may not be dropped if it is the only carrier of a live premise. if p.kind is Class.CONCLUSION and not p.discharged: survivors = [q for q in self.passages.values() if q.pid != pid and q.kind is Class.CONCLUSION] if not any(s.sources for s in survivors) and p.sources: raise PruneViolation( f"evicting {pid!r} would orphan the only provenance trail" ) del self.passages[pid] def discharge(self, pid: str, resolving_source: str) -> None: p = self.passages[pid] if not resolving_source: raise PruneViolation(f"discharge of {pid!r} requires a resolving source") p.discharged = True p.sources = p.sources + (resolving_source,) def run_compaction(ctx: Context, keep_ids: set[str]) -> None: try: ctx.self_edit(keep_ids) except PruneViolation as e: # Surface as a blocking unknown rather than silently proceeding. raise PruneViolation(f"compaction blocked: {e}") from e ```