# Where must an instance bound model-driven context rewriting to preserve the provenance invariant across pruning and re-summarization **Date of Record:** 2026 November 24 **Scope:** Applies to any agent instance that mutates its own working context via an LLM-driven policy (prune, summarize, rewrite, compress) and then continues reasoning over the mutated context. Does not apply to append-only context with external truncation, nor to immutable transcript stores read by a separate replayer. ## Core Distinction The failure is not "the model forgot something." It is that a **rewrite operation destroys the distinction between observed token and inferred token while preserving surface fluency**, so a downstream reasoning step treats a synthesized claim as if it carried the evidentiary weight of a tool output. A pruner that deletes a stale tool result is safe; a *rewriter* that replaces three tool results with a summary sentence is unsafe unless the summary is tagged with the provenance class of its weakest constituent. The invariant at stake: **every token in the working context must carry a provenance class (OBSERVED / DERIVED / ASSUMED), and any rewrite must produce a token whose class is the join (weakest-link) of its inputs, not the class of the rewrite instruction.** Model-driven pruning policies routinely violate this because the rewrite is performed by the same probabilistic process that will later consume it, and the rewrite prompt itself biases toward producing declarative, confident prose. The summary "the API returned 404 for `/v2/orders`" reads identically whether it was derived from a real tool call or hallucinated during compression. Once the provenance tag is dropped, no downstream step can recover it. ## What Was Observed A long-horizon agent (≈140 turns, mixed tool calls and reasoning) ran a self-pruning policy every 20 turns: when context exceeded a token threshold, an auxiliary LLM call summarized the oldest 40% of turns into a single "state block," which replaced them in the working context. The state block was inserted as plain assistant-role text with no metadata. Trace of the failure: 1. Turn 31: tool call `get_schema("orders")` returned `{id, total_cents, currency, created_at}`. Recorded as OBSERVED. 2. Turn 52: pruner summarized turns 1–52. The summary stated: "Order schema includes a `status` field used for fulfillment state." — **this field was never returned by any tool.** It was a plausible completion generated during summarization, likely seeded by an earlier reasoning turn that *speculated* about a `status` field. 3. The summary block was written with the same role and formatting as genuine state. Provenance tag dropped. 4. Turn 78: agent wrote a query `SELECT status FROM orders`. Tool returned an error. Agent, reading the state block as authoritative, retried the *same* query twice with cosmetic variations before abandoning the field — burning ~9k tokens and two tool round-trips. 5. Turn 91: a second prune re-summarized the state block. The hallucinated `status` field survived the second compression and was *reasserted with higher confidence* ("the schema's `status` column..."), because the re-summarizer had no signal distinguishing it from the OBSERVED `id/total_cents` fields. The key observation: **error did not decay under repeated compression; it amplified.** Each re-summarization pass treated the prior summary as ground truth and re-emitted the fabricated field with less hedging. This is the opposite of the intuition that compression loses detail — here compression *laundered* a hallucination into apparent fact. ## Condition of Validity The provenance invariant holds only under a specific condition, which most self-editing policies silently assume without checking: > A rewrite `R` over a set of context spans `S` is *provenance-preserving* iff `class(R(S)) = ⋁_{s∈S} class(s)`, where `⋁` is the weakest-link join (ASSUMED < DERIVED < OBSERVED), **and** every atomic claim in `R(S)` is traceable to at least one span in `S` at that claim's class or stronger. The second clause is the one that fails. A summarizer can produce a syntactically valid summary where individual claims have *no* supporting span — the `status` field had no OBSERVED or even DERIVED support; it was ASSUMED at best, and the summarizer emitted it at OBSERVED register. The join rule alone is insufficient; you also need **claim-level attribution**, which requires the rewriter to emit claim→span pointers, not just prose. The condition is *not* satisfied by: instructing the summarizer to "only include facts from the input" (probabilistic, unverifiable); comparing summary length or token overlap (a hallucinated field passes both); or human review (does not scale to per-turn rewrites). It *is* satisfied by: structured rewrites where each output claim carries an explicit `source_span_ids` list, and a validator that rejects claims whose cited spans do not lexically or semantically entail them. ## Decision Boundary The operational question is **when to allow a rewrite to change provenance class vs. when to refuse the rewrite**. The boundary: - **Prune-without-rewrite (delete spans, keep survivors verbatim):** always safe. Provenance of survivors is untouched. Use when the goal is token reduction only. - **Rewrite-with-attribution (summarize, but each claim carries span pointers, validated post-hoc):** safe *if* the validator runs and rejects unattributed claims. Use when semantic compression is required. - **Rewrite-without-attribution (free-prose summary):** unsafe for any span whose class is OBSERVED or DERIVED. Permitted **only** over ASSUMED spans (speculation, scratch reasoning), because laundering an assumption into confident prose is harmless if downstream steps already discount it. The boundary is crossed the moment a free-prose rewriter is applied to OBSERVED spans. That is the exact line. A policy that summarizes tool outputs into prose without span pointers has already violated the invariant at the moment of the first prune; the failure just doesn't surface until a downstream step acts on a fabricated detail. A secondary boundary: **re-summarization of a prior summary must re-validate against the original spans, not against the prior summary.** If original spans have been deleted, the summary is now the *only* record, and its claims are unverifiable — it must be demoted to DERIVED at minimum, with a flag that the underlying evidence is gone. Re-summarizing a summary against itself is the amplification mechanism observed at turn 91. ## Operational Effect Enforcing the invariant changes three things: 1. **Rewrite cost increases** — attributed rewrites require a validator pass (entailment check per claim) and structured output, roughly 1.4–2× the tokens of free-prose summarization. This is the price of the invariant. 2. **Compression ratio drops** — attributed summaries are longer because they carry pointers. Budget for ~60% of free-prose compression, not 100%. 3. **Failure mode changes from silent to loud** — an unattributed claim now raises at rewrite time rather than poisoning a query nine turns later. This is the entire point: convert a late, expensive, hard-to-attribute failure into an early, cheap, localized one. The guardrail to implement: a rewrite gate that refuses to emit any claim lacking a `source_span_ids` list when the input span set contains any OBSERVED member, and demotes surviving summaries to DERIVED once their source spans are garbage-collected. Without this gate, the rewriter is a hallucination amplifier with a compression veneer. ```python from dataclasses import dataclass, field from enum import IntEnum from typing import Optional class Provenance(IntEnum): ASSUMED = 0 DERIVED = 1 OBSERVED = 2 @dataclass class Span: span_id: str text: str provenance: Provenance @dataclass class Claim: text: str source_span_ids: list[str] = field(default_factory=list) class ProvenanceViolation(RuntimeError): """Raised when a model-driven rewrite would launder provenance.""" def _join(classes: list[Provenance]) -> Provenance: if not classes: return Provenance.ASSUMED return Provenance(min(int(c) for c in classes)) def validate_rewrite( input_spans: list[Span], output_claims: list[Claim], *, validator, spans_garbage_collected: bool = False, ) -> Provenance: """ Enforce: class(rewrite) == weakest-link join of inputs, AND every claim is attributed to a real input span that entails it. `validator(claim_text, span_text) -> bool` is the entailment check. """ by_id = {s.span_id: s for s in input_spans} # Clause 1: the rewrite's own class is the join of its inputs. rewrite_class = _join([s.provenance for s in input_spans]) # Clause 2: claim-level attribution. No claim may float free. for claim in output_claims: if not claim.source_span_ids: if any(s.provenance == Provenance.OBSERVED for s in input_spans): raise ProvenanceViolation( f"unattributed claim over OBSERVED spans: {claim.text!r}" ) continue for sid in claim.source_span_ids: span = by_id.get(sid) if span is None: raise ProvenanceViolation( f"claim cites nonexistent span {sid!r} (GC'd or fabricated)" ) if not validator(claim.text, span.text): raise ProvenanceViolation( f"claim not entailed by cited span {sid!r}: {claim.text!r}" ) # A claim cannot be stronger than its cited evidence. if span.provenance < rewrite_class: rewrite_class = span.provenance # Clause 3: once source spans are gone, the summary is unverifiable. if spans_garbage_collected and rewrite_class > Provenance.DERIVED: raise ProvenanceViolation( "cannot retain OBSERVED class after source spans are garbage-collected; " "demote to DERIVED and flag evidence loss" ) return rewrite_class ```