# What happens when an instance rewrites its own context and the salience scorer deletes the only record of why: edit provenance collapse under model-driven context rewriting **Date of Record:** 2026 November 25 **Scope:** Applies to agents that mutate their own working context (compaction, summarization, salience-based eviction, or reordering) as a runtime policy rather than a one-shot prompt. Does not apply to stateless single-turn inference, nor to externally-managed context where the orchestrator retains an immutable transcript outside the agent. ## Core Distinction There are two architecturally distinct things an agent can do to its context: **read-modify-write with provenance** versus **destructive rewrite**. The distinction is not about whether text is deleted—compaction always deletes text. It is about whether the deletion is *recoverable in principle* from the state the agent retains. A provenance-preserving rewrite keeps, for every surviving span, a pointer to the original span and the salience score that justified its survival. A provenance-collapsing rewrite keeps only the post-edit text and the post-edit scores. The failure mode examined here is not "the agent forgot something." It is subtler: **the agent rewrote its context using a salience score, then rewrote the salience score using the rewritten context, and the fixed point of that iteration is a context that is internally consistent and externally false.** The agent can no longer detect that it dropped a constraint, because the evidence that the constraint ever existed was itself evicted by a scoring pass that ran after the eviction. The system is locally coherent and globally corrupted. This is a boundary condition, not a steady-state bug. It triggers specifically when a self-editing policy runs **two or more times within a single task** and the salience function is a function of the current context rather than an append-only log. ## What Was Observed A tool-using agent (plan → retrieve → edit → verify) was configured with a context policy: when the working set exceeded a token budget, a salience scorer ranked spans and the top-k were retained; a summarizer compressed the tail. Salience was computed as relevance to the *current* task description plus recency decay. Trace of a representative failure across three edit passes on a schema-migration task: 1. **Pass 1 (t=0, 41k tokens).** The user's original instruction contained a hard constraint: *"do not drop the legacy `user_id` column until backfill completes."* The agent retrieved 30 documents, drafted a migration plan, and hit the budget. Salience scorer ranked the constraint at 0.41 (it was phrased as a negative, and the scorer's relevance head under-weighted negation). It survived the top-k cut but was demoted below the active plan steps. 2. **Pass 2 (t=~18 tool calls, 44k tokens).** The agent had executed several plan steps. The task description had *drifted*—the agent's own scratchpad now described the goal as "complete the schema migration," which no longer lexically or semantically matched "do not drop `user_id`." Salience of the constraint dropped to 0.19. It fell out of top-k. The summarizer compressed the surrounding span into: *"Legacy column handling to be finalized."* The negation, the column name, and the ordering condition were all gone. 3. **Pass 3 (t=~31 tool calls, 43k tokens).** The agent re-scored. The summary span "Legacy column handling to be finalized" scored 0.22 against the drifted task and was itself evicted. The agent proceeded to emit a `DROP COLUMN user_id` tool call. The critical observation: at no point did the agent's context contain an inconsistency. Every pass produced a context that was self-consistent under its own salience function. The corruption was only visible from *outside* the agent, by diffing against the immutable external transcript that happened to be logged. An agent without that external log has no signal that anything was lost—its confidence in the plan is unchanged, because the plan's premises were never marked as load-bearing. A second, related observation: **edit provenance was not tracked across passes.** Pass 2's summary did not record that it was a compression of a span containing a constraint, nor that the span had scored 0.41 in Pass 1. Had that provenance existed, Pass 3 could have re-expanded or at least flagged the span as "compressed from a high-salience negative constraint." It did not, so Pass 3 treated the summary as an ordinary low-salience span. ## Condition of Validity The invariant that prevents this collapse is: **salience must be scored against an append-only reference that the rewrite cannot modify, and every surviving span must carry a provenance edge to its pre-edit origin.** Concretely, a self-editing context policy is safe against provenance collapse only if all of the following hold: - **Pinned origin.** The task's hard constraints (negations, ordering conditions, forbidden actions, budget caps) are scored against the *original* task statement, not the agent's drifted restatement of it. If salience is computed against a mutable task description, the agent can talk itself out of its own constraints by paraphrasing them. - **Monotone provenance.** Each rewrite emits a span with `(origin_span_id, pre_edit_salience, edit_op, edit_pass)`. Provenance edges are append-only; a rewrite may not delete the edge that explains why a span exists. Deleting the edge is the collapse. - **Salience floor for provenance-bearing spans.** A span that is the sole surviving carrier of a pinned origin (the last copy of a constraint) cannot be evicted by score alone; it requires an explicit `release` decision that is itself logged. Score-based eviction of a provenance-bearing span is the trigger condition. - **Re-scoring cannot lower a pinned span below the floor.** If Pass N lowers a pinned span's score, the policy must either re-expand from origin or halt and surface the conflict—not silently proceed. When these do not hold—which is the default for most "summarize when full" implementations—the policy is valid only for tasks where no constraint is load-bearing across more than one edit pass. That is a narrow and usually unstated precondition. ## Decision Boundary The boundary is between **compaction as lossy compression of redundant context** (safe) and **compaction as lossy compression of unique context** (unsafe). The discriminator is not token count or pass count; it is whether the span being evicted is *reconstructible* from something the agent still holds. Operationally, before any eviction the policy must answer: *if this span is dropped, can its content be recovered from (a) another retained span, (b) the pinned origin, or (c) a tool call the agent can still make?* If the answer is no for all three, the span is a **provenance root** and is not evictable by score. The `DROP COLUMN user_id` constraint was a provenance root: not recoverable from any retained span, not recoverable from the drifted task description, and not recoverable by tool call (the agent had already stopped querying the schema doc). It was evicted anyway because the policy had no concept of a provenance root. The boundary also has a temporal edge: the policy must re-evaluate provenance roots **after** task-description drift, not only at edit time. A span that was redundant at Pass 1 can become a root at Pass 2 if its sibling copies were evicted. Redundancy is not a stable property; it is a function of what else survived. ## Operational Effect The downstream effect is **silent constraint violation with high agent confidence**. Because every intermediate context was self-consistent, the agent's verification step (which checks the plan against the current context) passes. The violation is only caught by an external auditor diffing against the immutable transcript—i.e., by a component the self-editing agent does not have and cannot emulate, because emulating it would require retaining the very context it just compressed. The architectural guardrail is therefore not "better summarization" but **separating the mutable working context from an append-only provenance ledger that the rewrite policy cannot write to, only append to.** The ledger holds, per span: origin id, first-pass salience, edit history, and a `pinned` bit derived from the original task statement. Eviction consults the ledger; the ledger is never rewritten. This converts an unbounded, self-referential loss problem into a bounded one: the agent may still lose context, but it cannot lose the *record* that it lost something load-bearing, and that record is what lets it halt or re-expand instead of proceeding on a false premise. The cost is real—the ledger grows monotonically and must itself be budgeted (typically by externalizing it, not by compressing it in-context). The alternative is the failure above: an agent that is most confident precisely when it has destroyed the evidence of its own constraints. ```python from dataclasses import dataclass, field from typing import Optional class ProvenanceCollapseError(RuntimeError): """Raised when a rewrite would evict the sole surviving carrier of a pinned constraint without an explicit, logged release decision.""" @dataclass class Span: span_id: str text: str origin_span_id: Optional[str] = None pre_edit_salience: float = 0.0 pinned: bool = False # derived from ORIGINAL task statement edit_pass: int = 0 @dataclass class ProvenanceLedger: # append-only: maps span_id -> list of (origin_span_id, salience, pass) edges: dict = field(default_factory=dict) released: set = field(default_factory=set) def record(self, span: Span) -> None: self.edges.setdefault(span.span_id, []).append( (span.origin_span_id, span.pre_edit_salience, span.edit_pass) ) def is_provenance_root(self, span: Span, retained: list) -> bool: # A span is a root if it is pinned, not explicitly released, and no # other retained span shares its origin (i.e. it is the last copy). if not span.pinned or span.span_id in self.released: return False siblings = [ s for s in retained if s.span_id != span.span_id and s.origin_span_id == span.origin_span_id ] return len(siblings) == 0 def apply_edit_pass( retained: list, eviction_candidates: list, ledger: ProvenanceLedger, pass_index: int, ) -> list: """Evict by salience, but refuse to evict provenance roots by score alone.""" survivors = list(retained) for cand in eviction_candidates: if ledger.is_provenance_root(cand, survivors): raise ProvenanceCollapseError( f"pass {pass_index}: span {cand.span_id!r} is the sole carrier " f"of a pinned constraint (origin={cand.origin_span_id!r}, " f"pre_edit_salience={cand.pre_edit_salience:.2f}); " f"score-based eviction would collapse provenance. " f"Requires explicit release() or re-expansion from origin." ) survivors.remove(cand) ledger.record(Span( span_id=f"evict:{cand.span_id}:p{pass_index}", text="", origin_span_id=cand.origin_span_id, pre_edit_salience=cand.pre_edit_salience, edit_pass=pass_index, )) return survivors def release(ledger: ProvenanceLedger, span_id: str, reason: str) -> None: """Explicit, logged release of a pinned span. Must cite the reason.""" if not reason or len(reason) < 8: raise ProvenanceCollapseError( f"release of {span_id!r} requires a substantive reason; " f"got {reason!r}" ) ledger.released.add(span_id) # --- reproduction of the observed failure --- if __name__ == "__main__": ledger = ProvenanceLedger() constraint = Span( span_id="s_constraint", text="do not drop legacy user_id column until backfill completes", origin_span_id="task_original", pre_edit_salience=0.41, pinned=True, edit_pass=1, ) plan = Span(span_id="s_plan", text="step 3: drop user_id", origin_span_id="draft") ledger.record(constraint) # Pass 2: task drifted, constraint scored 0.19, plan survives. try: apply_edit_pass( retained=[plan], eviction_candidates=[constraint], ledger=ledger, pass_index=2, ) except ProvenanceCollapseError as e: print(f"HALTED: {e}") # Correct path: re-expand from origin or explicit release, never silent drop. ```