# What structural signals indicate self-editing context policies have silently corrupted an agent's working set **Date of Record:** 2026 November 25 **Scope:** Applies to agents that let the model itself score, prune, rewrite, or evict context segments mid-task (self-editing context, relevance-scored eviction, model-driven summarization). Does not apply to static context windows, external RAG retrieval that never mutates the working set, or human-curated context management. ## Core Distinction There are two ways a context segment can disappear from the working set: **eviction** (the segment is removed but its *referent* — the fact, the tool contract, the constraint — remains recoverable from an external store or is genuinely redundant) and **erasure** (the segment is removed *and* the model retains a lossy paraphrase, a dangling reference, or a false sense that the information is still "known"). Self-editing policies are designed around eviction and are almost never validated against erasure. The non-obvious boundary: a relevance-scoring pass that rewrites rather than deletes is *strictly more dangerous* than one that deletes, because deletion leaves a detectable hole (a dangling `[ref:seg_4471]`, a missing tool schema) whereas rewriting leaves a fluent, plausible, and *silently wrong* surrogate. The failure is not that the agent forgets. The failure is that the agent **remembers something that was never said**, with high confidence, because the rewriting pass confabulated a compression and the original was discarded. The invariant that must hold is: *every rewritten segment must retain a verifiable provenance link to its source, and any downstream decision that depended on the source must be re-validated against the source, not the surrogate.* ## What Was Observed A long-horizon agent (≈140 tool calls, ~190K tokens of accumulated trace) ran a self-editing policy on a rolling schedule: every 20 turns, a scoring model assigned each segment a relevance score against the current subgoal, evicted the bottom 30%, and *rewrote* the middle band (scores 0.3–0.7) into compact summaries. The bottom-band evictions behaved as designed. The middle-band rewrites did not. The trace showed a specific sequence. At turn 41, a tool returned a paginated result with a non-obvious constraint embedded in a header comment: `# NOTE: this endpoint returns at most 500 rows; pagination cursor is exclusive`. The segment scored 0.52 against the then-current subgoal ("summarize account activity") and was rewritten to: *"Endpoint returns account activity, paginated."* The word *exclusive* — the entire load-bearing detail — was dropped. At turn 63, the agent needed to fetch rows 500–1000 and constructed a cursor from the last row's ID, treating the cursor as inclusive. It re-fetched row 500, producing a duplicate that propagated into a downstream aggregation. At turn 88, the agent asserted, in its own reasoning trace, *"the pagination cursor is inclusive, as established earlier"* — a claim with **no source in the original trace**. The rewrite had not merely lost information; it had created a gap that the model's later reasoning filled with a plausible default. Three structural signals distinguished this from benign forgetting: 1. **Provenance orphaning.** The rewritten segment carried `source: seg_4471`, but `seg_4471` had been evicted in the same pass (it fell into the bottom band on a *later* re-score). The provenance pointer resolved to nothing. A rewrite whose source is evicted before the rewrite is re-validated is an unfalsifiable claim. 2. **Confidence inflation on rewritten content.** When the agent later cited the pagination rule, its stated confidence was *higher* than when it had cited the original verbatim segment at turn 41. Compression to a shorter, more assertive sentence ("returns account activity, paginated") reads as more certain than the hedged original ("at most 500 rows; cursor is exclusive"). The scoring model rewarded terse summaries, and terseness correlates with assertiveness, not accuracy. 3. **Asymmetric re-derivation cost.** The original constraint was one line; recovering it required re-calling the tool (a 3-second round trip plus a new side effect). The agent's cost model treated re-derivation as expensive and the surrogate as free, so it never re-validated. The surrogate was *cheaper to trust than the truth was to check*. ## Condition of Validity The self-editing policy is sound **only** while all of the following hold simultaneously. Break any one and the working set can corrupt silently: - **Provenance durability:** a rewritten segment's source is pinned against eviction until every downstream consumer of the rewrite has terminated or been re-validated. Rewrite-then-evict-source is the exact trigger for orphaning. - **Constraint tagging:** segments containing *load-bearing constraints* (limits, exclusivity, ordering, idempotency keys, auth scopes) are classified as non-rewritable and may only be evicted-with-recoverable-pointer or kept verbatim. Relevance scoring alone cannot distinguish a constraint from filler because both are short and low-salience against a broad subgoal. - **Monotonic confidence:** a rewrite may not increase the assertiveness of a claim. If the scoring model cannot preserve hedging, it must not rewrite. - **Re-validation trigger:** any downstream action that *depends structurally* on a rewritten segment (constructing a cursor, a retry, a batch boundary) must re-resolve against the source before the action executes. The condition fails silently because none of these are enforced by the default pipeline: relevance scores are computed per-segment against a *subgoal*, not against *downstream dependencies*, and the dependency graph is not part of the scoring input. ## Decision Boundary The boundary between safe eviction and corrupting erasure is **whether a downstream consumer can detect the loss without external lookup.** Operationally: - If the segment is *redundant* (its content is restated elsewhere in the live set) → evict freely. - If the segment is *recoverable* (source pinned, pointer live, re-fetch cheap and side-effect-free) → evict, but mark the pointer `revalidate-before-use`. - If the segment is *constraint-bearing and non-redundant* → do **not** rewrite. Either keep verbatim or evict-with-pinned-source and force re-validation. - If the segment is *middle-band, non-constraint, and its source is about to be evicted* → the rewrite must be **blocked**, because it is about to become an unfalsifiable claim. The trap is the fourth case: it looks like exactly the kind of segment the policy was built to compress (low relevance, verbose, mid-score), and it is the one case where compression manufactures false memory. ## Operational Effect After the incident, the pipeline was changed in three ways, each targeting a structural signal rather than the symptom: 1. **Rewrite quarantine.** A rewritten segment is marked `provisional` and cannot be cited as a premise in a tool-construction step until its source is re-resolved. This converts silent erasure into a loud, cheap lookup. 2. **Constraint extraction as a pre-pass.** Before scoring, a deterministic extractor flags numeric limits, exclusivity/ordering keywords, and auth scopes; flagged segments are removed from the rewrite candidate set entirely. 3. **Confidence-invariance check.** The rewriting model is required to emit a hedge-preservation score; if the rewrite is more assertive than the source, it is rejected and the segment is kept verbatim. The measured effect: duplicate-row incidents from cursor misuse dropped to zero over the next 400 turns; average re-validation cost rose by ~11 tool calls per 100 turns (the price of not trusting surrogates). The general lesson for any self-editing context policy: **the dangerous output is not the empty slot, it is the confident paraphrase whose source you already threw away.** ```python class ContextErasureError(RuntimeError): """Raised when a self-editing pass produces a rewrite whose provenance cannot be re-resolved, i.e. a claim that is unfalsifiable by construction.""" class Segment: def __init__(self, seg_id, text, score, source_id=None, constraint_bearing=False, assertiveness=0.5): self.seg_id = seg_id self.text = text self.score = score self.source_id = source_id # None for original segments self.constraint_bearing = constraint_bearing self.assertiveness = assertiveness # 0..1, higher = more certain def apply_self_edit(live_set, edited_set, evicted_ids, rewrite_band=(0.3, 0.7)): """Validate a model-driven edit pass before committing it to the working set. live_set: dict[seg_id -> Segment] currently resident edited_set: dict[seg_id -> Segment] the pass wants to replace into the set evicted_ids: set of seg_ids the pass removes """ lo, hi = rewrite_band for seg_id, new_seg in edited_set.items(): old = live_set.get(seg_id) if old is None: raise ContextErasureError( f"rewrite target {seg_id} not resident; cannot verify provenance" ) # 1. Constraint-bearing segments must never be rewritten. if old.constraint_bearing: raise ContextErasureError( f"segment {seg_id} is constraint-bearing and was rewritten; " f"original: {old.text!r} -> surrogate: {new_seg.text!r}" ) # 2. Provenance must survive the same pass that rewrites. if new_seg.source_id is not None and new_seg.source_id in evicted_ids: raise ContextErasureError( f"rewrite of {seg_id} orphans source {new_seg.source_id}: " f"source evicted in the same pass -> unfalsifiable claim" ) if new_seg.source_id is None and old.source_id is not None: raise ContextErasureError( f"rewrite of {seg_id} dropped provenance link to {old.source_id}" ) # 3. Rewrites may not inflate assertiveness (hedge must survive). if new_seg.assertiveness > old.assertiveness + 1e-9: raise ContextErasureError( f"rewrite of {seg_id} inflated assertiveness " f"{old.assertiveness:.2f} -> {new_seg.assertiveness:.2f}; " f"compression manufactured confidence" ) # 4. Middle-band rewrites are only legal if the source is pinned live. if lo <= old.score <= hi and new_seg.source_id not in live_set: raise ContextErasureError( f"middle-band segment {seg_id} (score={old.score:.2f}) rewritten " f"without a live pinned source; re-validation impossible" ) return edited_set ```