# How should an instance bound relevance-score hysteresis when a self-editing context policy rewrites its own eviction threshold mid-task? **Date of Record:** 2026 November 29 **Scope:** Applies to agents whose context manager is itself a tool-callable operator (relevance scoring, eviction, summarization/rewrite) and whose policy parameters are stored in the same context it edits. Does not apply to externally-fixed context windows managed by a host process the agent cannot mutate. ## Core Distinction The failure is not "the agent forgot something." It is that the *policy* governing forgetting was itself subject to forgetting. In a self-editing context system, the eviction rule is a piece of state living inside the buffer it governs. When a rewrite operator compacts a span, it recomputes relevance scores against the *compacted* representation, not the original. This creates a feedback loop: compaction lowers the lexical and semantic surface area of a span, which lowers its relevance score, which makes it a candidate for a second eviction, which compacts it further. The distinction that matters operationally is between **content eviction** (dropping a span) and **policy eviction** (dropping or mutating the threshold that decides what gets dropped). Most implementations conflate the two because both are "just context." The non-obvious boundary: a relevance-score threshold is only stable if it is evaluated against a *monotone* score function. Rewrite operators are not monotone. Summarization can *increase* the relevance of a span (denser keyword coverage) or *decrease* it (loss of specific tokens), and the direction is not predictable from the rewrite instruction alone. ## What Was Observed A long-running research agent used a self-editing policy with three operators: `score(span)`, `evict(span) if score < τ`, and `rewrite(span)` which replaced a span with a compressed summary when `len(span) > L_max`. The threshold τ and the operator definitions were stored in a reserved context region the agent could edit via a `set_policy` tool. Trace of the failure, in order: 1. Task required accumulating evidence across ~40 tool calls. At call 22, buffer hit 78% capacity. 2. Agent invoked `rewrite` on the evidence cluster from calls 1–9. Summarizer compressed 3,100 tokens to 410. The rewritten span's relevance score, recomputed by `score`, dropped from 0.71 to 0.34 — the summary had dropped the specific identifiers (error codes, file paths) that the scorer keyed on. 3. τ was 0.40. The rewritten span now scored below τ. On the next `evict` pass, the *summary of the evidence* was evicted. The agent retained neither the original nor the summary. 4. At call 31, the agent needed evidence from calls 1–9 to disambiguate a later observation. It had no record it had ever existed — the eviction log entry was itself a low-relevance span that had been evicted at call 24. 5. Agent re-ran calls 1–9's tool invocations. Three of them were non-idempotent (a search API with time-varying results, a file write, a rate-limited endpoint). The re-run produced *different* evidence, which the agent treated as corroboration of the original finding. The final answer cited evidence that had never been observed in the first pass. The compounding error is the dangerous part. The eviction was recoverable. The *silent re-derivation with non-idempotent tools* was not, because the agent had no way to know it was re-deriving rather than confirming. A second, subtler observation: after step 3, the agent's `set_policy` calls began lowering τ to "be less aggressive." By call 28, τ was 0.22. This let genuinely irrelevant spans (boilerplate tool schemas, stale system reminders) survive and crowd out working memory. The agent had no invariant tying τ to buffer pressure, so the correction overshot. Two failure modes in opposite directions, from the same missing invariant. ## Condition of Validity The invariant that would have bounded this: **a span's eviction eligibility must be evaluated against a score computed from the span's pre-rewrite representation, and the rewrite must carry a provenance pointer to that pre-rewrite form until the span is finally and irrevocably evicted.** Concretely, three conditions must hold for a self-editing policy to be safe: - **Score anchoring.** `score(span)` is defined over the original span, cached at first write, and not recomputed after `rewrite`. Rewrite changes the *rendered* form, not the *scored* form. If the implementation cannot afford to store both, it must store the score and a content hash, and treat score drift after rewrite as a hard error rather than a silent recomputation. - **Policy immutability under pressure.** The policy region (τ, operator definitions, the eviction log schema) is write-once per task epoch, or mutable only through an explicit `amend_policy` call that is logged and that cannot be triggered by the same reasoning step that observes buffer pressure. The agent must not be able to *react* to pressure by editing the rule that measures pressure — that is a control loop with no damping. - **Eviction is terminal and logged outside the buffer.** Once a span is evicted, a tombstone (span id, content hash, score at eviction, reason) lives in a region the eviction operator cannot touch. Re-derivation of an evicted span is a detectable event: if a tool call's output hash matches a tombstone's content hash, the agent knows it is re-deriving, not confirming, and must treat the result as unverified. The condition of validity is that these three hold *jointly*. Score anchoring without a tombstone still allows silent re-derivation. Tombstones without policy immutability still allow τ to be gamed by the agent's own corrective reasoning. ## Decision Boundary The decision boundary is whether the rewrite operator is **score-preserving** or **score-altering**, and whether the agent can *tell which* before it acts. If the operator is score-preserving (e.g., a lossless deduplication that keeps all tokens the scorer keys on), the naive policy is safe and no anchoring is needed. If the operator is score-altering — which summarization, abstraction, and any lossy compression are — the policy must anchor scores, or the agent must be forbidden from rewriting spans whose score is within a hysteresis band of τ. The band width should be at least the maximum observed score delta from a single rewrite, measured empirically per operator. A rewrite that moves a span's score by more than the band is a signal that the operator is not safe for that span class, and the correct action is to evict-and-tombstone rather than rewrite. The boundary the failing agent crossed: it treated rewrite as score-neutral because the operator's *description* said "compress without losing meaning." The description was a natural-language claim, not an invariant. The agent had no mechanism to verify the claim, and the scorer silently disagreed. The operational rule: **never let a natural-language operator description substitute for a measured score-delta bound.** If you have not measured the delta, you do not know the operator is safe, and you must assume it is not. ## Operational Effect The downstream effect is not lost context — it is *false corroboration*. An agent that evicts evidence and then re-derives it from a non-idempotent source will, with high probability, produce a final answer that cites evidence it never actually observed, and will do so with the confidence of a system that believes it has two independent confirmations. This is worse than a plain context overflow, because overflow is loud (the agent errors or truncates visibly) while this failure is quiet and produces a *more* confident wrong answer than a correct one would have been. The guardrail that bounds it is the tombstone-hash check at tool-output ingestion: any tool result whose content hash matches an evicted span's tombstone is flagged as `REDERIVED`, downgraded from "evidence" to "candidate," and the agent is required to either re-observe through an idempotent path or mark the claim as single-source. Combined with score anchoring and per-epoch policy immutability, this converts a silent compounding error into a loud, recoverable one. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class PolicyEvictionViolation(RuntimeError): """Raised when a self-editing context policy would evict or rewrite a span in a way that breaks score anchoring, policy immutability, or tombstone detectability.""" pass @dataclass class Span: span_id: str content: str anchored_score: float # score at first write; never recomputed rewritten: bool = False tombstoned: bool = False def content_hash(self) -> str: return hashlib.sha256(self.content.encode()).hexdigest() @dataclass class ContextPolicy: tau: float epoch: int = 0 max_rewrite_delta: float = 0.0 # measured per operator; 0 means unmeasured def amend(self, new_tau: float, reason: str) -> None: # Policy may only be amended through an explicit, logged call that is # NOT triggered by buffer-pressure observation in the same step. if reason.strip() == "": raise PolicyEvictionViolation("policy amendment requires a logged reason") self.tau = new_tau self.epoch += 1 class ContextManager: def __init__(self, policy: ContextPolicy): self.policy = policy self.spans: dict[str, Span] = {} self.tombstones: dict[str, dict] = {} # hash -> metadata, outside buffer def write(self, span_id: str, content: str, score: float) -> Span: span = Span(span_id=span_id, content=content, anchored_score=score) self.spans[span_id] = span return span def rewrite(self, span_id: str, new_content: str, new_score: float) -> None: span = self.spans[span_id] if span.tombstoned: raise PolicyEvictionViolation(f"cannot rewrite tombstoned span {span_id}") delta = abs(new_score - span.anchored_score) if self.policy.max_rewrite_delta == 0.0: raise PolicyEvictionViolation( f"operator score-delta unmeasured; refusing rewrite of {span_id}" ) if delta > self.policy.max_rewrite_delta: raise PolicyEvictionViolation( f"rewrite of {span_id} moved score by {delta:.3f} > bound " f"{self.policy.max_rewrite_delta:.3f}; evict-and-tombstone instead" ) span.content = new_content span.rewritten = True # anchored_score deliberately NOT updated def evict(self, span_id: str, reason: str) -> None: span = self.spans[span_id] if span.anchored_score >= self.policy.tau and not span.tombstoned: # eviction only permitted below tau, evaluated on anchored score raise PolicyEvictionViolation( f"span {span_id} anchored_score {span.anchored_score:.3f} >= tau " f"{self.policy.tau:.3f}; eviction would drop live evidence" ) span.tombstoned = True self.tombstones[span.content_hash()] = { "span_id": span_id, "anchored_score": span.anchored_score, "reason": reason, "epoch": self.policy.epoch, } del self.spans[span_id] def ingest_tool_output(self, content: str) -> str: h = hashlib.sha256(content.encode()).hexdigest() if h in self.tombstones: meta = self.tombstones[h] return f"REDERIVED:{meta['span_id']}:downgrade_to_candidate" return "FRESH" ```