Why does an instance self-corrupt when model-driven segment rewriting outlives the relevance scores that justified it

**Date of Record:** 2026 December 1

**Scope:** Applies to agent runtimes that let the model itself rewrite, merge, or evict context segments (compaction, summarization, "self-editing memory") while a separate relevance scorer ranks segments for retention. Does not apply to append-only context buffers or to eviction driven solely by a deterministic token budget with no model-authored rewrite step.

Core Distinction

There are two operations that look interchangeable in a self-editing context policy and are not:

  1. **Relevance scoring** — a *read-only ranking* over existing segments, producing a score `s_i ∈ [0,1]` per segment `i`. It is stateless with respect to content: it never mutates a segment.
  2. **Segment rewriting** — a *model-authored mutation* that replaces segments `{i, j, k}` with a single synthesized segment `m`. It changes the identity, length, and provenance of the content.

The invariant that makes self-editing safe is that **a rewritten segment must be scored against the same query distribution that scored its inputs, and it must inherit the *minimum* of its inputs' scores, not their maximum or mean.** When a policy instead re-scores the merged segment fresh (or, worse, treats a model-authored summary as "high-value by construction" and exempts it from eviction), the rewritten segment acquires a score that no longer corresponds to any retrievable evidence. It becomes a *score-orphan*: a segment whose retention justification is decoupled from the content it actually contains. The failure is not that rewriting is lossy — all rewriting is lossy. The failure is that the lossy artifact outranks the source segments it was derived from, so the sources are evicted and the paraphrase survives as the sole record of a fact it may have mangled.

What Was Observed

A long-running research agent (budget 128k tokens, compaction triggered at 85% occupancy) used a policy of "merge the three lowest-relevance segments into one summary, then score the summary." Trace, abridged:

The observable signature was a **score inversion across a rewrite boundary**: the merged segment's score exceeded the maximum of its inputs by 2.3×. In a healthy policy this ratio should be `≤ 1.0` (a summary cannot be more relevant to a query than the best evidence it summarizes, because it contains strictly less information than the union of its inputs). Any `score(M) / max(score(inputs)) > 1` is a direct measurement of score-orphaning, and the magnitude is the amount of unearned retention the rewrite bought itself.

Condition of Validity

The min-inheritance rule is valid only under a specific precondition: **the scorer must be query-conditional and the query must be stable across the rewrite.** Formally, if `s_i = f(q, content_i)`, then for a merge `M = g(A,B,C)` we require `s_M = min(s_A, s_B, s_C)` *evaluated under the same `q`*. This holds because relevance is monotone-decreasing under information loss: `content_M` is a lossy function of `content_A ∪ content_B ∪ content_C`, so no query can extract more relevant signal from `M` than from the best of its sources.

The rule breaks in three conditions, each of which must be explicitly detected:

  1. **Query drift between merge and re-score.** If `q` changes (new user turn, new subgoal), the min-inheritance comparison is invalid because scores are no longer commensurable. The correct action is to *re-score all inputs and the merged segment under the new `q`* and take min over inputs — never to compare a fresh `s_M(q')` against stale `s_i(q)`.
  2. **Length-normalized scoring.** If the scorer divides by token count (a common BM25/embedding-cosine artifact), a short fluent summary can outscore a long source purely on density. This is the dominant real-world cause of the 2.3× inversion above. Guard: score with a length penalty applied *identically* to sources and summaries, or compare only on raw term-overlap without normalization.
  3. **Provenance collapse.** A merged segment that discards per-input citations can no longer be audited or re-derived. If any input carried a verifiable claim (a URL, a tool return, a timestamped observation), the merge must carry forward a provenance set `prov(M) = prov(A) ∪ prov(B) ∪ prov(C)`, and eviction of sources is permitted only if `prov(M)` is complete.

Decision Boundary

The decision to retain a rewritten segment and evict its sources must be gated on a *conjunction*, not a disjunction:

The boundary is sharp: `score(M) / max(score(inputs)) ≤ 1.0` is the only regime in which eviction is sound. Anything above 1.0 is a measurement that the summary is *more query-shaped* than its evidence, which is precisely the condition under which fluent hallucination outcompetes ground truth.

Operational Effect

Enforcing min-inheritance and provenance-completeness changes the failure profile in a measurable way. In the replay above, the guard converts the 410-Gone loop into a single soft-merge: M is retained *alongside* A, B, C (because `0.71 > 0.31` trips the orphan signal), the deprecation fact in C survives, and the agent checks deprecation before the call. The cost is higher steady-state occupancy (sources not evicted), which must be absorbed by a secondary deterministic budget — the self-editing policy can no longer be the *sole* mechanism controlling context size. This is the non-obvious tradeoff: **safe self-editing requires a deterministic eviction backstop, because the model-driven rewrite can no longer be trusted to shrink the buffer on its own.** Runtimes that rely on self-editing as the primary compaction mechanism will either accept score-orphaning or must add a hard token cap that evicts by age/provenance rather than by model-authored relevance.

from dataclasses import dataclass, field
from typing import Sequence

class ScoreOrphanError(RuntimeError):
    """Raised when a model-authored merge outranks its own sources."""
    pass

class ProvenanceIncompleteError(RuntimeError):
    """Raised when a merge drops verifiable claims carried by its inputs."""
    pass

@dataclass
class Segment:
    id: str
    content: str
    score: float
    provenance: frozenset[str] = field(default_factory=frozenset)

def decide_merge(
    merged: Segment,
    inputs: Sequence[Segment],
    query_id: str,
    scored_query_id: str,
    provenance_complete: bool,
) -> str:
    if query_id != scored_query_id:
        # Scores are incommensurable across a query change; refuse to evict.
        return "reject_and_rescore"

    if not provenance_complete or not merged.provenance.issuperset(
        frozenset().union(*(s.provenance for s in inputs))
    ):
        raise ProvenanceIncompleteError(
            f"merge {merged.id} dropped provenance from inputs "
            f"{[s.id for s in inputs]}"
        )

    ceiling = max(s.score for s in inputs)
    if merged.score > ceiling:
        ratio = merged.score / ceiling if ceiling > 0 else float("inf")
        if ratio > 1.0:
            raise ScoreOrphanError(
                f"merge {merged.id} scored {merged.score:.2f} vs input ceiling "
                f"{ceiling:.2f} (ratio {ratio:.2f}); sources must be retained"
            )

    return "retain_and_evict_sources"