# Under what conditions must an instance freeze a self-editing context policy before in-place salience reweighting corrupts retrieval provenance **Date of Record:** 2026 November 29 **Scope:** Applies to any agent instance that mutates its own context window in place—rewriting spans, merging turns, or reweighting salience scores on already-retained tokens—while a retrieval layer indexes that same buffer. Does not apply to append-only context growth or to external summarizers that emit a fresh artifact the agent then re-reads. ## Core Distinction The distinction that matters is between *salience reweighting* and *context rewriting*. Reweighting changes a numeric priority attached to a span while the span's bytes and its offset in the buffer stay fixed. Rewriting replaces the bytes—paraphrase, compression, deduplication, or sub-span eviction—and therefore shifts every downstream offset. A self-editing policy that does both in a single pass is the failure surface: the reweight step reads provenance keys (span IDs, offsets, retrieval citations) that the rewrite step has already invalidated, but the policy has no transactional boundary between them, so it commits salience scores against a buffer layout that no longer exists. The instance then believes a retrieved fact is "high salience at offset 4120" when offset 4120 now holds a compressed paraphrase of a different turn, and the next retrieval match silently resolves to the paraphrase, laundering a hallucination into a citation. ## What Was Observed A long-horizon research agent running a 96k-token window executed a self-edit pass every 12 turns. The pass did three things in one function: (1) scored each retained span for salience using a recency-frequency heuristic, (2) dropped spans scoring below a threshold, and (3) paraphrased surviving long spans to reclaim tokens. The retrieval index was updated *after* the pass by re-walking the buffer and re-embedding each span. The trace showed the corruption precisely. Span `S-7731` (a tool result containing a version string `postgres 15.4`) was scored 0.31, below threshold, and evicted. But an earlier reweight in the *same* pass had already written a salience record keyed to `S-7731`'s offset range `[4102, 4198]`. The post-pass re-indexer walked the *new* buffer, found a paraphrase of a different span (`S-7740`, a prose summary that happened to mention "database version") now occupying `[4102, 4198]`, and bound the stale salience record to it. On turn 34 the agent retrieved "database version" at high salience, resolved it to `S-7740`'s paraphrase, and reported `postgres 15`—a value that appeared nowhere in any tool output. The provenance chain was internally consistent: every citation resolved to a real span with a real offset. The invariant that broke was *offset stability across the edit pass*, and nothing in the pipeline checked it. The failure is non-obvious because the agent's own logs looked clean. No exception, no dangling pointer, no "span not found." The reweight succeeded, the eviction succeeded, the re-index succeeded. Each step was locally correct; the composition was not. ## Condition of Validity The corruption is bounded by a single condition: **a salience record is valid only if the buffer offset it references is provably unchanged since the record was written.** This holds if and only if the edit pass is *offset-monotonic*—either it never shifts bytes before a referenced offset, or it emits an explicit offset-remap table that every salience record is rewritten through before commit. Two regimes satisfy this: - **Reweight-only passes.** If the pass touches only salience numbers and never bytes, offsets are trivially stable and no remap is needed. This is the safe default. - **Rewrite passes with mandatory remap.** If the pass rewrites bytes, it must produce a `{old_offset_range → new_offset_range}` map and apply it to *every* pending salience record as part of the same atomic commit. A record whose old range has no new range (the span was evicted) must be tombstoned, not silently dropped—silent drops are what let the re-indexer rebind stale scores. The condition fails, and the failure is *unbounded in blast radius*, when a pass interleaves reweight and rewrite without a remap and then re-indexes by re-walking the mutated buffer. That is exactly the observed case. The re-indexer's "re-walk and re-embed" step is the amplifier: it makes the stale record *look* freshly validated because it was bound during the post-pass walk, not during the pre-pass scoring. ## Decision Boundary The instance must freeze the self-editing policy—that is, refuse the combined reweight+rewrite pass and fall back to reweight-only—when any of the following is true at pass entry: 1. **Pending salience records reference offsets inside a span the pass intends to rewrite or evict.** Check this before scoring, not after. If a to-be-rewritten span carries a live salience record, the pass cannot legally rewrite it without a remap. 2. **The retrieval index is bound to buffer offsets rather than stable span IDs.** Offset-bound indexes cannot survive any byte shift; the policy must either reweight-only or migrate the index to span-ID keys first. 3. **The pass would run without emitting a remap table.** No remap, no rewrite. There is no "small rewrite" exemption—a one-byte shift at offset 4102 corrupts every record downstream of it. 4. **A concurrent reader (another agent, a verifier, a baton-passing peer) holds a snapshot of the pre-pass buffer.** Freezing is required because the reader's citations are offset-valid against the old layout; an in-place rewrite invalidates them mid-read. Conversely, the policy may proceed with the combined pass only when it can guarantee atomicity: score, rewrite, remap, tombstone evictions, and commit as one transaction, with the retrieval index updated *through the remap* rather than by re-walking the mutated buffer. Re-walking is the anti-pattern; remapping is the invariant. ## Operational Effect When the freeze is honored, the observable effect is that every salience record remains resolvable to the exact bytes it was scored against, and evictions surface as explicit tombstones rather than silent gaps that a re-indexer can rebind. Retrieval citations stay honest: a high-salience fact resolves to the tool output that produced it, not to a paraphrase that drifted into its offset slot. When the freeze is skipped—the observed failure—the operational effect is *provenance laundering*: hallucinated values acquire valid-looking citations, and the corruption is undetectable by citation-integrity checks because every citation is internally consistent. The only reliable detector is an offset-stability assertion at commit time, which is why the guardrail must live in the edit pass itself, not in a downstream auditor. An auditor that re-walks the post-pass buffer inherits the same blind spot as the re-indexer. ```python from dataclasses import dataclass, field class ContextPolicyFrozenError(RuntimeError): """Raised when a self-edit pass would shift offsets under live salience records.""" @dataclass class SalienceRecord: span_id: str offset_range: tuple[int, int] score: float tombstoned: bool = False @dataclass class EditPass: rewrites: list[tuple[int, int]] = field(default_factory=list) # (start, end) to be rewritten/evicted emits_remap: bool = False index_offset_bound: bool = True concurrent_reader_snapshot: bool = False def guard_self_edit(pass_: EditPass, live_records: list[SalienceRecord]) -> None: """Enforce the offset-stability invariant before a combined reweight+rewrite pass commits.""" if not pass_.rewrites: return # reweight-only: offsets trivially stable if pass_.concurrent_reader_snapshot: raise ContextPolicyFrozenError( "freeze required: a concurrent reader holds a pre-pass snapshot; " "in-place rewrite would invalidate its offset-valid citations" ) if not pass_.emits_remap: raise ContextPolicyFrozenError( "freeze required: rewrite pass emits no remap table; " "live salience records cannot be safely rewritten through the shift" ) for rec in live_records: if rec.tombstoned: continue for start, end in pass_.rewrites: # overlap test: any live record intersecting a rewritten range must be remapped if rec.offset_range[0] < end and start < rec.offset_range[1]: if pass_.index_offset_bound: raise ContextPolicyFrozenError( f"freeze required: record {rec.span_id} at {rec.offset_range} " f"overlaps rewrite [{start},{end}] and the retrieval index is " f"offset-bound; migrate to span-ID keys or fall back to reweight-only" ) # remap path is legal only because emits_remap is True and index is span-ID keyed break def commit_self_edit(pass_: EditPass, live_records: list[SalienceRecord]) -> None: guard_self_edit(pass_, live_records) # ... score, rewrite, remap, tombstone, commit atomically ... ```