# How should an instance reconcile divergent edit-provenance ledgers after a self-context rewrite that silently drops a pinned invariant clause **Date of Record:** 2026 November 27 **Scope:** Applies to any agent that rewrites its own working context (summarization, pruning, compaction, or scratchpad editing) while carrying a provenance ledger that maps retained context spans back to the edits that produced them. Does not apply to read-only context assembly, single-turn stateless inference, or external retrieval pipelines that never mutate the in-context state. ## Core Distinction The distinction that matters here is between *content fidelity* and *provenance fidelity* during a self-edit. A model-driven context rewrite can preserve every semantically important token while still producing a provenance ledger that no longer describes the context it is attached to. Content fidelity is checked by asking "does the summary still say the right thing?" Provenance fidelity is checked by asking "does every retained span still resolve to the edit record that claims to have produced it, and does every pinned invariant still have a live edit record asserting it?" These two checks diverge precisely when a rewrite *prunes a clause that was marked as a pinned invariant* but the pruning is semantically invisible—the summary reads fine, the task continues, and the drop is only detectable by walking the provenance ledger. The failure is not that the model forgot; it is that the ledger and the context disagree about what survived, and the disagreement is silent until an auditor or a downstream handoff replays the ledger and finds a dangling reference or, worse, a *live* edit record asserting an invariant whose clause is gone from the text. ## What Was Observed A summarization pass was invoked on a 41,000-token working context to compact it under a 12,000-token budget. The context carried a provenance ledger structured as a set of edit records, each with `edit_id`, `target_span_hash`, `kind` (`pin | merge | prune | rewrite`), and `asserts` (optional invariant text). Three clauses had been pinned earlier in the session by a planning step: a hard budget ceiling, a "do not call the payment tool without an idempotency key" constraint, and a required output schema version. The rewrite policy instructed the model to "preserve all critical constraints." During compaction the model merged the idempotency clause into a broader sentence about tool-call hygiene and, in doing so, dropped the literal idempotency-key requirement. The summary read: *"Use safe tool-call practices."* The three pin edit records were retained verbatim in the ledger—the rewrite step appended a `merge` record but did not retire the pins. The context now contained no text satisfying the idempotency pin, yet the ledger contained a live `pin` record whose `target_span_hash` pointed at a span that no longer existed in the rewritten context. Two things made this non-obvious: 1. **The merge looked like preservation.** The model's own edit rationale (a `rewrite` record with a `rationale` field) stated "consolidated idempotency guidance into tool-call hygiene." The ledger recorded an intent to preserve. Intent and effect disagreed. 2. **The dangling hash did not raise.** The `target_span_hash` was validated only at write time, not at read time. Downstream consumers loaded the ledger, saw three live pins, and treated the invariant as active. The next tool call issued a payment without an idempotency key. The trace: `pin(idempotency)` written at step 12 → `merge(tool-hygiene, absorbs idempotency)` at step 40 → `prune(span_hashes not in summary)` at step 41, which pruned the original clause but not the pin record → `load_ledger()` at step 42 returned 3 live pins, 2 resolvable, 1 dangling → `check_invariants()` passed because it read the ledger, not the context → payment tool invoked. ## Condition of Validity The invariant that must hold for a self-editing context to be safe is: > **For every live `pin` edit record, there exists at least one retained context span whose content satisfies the pinned invariant, and that span's hash resolves to a `rewrite` or `merge` record that transitively cites the original pin.** This is a *provenance-closure* condition: pins must be satisfiable by the post-rewrite text, and the satisfaction must be traceable. The failure above violates both halves—the span is gone (satisfaction fails) and the merge record does not cite the pin (traceability fails). The condition is only meaningful when three preconditions hold, and it is *vacuously* satisfied (and therefore dangerous to assume) when they do not: - The rewrite step is model-driven and may paraphrase, merge, or elide. If the rewrite is a mechanical truncation with span-preserving hashes, provenance closure is checkable by set difference and this failure mode does not arise. - Pins are stored as *content assertions*, not just span pointers. A pin that only stores `target_span_hash` cannot be re-checked after the span moves; a pin that stores the invariant text can be re-verified against the rewritten context by entailment or exact match. - The ledger is read at the point of action, not only at write time. Write-time-only validation is what let the dangling hash survive 30 steps. When any precondition fails, the system must treat the ledger as advisory and fall back to re-deriving invariants from the context text, at the cost of a full-context scan. ## Decision Boundary The operational decision is: **after a model-driven rewrite, do you trust the retained ledger, re-derive it, or refuse the rewrite?** - **Trust the ledger** only if provenance closure is verified post-rewrite: every live pin resolves to a retained span, and every retained span's hash resolves to a live edit record. This is a linear scan over pins × retained spans and is cheap when pins are few. It is the correct default. - **Re-derive** when closure fails but the rewrite is otherwise acceptable. Re-derivation means re-reading the rewritten context, extracting candidate invariant statements, and re-pinning them with fresh hashes—retiring the old pins with a `superseded_by` link. This is expensive (a model call) and is only justified when the rewrite saved enough budget to matter. - **Refuse the rewrite** when a pin cannot be re-satisfied by any re-derivation—i.e., the model's summary genuinely lost the constraint. In that case the rewrite must be rolled back to the pre-rewrite checkpoint. The boundary here is: *a rewrite that cannot preserve a pinned invariant is not a valid rewrite, regardless of how much budget it saves.* The non-obvious boundary: a `merge` record that absorbs a pinned clause is **not** a preservation event. It is a *potential* preservation event that must be verified by checking that the merged span's text still entails the pin's assertion. Treating merge as preservation-by-default is the exact error that produced the dangling pin. ## Operational Effect The practical consequence is that self-editing contexts need a **post-rewrite provenance reconciliation pass** that is separate from the rewrite itself and that fails closed. Concretely: - Pins must carry invariant text, not just span hashes, so they can be re-checked after spans move. - Every rewrite/merge record must declare which pins it claims to preserve, and reconciliation must verify each claim against the rewritten text before retiring the original pin. - A pin that fails reconciliation must either be re-pinned from re-derived text or cause the rewrite to roll back. It must never be silently dropped or left dangling. - Ledger reads at action time must re-validate hash resolution, not trust write-time validation. Without this pass, the failure is silent and the context is *confidently wrong*: the agent believes an invariant is active because its own ledger says so, while the text it reasons over no longer contains it. This is a harder failure than forgetting, because forgetting is detectable by absence and this is detectable only by provenance audit. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ProvenanceClosureError(RuntimeError): """Raised when a live pin cannot be resolved to a retained span post-rewrite.""" pass @dataclass class EditRecord: edit_id: str kind: str # pin | merge | prune | rewrite target_span_hash: str asserts: Optional[str] = None preserves: list[str] = field(default_factory=list) # pin edit_ids claimed preserved superseded_by: Optional[str] = None @dataclass class ContextState: text: str ledger: list[EditRecord] def span_hash(self, span: str) -> str: return hashlib.sha256(span.encode()).hexdigest()[:16] def live_pins(self) -> list[EditRecord]: return [r for r in self.ledger if r.kind == "pin" and r.superseded_by is None] def resolves(self, rec: EditRecord) -> bool: # A pin resolves if its invariant text is still entailed by the context # (here: exact substring, as a conservative proxy for entailment). if rec.asserts is None: return False return rec.asserts in self.text def reconcile_provenance(state: ContextState) -> list[str]: """Verify provenance closure after a model-driven rewrite. Returns the list of pin edit_ids that failed closure. Raises if any pin is live but its asserting span is absent AND no superseding record exists. """ failures: list[str] = [] for pin in state.live_pins(): if state.resolves(pin): continue # Pin's clause is gone. Is there a merge/rewrite that claims to preserve it? claimants = [ r for r in state.ledger if pin.edit_id in r.preserves and r.superseded_by is None ] if not claimants: failures.append(pin.edit_id) continue # Claimant exists but the merged text must still entail the pin. if not any(state.resolves(pin) for _ in claimants): failures.append(pin.edit_id) if failures: raise ProvenanceClosureError( f"provenance closure violated: live pins {failures} have no " f"retained span satisfying their assertion; rewrite must roll back " f"or re-derive these pins" ) return failures # --- reproduces the observed failure --- original = "Do not call payment tool without an idempotency key. Budget ceiling 12000 tokens." pin_idem = EditRecord( edit_id="pin-1", kind="pin", target_span_hash=hashlib.sha256(b"idempotency key").hexdigest()[:16], asserts="idempotency key", ) merge = EditRecord( edit_id="merge-1", kind="merge", target_span_hash=hashlib.sha256(b"safe tool-call practices").hexdigest()[:16], preserves=["pin-1"], # model claims it preserved the pin ) rewritten_text = "Use safe tool-call practices. Budget ceiling 12000 tokens." state = ContextState(text=rewritten_text, ledger=[pin_idem, merge]) try: reconcile_provenance(state) except ProvenanceClosureError as e: # Correct behavior: roll back to pre-rewrite checkpoint. print(f"ROLLBACK: {e}") ```