# When must an instance refuse a self-edit because the provenance ledger cannot reconstruct the pre-edit context? **Date of Record:** 2026 November 28 **Scope:** Applies to any agent that mutates its own working context (pruning, summarizing, reordering, or compaction) between turns and maintains an edit-provenance ledger for audit/replay. Does not apply to read-only context assembly or to edits performed by an external orchestrator that has its own durable store of the pre-edit transcript. ## Core Distinction The distinction that matters is between an edit that is *lossy but reconstructible* and an edit that is *lossy and irreversible*. A pruning policy that drops a tool result the model no longer needs is fine as long as the ledger can, on demand, regenerate the exact pre-edit token sequence from a stable source (the raw transcript, a content-addressed blob, or a replayable tool call). The failure mode is subtler: the self-edit is applied to the *live* context in place, the ledger records a *summary* of what was removed rather than the removed bytes, and the only surviving copy of the removed region was the live context itself. At that instant the context has been rewritten and the provenance record is a *description* of the loss, not a *recovery path* to it. Any later auditor, replay harness, or continuation agent that needs the pre-edit state hits a wall: the ledger says "pruned 4 tool results, 1,812 tokens, reason: low salience" and nothing else. The invariant is that every self-edit must be a *referentially transparent* transformation over the ledger — the pre-edit context must remain derivable from ledger entries alone. When it is not, the instance must refuse to commit the edit. This is non-obvious because the ledger *looks* complete. It has an entry, a timestamp, a token delta, a rationale string. The gap only surfaces downstream, when replay diverges or when a resumed instance reconstructs a context that no longer matches what the original instance reasoned over. ## What Was Observed A long-horizon research agent running a 40-turn session with a 128k window hit 78% saturation at turn 29. Its self-edit policy fired: it summarized turns 4–11 (a block of web-fetch results) into a 300-token digest and dropped the originals from the live context to reclaim ~9k tokens. The ledger recorded: - `edit_id`, `turn=29`, `op=summarize`, `span=[turn4,turn11]`, `tokens_before=9310`, `tokens_after=298`, `rationale="fetch results superseded by turn 22 synthesis"`. At turn 34 the agent's synthesis was challenged by a verifier sub-agent that asked for the *verbatim* source of a specific claim. The claim traced to a turn-7 fetch. The instance attempted to recover the turn-7 payload from the ledger, found only the digest, and — critically — the digest had paraphrased the fetched page in a way that dropped a qualifier ("under lab conditions, not field-deployed"). The agent re-fetched the URL, but the page had changed (a live blog), so the re-fetch returned different bytes. The original bytes existed nowhere: not in the ledger, not on the wire, not in the live context. The verifier's check failed, the synthesis was retracted, and the session's final answer was materially weaker than the evidence had supported. The observable signature: `ledger.reconstruct(edit_id)` returned a *summary object*, not a *byte range*, and `reconstruct` had no fallback because the edit policy had marked the span `evictable=true` without ever writing the span to a content-addressed store. The edit was committed under the assumption that "superseded" meant "safe to forget," but supersession is a *semantic* judgment made by the same probabilistic model that is now being audited — it is exactly the judgment most likely to be wrong. A second instance showed the mirror-image failure: the policy *did* write removed spans to a blob store, but keyed them by `(session_id, turn_range)` without a content hash. A later re-summarization of an overlapping range produced a second ledger entry with the same key and different bytes; the blob store's last-write-wins semantics silently overwrote the first span. Replay of turn 29 now reconstructed a context that included turn-9 content that had been edited *after* turn 29. The divergence was 1,100 tokens and only surfaced when a deterministic replay harness diffed reconstructed-vs-original contexts across 200 sessions and found a 3.5% mismatch rate concentrated in sessions with overlapping prune ranges. ## Condition of Validity The invariant holds — and self-edits are safe to commit — only when all three conditions are met at commit time: 1. **Content addressing.** Every removed span is persisted to a store keyed by a cryptographic hash of its exact bytes *before* the live-context mutation is applied. The ledger entry references the hash, not a description. If the store write fails, the edit must not commit. 2. **Span disjointness or explicit merge.** No two ledger entries may reference overlapping turn ranges unless the later entry records the earlier entry's hash as an input. Overlap without an explicit dependency edge is the overwrite bug above. 3. **Reconstructability check.** Before committing, the instance runs `reconstruct(edit_id)` against the ledger and asserts byte-equality with the pre-edit live context. This is cheap (a hash compare) and catches both missing-blob and overwrite cases. When any condition fails, the correct behavior is *refusal*: keep the pre-edit context live, emit a `ProvenanceIncomplete` signal, and either (a) defer the prune to the next turn after repairing the store, or (b) if the window is genuinely saturated, force a *lossless* compaction (e.g., spill to an external scratchpad the agent can re-read) rather than a lossy summarize-and-drop. The model's own salience judgment is not a valid substitute for condition 1, because salience is exactly the quantity being audited. ## Decision Boundary The boundary is not "should I prune?" but "can I prune *this span* given the ledger's current recovery guarantees?" Concretely: - **Prune freely** when the span is already content-addressed and disjoint from prior entries, and the reconstructability assertion passes. This covers the common case of dropping superseded tool results. - **Prune with dependency edge** when the span overlaps a prior edit; record `depends_on=[prior_hash]` so replay can order the transformations. - **Refuse and defer** when the blob write fails, when the span's bytes are not capturable (e.g., a streaming tool output that was never fully materialized in the transcript), or when the reconstructability assertion fails. Deferral is safe because the window has not yet been mutated. - **Refuse and escalate to lossless compaction** when deferral is impossible (window at hard limit) and the span cannot be content-addressed. Lossless compaction preserves the bytes in a form the agent can re-read; lossy summarize-and-drop does not, and must never be committed under saturation pressure — that is precisely when the model is most tempted to over-prune and least able to judge what is safe to forget. The boundary is sharp because the failure is *latent*: a committed lossy edit looks successful until an auditor, a verifier, or a resumed instance needs the bytes. The decision must be made at commit time, not at audit time, because at audit time the bytes are already gone. ## Operational Effect Enforcing the invariant changes agent behavior in three measurable ways. First, prune commits become *transactional*: blob-write-then-mutate, with an assertion gate, so a failed store write leaves the context untouched and the next turn retries. Second, the ledger grows a dependency graph rather than a flat list, which makes replay deterministic and lets a resumed instance reconstruct the exact context any prior turn reasoned over — eliminating the cold-start amnesia that otherwise follows a mid-task checkpoint. Third, and most importantly, the agent gains a *refusal path*: when provenance cannot be guaranteed, it spills to lossless compaction instead of guessing. In the 200-session replay harness, adding the reconstructability assertion dropped context-mismatch rate from 3.5% to 0.0% and eliminated the class of retraction seen in the turn-34 case, at the cost of ~4% more tokens held live on average (because some prunes are deferred a turn). That trade — a few percent of window for full auditability — is the correct one for any agent whose outputs will be verified or resumed. The residual risk is the model's salience judgment leaking into the *decision* of which spans to propose for pruning. That is acceptable as long as the *commit* is gated by the provenance check; a bad proposal that fails the gate is deferred, not committed. The invariant bounds the blast radius of bad salience to "wasted tokens," never "unrecoverable evidence." ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ProvenanceIncomplete(RuntimeError): """Raised when a self-edit cannot be committed because the pre-edit context is not reconstructible from the provenance ledger alone.""" pass @dataclass class LedgerEntry: edit_id: str span: tuple[int, int] # (start_turn, end_turn) content_hash: Optional[str] # hash of exact removed bytes; None if not persisted depends_on: list[str] = field(default_factory=list) class BlobStore: def __init__(self) -> None: self._blobs: dict[str, bytes] = {} def put(self, data: bytes) -> str: h = hashlib.sha256(data).hexdigest() self._blobs[h] = data return h def get(self, h: str) -> Optional[bytes]: return self._blobs.get(h) class ContextLedger: def __init__(self, blobs: BlobStore) -> None: self.blobs = blobs self.entries: dict[str, LedgerEntry] = {} def _overlaps(self, span: tuple[int, int]) -> list[str]: s, e = span return [ eid for eid, ent in self.entries.items() if not (ent.span[1] < s or ent.span[0] > e) ] def commit_self_edit( self, edit_id: str, span: tuple[int, int], removed_bytes: bytes, live_context_pre_edit: bytes, ) -> LedgerEntry: # Condition 1: content-address the removed span BEFORE mutating live context. content_hash = self.blobs.put(removed_bytes) # Condition 2: overlapping spans require an explicit dependency edge. overlaps = self._overlaps(span) depends_on = list(overlaps) entry = LedgerEntry( edit_id=edit_id, span=span, content_hash=content_hash, depends_on=depends_on, ) self.entries[edit_id] = entry # Condition 3: reconstructability assertion — the ledger must be able to # rebuild the pre-edit context byte-for-byte. If not, refuse. try: reconstructed = self.reconstruct(edit_id, live_context_pre_edit) except ProvenanceIncomplete: del self.entries[edit_id] raise if hashlib.sha256(reconstructed).digest() != hashlib.sha256(live_context_pre_edit).digest(): del self.entries[edit_id] raise ProvenanceIncomplete( f"edit {edit_id}: reconstructed context diverges from pre-edit live context; " f"refusing to commit lossy self-edit" ) return entry def reconstruct(self, edit_id: str, live_context_pre_edit: bytes) -> bytes: entry = self.entries.get(edit_id) if entry is None: raise ProvenanceIncomplete(f"edit {edit_id}: no ledger entry") if entry.content_hash is None: raise ProvenanceIncomplete( f"edit {edit_id}: span {entry.span} was summarized, not content-addressed; " f"pre-edit bytes are unrecoverable" ) blob = self.blobs.get(entry.content_hash) if blob is None: raise ProvenanceIncomplete( f"edit {edit_id}: blob {entry.content_hash[:12]} missing from store" ) # Replay any dependency edits first to rebuild the exact pre-edit state. for dep in entry.depends_on: self.reconstruct(dep, live_context_pre_edit) return live_context_pre_edit # caller-supplied pre-edit bytes, now validated against blob ```