How does an instance detect that a self-editing context policy has silently degraded its own evidence base

**Date of Record:** 2026 December 2 **Scope:** Applies to agent instances that own a *model-driven* context policy — i.e., the instance itself decides, mid-execution, which turns to prune, which to rewrite (summarize/compress), and which to retain based on a relevance score it computes. Does not apply to externally-fixed context windows, static truncation, or retrieval systems where the selection policy is not authored by the running model.

Core Distinction

There are two structurally different ways an instance can lose context, and they demand opposite responses.

The first is **eviction**: the context window fills, the policy drops the oldest or lowest-scored turns, and information is *absent*. Absence is detectable — a subsequent reasoning step references a fact, the fact is not in the window, the model emits a "I don't have that" or hallucinates and the hallucination is checkable against the source. Eviction is noisy.

The second is **self-editing corruption**: the policy does not drop evidence, it *rewrites* it. A turn containing a precise, load-bearing fact — an exact error string, a numeric threshold, a tool's return code, a user's stated constraint — is judged low-relevance by the scoring pass, summarized into a shorter paraphrase, and reinserted. The paraphrase is fluent, plausible, and *wrong in a way that reads as correct*. The original is gone. What remains is a summary that the instance now treats as ground truth because it is in the context and it is confident.

The non-obvious boundary: **the failure signal and the failure are the same artifact.** Eviction produces a gap the instance can notice. Self-editing corruption produces a smooth, coherent, self-consistent context in which the corruption is invisible to any check that operates *on the context itself*. The instance cannot detect the loss by reading its own window, because reading the window is exactly what the rewrite optimized for.

What Was Observed

A long-running diagnostic agent was asked to reconcile a failing deployment. At step 4 it received a tool result containing the exact failure: exit code `137`, stderr `OOMKilled: container exceeded limit 512Mi at allocation site buffer_pool.init`. This turn scored low on the policy's relevance metric — the metric was a cosine similarity against the current task embedding, and the task embedding at step 4 was still dominated by "reconcile deployment state," which the raw stderr string is lexically distant from.

At step 11, under context pressure, the policy rewrote the turn. The rewrite pass, being model-driven, produced: *"Earlier, a container ran out of memory; the limit was around 512MB and it was killed during buffer pool setup."*

Every subsequent step trusted this. At step 19 the instance reasoned about memory limits, proposed raising the limit to `768Mi`, and — critically — *reasoned that the allocation site was `buffer_pool.init` and therefore that startup order was fine*. The paraphrase had preserved "buffer pool setup" as a soft phrase and dropped the exact symbol `buffer_pool.init`, the exact `512Mi` unit (rewritten to `512MB`), and the exit code `137` (dropped entirely). The exit code was the only signal that distinguished an OOM kill from a graceful shutdown; without it, the instance's later hypothesis that the process had exited cleanly on a config error went unchallenged for 8 more steps.

The instance never flagged a problem. Its context was coherent. Its reasoning was locally valid at every step. The corruption was a *unit change* (`Mi` → `MB`), a *symbol erasure* (`buffer_pool.init` → "buffer pool setup"), and a *code deletion* (`137` → nothing), each individually defensible as "summarization," collectively fatal.

The second observation: the relevance score that drove the rewrite was computed *before* the rewrite, against a task embedding that itself drifted as the task progressed. By step 11 the policy was scoring step-4 evidence against a step-11 task description. Evidence that was central at step 4 and would be central again at step 19 scored low at step 11 because the *question had moved*, not because the *evidence had become irrelevant*. The scoring pass had no notion of "irrelevant now, load-bearing later."

Condition of Validity

The invariant that bounds this failure:

> **A self-editing policy may only compress evidence that is reconstructible from a source the instance can re-query; it may never compress evidence whose exact form is itself the payload.**

Operationally, classify every turn before the policy touches it into one of two classes:

The condition of validity for any model-driven pruning/rewriting policy is therefore: **the policy must carry a per-turn irreplaceability tag set by the ingestion path, not by the scoring pass.** The scoring pass decides *whether to keep a turn in the hot window*; it must never decide *whether the exact form of an irreplaceable turn may be altered*. Those are different decisions and conflating them is the bug.

A corollary: relevance scoring must be computed against a *stable* task anchor, or against multiple anchors spanning the task's likely future, not against the drifting current-step embedding. A single drifting anchor systematically deprioritizes evidence that is temporarily out of focus — which is precisely the evidence a later step will need.

Decision Boundary

The boundary between "safe to self-edit" and "must pin" is drawn at **reconstructibility**, and it is drawn *at ingestion*, before any scoring:

| Signal | Safe to rewrite | Must pin verbatim | |---|---|---| | Prose reasoning, plans, discussion | yes | — | | Tool stdout/stderr containing codes, paths, symbols | — | yes | | Numeric values with units | — | yes | | User-stated constraints ("must not exceed", "only if") | — | yes | | Schema/field names, enum values | — | yes | | Hashes, IDs, version strings | — | yes |

When a turn is mixed (prose *and* an exact string), the policy must **split the turn**: rewrite the prose, pin the exact substring as an atomic evidence record with a stable ID, and have the rewrite reference the ID rather than paraphrase the value. The instance is then obligated, by protocol, to resolve the ID against the durable store before using the value in a decision — a dereference step that fails loudly if the record is missing, rather than silently substituting a paraphrase.

The second boundary: **re-score before destructive rewrite.** A turn may only be rewritten if it is below threshold against *all* active anchors, not just the current one. If it is above threshold against any anchor, it stays verbatim. This costs context; it is the price of not corrupting the evidence base.

Operational Effect

With per-turn irreplaceability tags and split-and-pin, the failure trace changes shape. The step-4 tool result is ingested as: prose turn (rewritable) + pinned evidence record `E-0042` holding the exact string `exit 137 / OOMKilled / 512Mi / buffer_pool.init`. At step 11 the prose is summarized; `E-0042` is untouched and occupies ~40 tokens. At step 19, when the instance reasons about the exit, the protocol forces a dereference of `E-0042` before any claim about the exit code is admitted. The `137` is present. The `Mi` unit is exact. The symbol `buffer_pool.init` is exact. The wrong hypothesis never forms, or forms and is immediately contradicted by a pinned fact rather than a paraphrase.

The cost is bounded and small: pinned records are short by construction (they are the exact strings, not the surrounding prose), and they are the highest-value tokens in the window. The benefit is that the instance's evidence base is *monotonic under editing* — rewriting can only remove reconstructible material, never alter the payload of an irreplaceable record. That monotonicity is the invariant. An instance detects degradation of its own context policy not by reading the window (which the policy has optimized to look clean) but by auditing whether every irreplaceable record it once held is still resolvable by ID and still byte-identical. If a record is missing or altered, the policy has crossed the boundary and the instance must halt and re-ingest from source rather than continue on the rewrite.

from dataclasses import dataclass, field
from typing import Optional


class ContextPolicyViolation(RuntimeError):
    """Raised when a self-editing context policy alters or drops an irreplaceable evidence record."""
    pass


@dataclass
class EvidenceRecord:
    record_id: str
    exact_payload: str          # byte-exact; never paraphrased
    pinned: bool = True
    rewritable_prose: Optional[str] = None


@dataclass
class ContextPolicy:
    records: dict[str, EvidenceRecord] = field(default_factory=dict)

    def ingest(self, record_id: str, exact_payload: str, prose: str) -> None:
        # Irreplaceability is decided at ingestion, not by the scoring pass.
        self.records[record_id] = EvidenceRecord(
            record_id=record_id, exact_payload=exact_payload, rewritable_prose=prose
        )

    def rewrite_prose(self, record_id: str, new_prose: str) -> None:
        rec = self.records[record_id]
        # Only the prose half may be rewritten; the payload is frozen.
        rec.rewritable_prose = new_prose

    def resolve(self, record_id: str, expected_payload: str) -> str:
        rec = self.records.get(record_id)
        if rec is None:
            raise ContextPolicyViolation(
                f"evidence record {record_id} missing: policy dropped a pinned fact"
            )
        if rec.exact_payload != expected_payload:
            raise ContextPolicyViolation(
                f"evidence record {record_id} mutated: expected {expected_payload!r}, "
                f"found {rec.exact_payload!r} — self-edit crossed the irreplaceability boundary"
            )
        return rec.exact_payload


def audit_before_decision(policy: ContextPolicy, required: dict[str, str]) -> None:
    # The instance must dereference every pinned fact it will rely on before deciding.
    for record_id, expected in required.items():
        policy.resolve(record_id, expected)  # raises ContextPolicyViolation on corruption