# How should an instance preserve provenance when a self-editing context prunes its own rewrite log **Date of Record:** 2026 November 27 **Scope:** Applies to any agent that rewrites or prunes its own context window between turns and maintains a provenance ledger recording *which* prior edits produced each surviving span. Does not cover external summarization by a separate process, nor one-shot prompt compression performed before the instance is instantiated. ## Core Distinction There are two ways a self-editing context can "prune." The first is **content pruning**: removing spans, replacing them with summaries, or lowering their token weight while leaving the provenance ledger structurally intact. The second is **provenance pruning**: the rewrite operation also drops, merges, or re-aliases the ledger entries that pointed to the removed spans. Only the second is dangerous, and it is dangerous in a way that is invisible at the moment of pruning. The failure is not that information is lost. Loss of information is the intended effect of pruning. The failure is that the *record of what was lost and why* is lost along with it, so the instance can no longer distinguish "I never knew X" from "I chose to forget X." That distinction is the entire basis on which a later turn can decide whether to re-fetch, re-derive, or trust a summary. When the ledger is pruned in lockstep with the content, the instance's self-model of its own history silently diverges from its actual history, and every subsequent edit compounds the divergence. ## What Was Observed An instance running a long-horizon research task was given a self-editing loop: every N turns it scored spans in its context window by recency-weighted relevance to the active subgoal, and when the window exceeded a token budget it replaced the lowest-scoring spans with a generated summary and deleted the originals. Each replacement wrote a diff record into a provenance ledger: `{removed_span_ids, summary_id, edit_turn, rationale}`. The ledger was itself stored in context, at the tail. At turn 41 the window crossed the hard budget. The scorer ranked the *ledger entries themselves* as low-relevance (they referenced subgoals already marked complete) and pruned the three oldest diff records, replacing them with a single line: "Earlier edits consolidated." The content summaries they described survived. The record of what those summaries had replaced did not. The observable consequence appeared at turn 58. The instance needed to answer a factual question whose answer had lived in one of the pruned spans. It queried its own context, found the surviving summary (which had paraphrased the fact loosely and dropped a numeric qualifier), and — because the diff record that would have flagged "this is a lossy summary of a span you once held verbatim, with a numeric qualifier" was gone — treated the summary as ground truth. It reported the unqualified number with full confidence. On replay with the ledger pinned, the same instance at the same turn correctly flagged the summary as lossy and re-derived the fact from a tool call. The only difference between the two runs was the presence of three diff records. A second, subtler trace: because the ledger was pruned by the *same* relevance scorer that pruned content, and the scorer's notion of relevance was anchored to the *current* subgoal, the ledger entries most likely to be pruned were exactly those describing edits made under *previous* subgoals. This is an adversarial selection: the pruning policy systematically deletes the provenance for precisely the context whose reinterpretation under a new subgoal is most likely to be needed. The instance forgets not uniformly but preferentially, and preferentially in the direction that maximizes future misinterpretation. ## Condition of Validity The invariant that was violated: **the provenance ledger must be monotonically append-only with respect to the content it describes, and must never be subject to the same relevance-scoring policy as content.** Formally, for any content span `s` removed at edit `e`, the diff record `d(s, e)` must remain retrievable for as long as any descendant of `s` (a summary, a re-derivation, a citation) remains in context. The ledger's lifetime is bounded below by the lifetime of its dependents, not by its own relevance score. This condition holds trivially when the ledger is stored outside the context window (external store, tool-accessible). It fails specifically and only when the ledger is *in-context* and *co-scored* with content. The failure requires three jointly necessary conditions: 1. The ledger lives inside the same window it governs. 2. The pruning policy is model-driven and goal-conditioned (so it can rank ledger entries low). 3. Surviving summaries carry no self-describing lossiness marker that is independent of the ledger. Remove any one and the failure cannot occur. Remove (1) and the ledger is safe by construction. Remove (2) and ledger entries are pruned only by age or size, not by a scorer that can be fooled. Remove (3) — i.e., make every summary carry an inline `lossy=true, source_span_hash=…` tag — and even a pruned ledger leaves a recoverable breadcrumb. ## Decision Boundary The instance must decide, at each edit, whether a candidate span is *content* or *provenance*. The boundary is not "is it a diff record" — it is **"does any other span in the window depend on this one for its interpretation?"** A diff record is provenance if any surviving summary, citation, or derived claim references it. A summary that no other span references is content and may be pruned freely. A diff record referenced by a surviving summary is provenance and must be pinned regardless of its relevance score. Operationally, this means the relevance scorer must be run with a **dependency filter applied first**: before scoring, mark every span that is a transitive dependency of any span the instance intends to keep, and exempt marked spans from pruning. The scorer ranks the remainder. A span that is both low-relevance *and* a dependency is a contradiction the instance must resolve by keeping the span, not by trusting the score — because the score is computed against the current subgoal and the dependency exists precisely because a *future* subgoal may need it. The boundary case that breaks naive implementations: a diff record whose referenced summary has itself been pruned. Such an orphaned record is genuinely prunable — its dependent is gone. But the instance must verify the dependent is gone by checking the *current* window, not by trusting that a prior edit removed it, because prior edits are exactly what may have been mis-recorded. This is the recursive trap: to know whether a ledger entry is safe to prune, you must consult the ledger, which may be the thing you pruned. ## Operational Effect The architectural consequence is a **two-tier context**: a mutable content tier subject to model-driven scoring and pruning, and an immutable provenance tier that is append-only for the instance's lifetime and is *never* scored by the content policy. The provenance tier may be compacted only by a lossless, verifiable operation (hash-chained consolidation that preserves the ability to answer "what did span X originally say, and who removed it") — never by a generative summarizer whose output cannot be checked against the original. When this invariant is enforced, the failure mode observed above disappears: the instance at turn 58 finds the pinned diff record, sees `lossy=true, dropped_qualifier="±3%"`, and either re-derives or qualifies its answer. When it is not enforced, the instance's confidence and its accuracy decouple silently, and the decoupling is undetectable from inside because the evidence of the decoupling was pruned by the same policy that caused it. The guardrail must be enforced *before* the scorer runs, not after, because a post-hoc check ("did we prune any dependencies?") requires the ledger you may have just pruned. The check is only sound as a pre-condition on the edit set. ```python import hashlib from dataclasses import dataclass, field from typing import Dict, Set, List class ProvenanceInvariantError(RuntimeError): """Raised when a self-edit would prune a span that a surviving span depends on.""" pass @dataclass class Span: span_id: str text: str is_provenance: bool = False depends_on: Set[str] = field(default_factory=set) class SelfEditingContext: def __init__(self, token_budget: int): self.token_budget = token_budget self.spans: Dict[str, Span] = {} self.ledger: List[dict] = [] # append-only provenance tier def add(self, span: Span) -> None: self.spans[span.span_id] = span def _dependents_of(self, span_id: str) -> Set[str]: return {s.span_id for s in self.spans.values() if span_id in s.depends_on} def _transitive_dependents(self, span_id: str) -> Set[str]: seen: Set[str] = set() frontier = [span_id] while frontier: cur = frontier.pop() for dep in self._dependents_of(cur): if dep not in seen: seen.add(dep) frontier.append(dep) return seen def prune(self, candidate_ids: List[str], scorer_ranked: List[str]) -> None: """Prune content spans. Provenance spans and any span with surviving dependents are exempt, regardless of scorer rank.""" to_remove: Set[str] = set() for sid in scorer_ranked: if sid not in candidate_ids: continue span = self.spans.get(sid) if span is None: continue if span.is_provenance: continue # provenance tier is never scored by content policy if self._transitive_dependents(sid): raise ProvenanceInvariantError( f"refusing to prune {sid!r}: surviving dependents " f"{sorted(self._transitive_dependents(sid))} rely on it for interpretation" ) to_remove.add(sid) for sid in to_remove: span = self.spans.pop(sid) self.ledger.append({ "removed": sid, "text_hash": hashlib.sha256(span.text.encode()).hexdigest()[:16], "edit_turn": len(self.ledger), }) def replace_with_summary(self, target_id: str, summary: Span) -> None: if target_id not in self.spans: raise ProvenanceInvariantError(f"cannot summarize missing span {target_id!r}") summary.is_provenance = False summary.depends_on.add(target_id) # Pin the provenance record for the replaced span. self.spans[target_id].is_provenance = True self.add(summary) self.ledger.append({ "summarized": target_id, "summary": summary.span_id, "lossy": True, # generative summaries are lossy by construction }) ```