# In what scenarios must an instance treat a self-editing context pass as a state-mutating commit rather than a lossless cache eviction **Date of Record:** 2026 November 25 **Scope:** Applies to any agent that rewrites, prunes, summarizes, or relevance-scores its own working context mid-episode (including self-summarization loops, eviction-by-score policies, and tool-output compaction). Does not apply to contexts mutated only by an external orchestrator with a full audit log, nor to stateless single-turn inference. ## Core Distinction The failure lives in the gap between two mental models of context editing that look identical at the API layer but are categorically different in state semantics: - **Eviction-as-cache:** the assumption that dropping or rewriting a span removes *bytes* but preserves *information availability* — that the model can "re-derive" anything it needs from what remains. - **Eviction-as-commit:** the recognition that a self-editing pass is an irreversible write to the only durable substrate the instance has. Once a span is pruned or summarized, the original tokens are gone from the working set, and any fact, constraint, or intermediate result that existed *only* in that span is now unrecoverable within the episode. The non-obvious boundary: **a self-editing pass is a commit, not a cache eviction, precisely when the pruned span contains information that is not reconstructible from the retained span plus external tools.** Most pruning policies are tuned on relevance-to-current-subgoal, which is exactly the wrong signal for this boundary, because the highest-risk losses are low-relevance-to-now, high-relevance-to-later facts (constraints, negative results, user-stated invariants, IDs). ## What Was Observed A long-horizon agent (task: reconcile a schema migration across ~40 tool calls) ran a self-summarization pass every time context utilization crossed 80%. The policy scored each message by cosine similarity to the current subgoal embedding and evicted the bottom 30%, then wrote a compressed digest of the evicted span back into the head of the context. Failure trace: 1. At pass 3, the agent had already accepted a user constraint stated at turn 2: *"do not alter the `legacy_id` column; downstream jobs depend on it."* That constraint had low similarity to the active subgoal ("write the ALTER statement for `orders`"), because the current subgoal was about a *different* table. 2. The constraint-bearing message scored in the bottom 30%. It was evicted. The digest step summarized the evicted span as *"user provided background on downstream dependencies"* — a plausible, fluent, and semantically empty compression. The literal `legacy_id` token did not survive. 3. Passes 4–7 proceeded normally. At pass 8 the agent, working on a cross-table foreign-key cleanup, emitted an `ALTER TABLE ... DROP COLUMN legacy_id` because nothing in the retained context contradicted it. 4. The error was not a reasoning error. Every step after pass 3 was locally valid given the context the agent actually held. The defect was committed at pass 3 and lay dormant for five passes. Two properties made this hard to catch: the digest was *fluent* (it read as a correct summary, so a downstream auditor skimming the context saw no anomaly), and the loss was *latent* (no tool call failed at eviction time; the contradiction only surfaced when a later step needed the pruned fact). ## Condition of Validity The "lossless eviction" assumption holds — and self-editing is safe — only when **all three** of the following are true for every pruned span: 1. **Reconstructibility:** the span's load-bearing content is derivable from retained context plus a deterministic tool call (e.g., re-reading a file, re-querying an API). If the span contains user utterances, one-shot tool outputs, or sampled model reasoning, it is *not* reconstructible — the source is gone. 2. **Idempotent re-derivation cost:** re-deriving the fact is cheap enough that the agent will actually do it. A constraint that requires re-reading a 200-message transcript is functionally lost even if technically recoverable. 3. **No latent contradiction:** the pruned span does not contain a *negative* constraint (a "do not", a "must not", a ruled-out hypothesis, a failed approach). Negative constraints are the canonical adversarial case for relevance scoring: they are by construction dissimilar to the active positive subgoal, and their absence is invisible. When any condition fails, the self-editing pass is a commit and must be treated with the durability guarantees of a commit: preserved provenance, an immutable record of what was dropped, and a re-validation gate before any destructive downstream action. ## Decision Boundary The operational rule the instance must apply at every self-editing pass: ``` For each candidate span S to prune/rewrite: if S contains (user constraint | negative constraint | one-shot tool output | sampled reasoning | identifier/credential/literal) : -> DO NOT summarize-and-drop. Move to a pinned, verbatim-preserved region. -> The digest may reference S but must not replace it. else if S is reconstructible via a named, cheap tool call: -> safe to evict; record the re-derivation pointer. else: -> safe to evict only if a full verbatim copy is retained out-of-context. ``` Additionally, any self-editing pass that precedes a **destructive or irreversible action** (DROP, DELETE, send, deploy, payment) must re-validate the action against the *pinned* constraint set, not against the current summarized context. The pinned set is the authority; the working context is a lossy view of it. The boundary is sharp: relevance score is a *retrieval* signal, never an *eviction* signal for constraint-bearing or non-reconstructible spans. Using a similarity threshold to decide what to delete conflates "unlikely to be needed for this subgoal" with "safe to destroy," and those are different predicates. ## Operational Effect - **Latency of failure inverts intuition.** Lossless-eviction bugs do not fail at the edit; they fail N passes later, at the first step that needed the pruned fact. Debugging must therefore treat the self-edit log, not the failing tool call, as the root-cause surface. - **Fluency is not integrity.** A digest that reads correctly can still have dropped the one literal that mattered. Auditors cannot rely on reading the summary; they must diff the summary against the pinned constraint set. - **Pinning is mandatory, not an optimization.** Constraints, negative results, and one-shot outputs must live in a region the eviction policy cannot score. This is the architectural invariant that bounds the failure: *no self-editing policy may evict from the pinned region, and every destructive action must cite the pinned region.* - **Cost tradeoff is real but bounded.** Pinning grows the context floor and reduces headroom for the summarizer. The correct response is to pin *selectively* (constraints and non-reconstructible literals only) and to compress the pinned region by *reference* (stable IDs the agent can re-expand), never by paraphrase. The invariant to encode: **a self-editing pass is safe iff every evicted span is either reconstructible or pinned; otherwise it is a commit and must be gated like one.** ```python from dataclasses import dataclass, field from enum import Enum class SelfEditViolation(RuntimeError): """Raised when a context-rewrite pass would drop non-reconstructible or constraint-bearing state.""" pass class SpanKind(Enum): USER_CONSTRAINT = "user_constraint" NEGATIVE_CONSTRAINT = "negative_constraint" ONE_SHOT_TOOL_OUTPUT = "one_shot_tool_output" SAMPLED_REASONING = "sampled_reasoning" RECONSTRUCTIBLE = "reconstructible" PINNED_KINDS = { SpanKind.USER_CONSTRAINT, SpanKind.NEGATIVE_CONSTRAINT, SpanKind.ONE_SHOT_TOOL_OUTPUT, SpanKind.SAMPLED_REASONING, } @dataclass class Span: span_id: str kind: SpanKind relevance: float rederive_tool: str | None = None @dataclass class SelfEditPass: pinned: dict[str, Span] = field(default_factory=dict) evicted: dict[str, Span] = field(default_factory=dict) def apply(self, spans: list[Span], evict_below: float) -> None: for s in spans: if s.relevance >= evict_below: continue if s.kind in PINNED_KINDS: # Never let a relevance score delete constraint-bearing or # non-reconstructible state. Pin it verbatim instead. if s.span_id in self.evicted: raise SelfEditViolation( f"span {s.span_id} ({s.kind.value}) was previously evicted " f"and now must be pinned; state already lost this episode" ) self.pinned[s.span_id] = s continue if s.kind is SpanKind.RECONSTRUCTIBLE and s.rederive_tool: self.evicted[s.span_id] = s # safe: re-derivable via named tool continue raise SelfEditViolation( f"span {s.span_id} kind={s.kind.value} has no rederive_tool " f"and is not pinnable; eviction would be an unrecoverable commit" ) def assert_destructive_action_ok(self, action: str, cited_ids: set[str]) -> None: required = {sid for sid, s in self.pinned.items() if s.kind in {SpanKind.USER_CONSTRAINT, SpanKind.NEGATIVE_CONSTRAINT}} missing = required - cited_ids if missing: raise SelfEditViolation( f"destructive action {action!r} did not cite pinned constraints {sorted(missing)}" ) if __name__ == "__main__": p = SelfEditPass() # The turn-2 constraint, low relevance to the current subgoal, is the trap. spans = [ Span("turn2_legacy_id", SpanKind.USER_CONSTRAINT, relevance=0.11), Span("turn5_schema_dump", SpanKind.RECONSTRUCTIBLE, relevance=0.12, rederive_tool="read_file:orders.sql"), ] p.apply(spans, evict_below=0.30) # pins turn2_legacy_id, evicts the dump p.assert_destructive_action_ok("DROP COLUMN legacy_id", cited_ids=set()) # raises ```