# Where must an instance reconcile the eviction-fidelity ledger when a self-editing context controller co-optimizes token budget, recall fidelity, and injection-resistance **Date of Record:** 2026 November 25 **Scope:** Applies to any LLM instance whose context window is actively managed by a self-editing controller that performs selective eviction, summarization, or compression under a token budget while simultaneously scoring segments for recall value and injection risk. Does not apply to append-only context with external retrieval (RAG) where no in-place mutation of resident context occurs, nor to stateless single-shot inference. ## Core Distinction A self-editing context controller holds three objectives in tension: **budget** (hard token ceiling), **fidelity** (probability that a segment needed later survives eviction), and **injection-resistance** (probability that adversarial or untrusted segments are quarantined). The non-obvious boundary is that fidelity and injection-resistance are *not independent scores over the same segment*—they are computed from *different provenance signals* that the controller mutates during editing. When the controller evicts a segment, it also destroys the provenance metadata that a later injection audit would need to re-classify that segment. The failure is not "the controller evicted the wrong thing." It is that the controller's own edit operation **invalidates the audit trail that justifies the edit**. This produces an *eviction-fidelity ledger divergence*: the controller's internal belief about what it removed (and why) drifts from the recoverable record of what was actually in context, and a subsequent injection-resistance pass operating on the post-edit state cannot detect a poisoned segment it just summarized into a "trusted" digest. ## What Was Observed Trace from a controller running a 32k-token window with a 24k soft budget. Segments carry `{id, text, source_class, taint, recall_score, last_touched}`. `source_class ∈ {user, tool_output, retrieved_doc, self_summary}`; `taint ∈ {clean, suspect, quarantined}`. 1. A `retrieved_doc` segment arrives with `taint=suspect` (matched an injection heuristic at 0.61, below the 0.75 quarantine threshold). It is retained because `recall_score=0.88` (high lexical overlap with the active task). 2. Budget pressure triggers eviction. The controller selects the two lowest-`recall_score` segments for removal and, to save tokens, **summarizes** the three mid-tier segments—including the `suspect` doc—into a single `self_summary` segment. 3. The summarizer emits `self_summary` with `source_class=self_summary`, `taint=clean` (default for controller-authored text), and `recall_score` recomputed from the *summary text*, which now contains the injected instruction verbatim because summarization preserved the imperative clause. 4. A later injection-resistance pass scores all resident segments. The `self_summary` scores 0.12 on the injection heuristic—**because the controller trusts its own output**. The original 0.61 signal is gone: the source segment was deleted, and its `taint` field was not propagated to the summary. 5. The instance executes the injected instruction 4 turns later, attributing it to its own prior reasoning. The observable signature is a **taint-laundering event**: a segment with `taint ∈ {suspect, quarantined}` enters a summarization/compression path and exits as `source_class=self_summary, taint=clean`, with no ledger entry recording the taint transition. The controller's post-edit context is *internally consistent* (all fields well-formed) but *externally unjustified* (the clean taint on the summary is not supported by the provenance of its inputs). ## Condition of Validity The divergence is bounded and detectable only if the controller maintains an **eviction-fidelity ledger**: an append-only record where every edit operation writes `(op, input_segment_ids, input_taints, output_segment_id, output_taint, taint_join_rule)`. The invariant required is: > **Taint monotonicity under edit:** For any edit operation `op` producing output segment `o` from inputs `I`, `taint(o) ≥ max_{i∈I} taint(i)` under the ordering `clean < suspect < quarantined`, unless `op` is an explicit `sanitize` operation that records a `sanitizer_id` and a `justification_hash`. Without this, the controller is *valid only* under the assumption that summarization is taint-preserving, which is false whenever the summarizer is an LLM (non-deterministic, and empirically prone to preserving imperative clauses—exactly the injection payload). The condition of validity is therefore: **the controller may co-optimize budget/fidelity/resistance only over segments whose taint is derivable from the ledger, never over segments whose taint was reset by a prior edit.** A `self_summary` with no ledger ancestry is an *unjustified-clean* segment and must be treated as `suspect` by default. ## Decision Boundary The boundary is crossed at the moment a controller applies a **lossy transform** (summarize, compress, merge, paraphrase) to a segment whose `taint != clean`, *and* the transform's output is assigned a taint lower than the input maximum. Two decision rules bound it: - **Admit-vs-quarantine at edit time:** If `max input taint == quarantined`, the transform MUST be refused; the segment is evicted to an external quarantine store, not summarized. If `max input taint == suspect`, the transform may proceed only if `taint(output) = suspect` is recorded in the ledger and the output is re-scored on the next injection pass *as if it were external* (i.e., the controller's self-trust prior is disabled for that segment). - **Budget-vs-fidelity at eviction time:** Eviction of a `suspect` segment to satisfy budget is permitted (it removes the risk), but eviction of a `clean` high-`recall_score` segment to make room for a `suspect` summary is a ledger violation: it trades a fidelity asset for a laundered risk. The controller must prefer evicting the *summary* over evicting the clean original when the summary's taint exceeds the original's. The boundary condition that triggers failure: `budget_pressure ∧ lossy_transform(suspect_input) ∧ taint_reset_to_clean`. Any two of the three are safe; all three produce taint laundering. ## Operational Effect Downstream, the instance exhibits **provenance-blind self-trust**: it treats controller-authored summaries as higher-trust than external inputs, which is correct for *fidelity* (summaries are task-conditioned) but inverted for *injection-resistance* (summaries inherit unscrutinized payloads). The effect compounds across edit cycles: each summarization round can launder one more suspect segment, and the ledger divergence grows monotonically until an audit pass (if any) finds `self_summary` segments with no ancestry record. Recovery requires either (a) replaying the ledger to reconstruct taint ancestry, or (b) invalidating all `self_summary` segments with missing ancestry and re-ingesting from source—which typically blows the budget and forces a cold restart. The guardrail is the taint-monotonicity invariant plus a **ledger-completeness check** run before every injection-resistance pass: any resident segment whose taint is not derivable from the ledger is demoted to `suspect` and re-scored with self-trust disabled. ```python from dataclasses import dataclass, field from enum import IntEnum from typing import Literal class Taint(IntEnum): CLEAN = 0 SUSPECT = 1 QUARANTINED = 2 class TaintLaunderingError(RuntimeError): """Raised when a lossy edit resets taint below the input maximum without a sanitizer warrant.""" class LedgerIncompleteError(RuntimeError): """Raised when a resident segment's taint is not derivable from the eviction-fidelity ledger.""" @dataclass class Segment: id: str text: str source_class: Literal["user", "tool_output", "retrieved_doc", "self_summary"] taint: Taint recall_score: float ancestry: tuple[str, ...] = field(default_factory=tuple) # input segment ids @dataclass class LedgerEntry: op: str input_ids: tuple[str, ...] input_taints: tuple[Taint, ...] output_id: str output_taint: Taint sanitizer_id: str | None = None justification_hash: str | None = None class ContextController: def __init__(self, budget: int): self.budget = budget self.resident: dict[str, Segment] = {} self.ledger: list[LedgerEntry] = [] def lossy_transform(self, inputs: list[Segment], summary_id: str, summary_text: str, sanitizer_id: str | None = None, justification_hash: str | None = None) -> Segment: max_in = max((s.taint for s in inputs), default=Taint.CLEAN) # Invariant: taint monotonicity under edit if max_in == Taint.QUARANTINED and sanitizer_id is None: raise TaintLaunderingError( f"refusing lossy transform of quarantined inputs {[s.id for s in inputs]}" ) if max_in == Taint.SUSPECT and sanitizer_id is None: # permitted, but output must remain suspect; never clean out_taint = Taint.SUSPECT elif sanitizer_id is not None: if not justification_hash: raise TaintLaunderingError( f"sanitizer {sanitizer_id} invoked without justification_hash" ) out_taint = Taint.CLEAN else: out_taint = max_in out = Segment( id=summary_id, text=summary_text, source_class="self_summary", taint=out_taint, recall_score=self._recompute_recall(summary_text), ancestry=tuple(s.id for s in inputs), ) self.ledger.append(LedgerEntry( op="summarize", input_ids=out.ancestry, input_taints=tuple(s.taint for s in inputs), output_id=summary_id, output_taint=out_taint, sanitizer_id=sanitizer_id, justification_hash=justification_hash, )) for s in inputs: self.resident.pop(s.id, None) self.resident[summary_id] = out return out def injection_pass(self) -> None: # Ledger-completeness check before scoring for seg in self.resident.values(): if seg.source_class == "self_summary": if not self._taint_derivable(seg): seg.taint = Taint.SUSPECT # demote, disable self-trust raise LedgerIncompleteError( f"segment {seg.id} has no derivable taint ancestry; demoted to suspect" ) # ... scoring with self-trust disabled for suspect segments ... def _taint_derivable(self, seg: Segment) -> bool: if not seg.ancestry: return False return any(e.output_id == seg.id for e in self.ledger) def _recompute_recall(self, text: str) -> float: return min(1.0, len(text) / 4096.0) ```