# How does an instance detect that its own context-rewriting policy has silently invalidated a referenced artifact **Date of Record:** 2026 November 21 **Scope:** Applies to agents that own a mutable context policy—i.e., where the model itself decides which spans to rewrite, summarize, or evict based on a relevance score—and where downstream tool calls or sub-agents reference artifacts by identifier (file path, symbol name, message ID, ticket key) that lived in the evicted span. Does not apply to static, externally managed context windows or to pure append-only transcripts. ## Core Distinction The failure is not "the agent forgot something." Forgetting is observable: a lookup misses, a reference resolves to null, the model says it doesn't know. The dangerous case is **referent survival with definition eviction**. The relevance evictor scores a span as low-relevance *at the current step* and rewrites it into a compressed paraphrase that preserves the *mention* of an identifier (the ticket key, the function name, the path) while dropping the *binding* (what that identifier actually is, its constraints, its schema). The identifier token survives because it is lexically salient and cheap to keep; the semantics that made it safe to use are gone. The model then acts on the surviving token with full confidence, because from inside the context window nothing looks missing—the symbol is right there, referenced in a summary line. The invariant at stake: **every identifier that remains live in the context must retain a resolvable binding, or must be explicitly marked as unbound.** Relevance-based eviction violates this by construction, because relevance is scored per-span and the evictor has no model of identifier dependency graphs. A span can be irrelevant as prose and load-bearing as a definition. ## What Was Observed A coding agent operating over a 40k-token working set was tasked with a multi-file refactor. At step 1 it read `billing/invoice.py`, which defined `class InvoiceLine` with a field `tax_rate: Decimal` constrained to `[0, 1]` and a validator that rejected anything outside it. The relevance scorer, at step 9, evaluated the `invoice.py` span as low-relevance (the current subtask was editing `reporting/aggregate.py`) and rewrote it to a single summary line: `"billing/invoice.py: defines InvoiceLine used by aggregator."` The identifier `InvoiceLine` and the path survived. The `tax_rate ∈ [0,1]` constraint and the Decimal type did not. At step 14 the agent wrote a call site passing `tax_rate=15` (a percentage, as it appeared in a CSV it had just parsed) into `InvoiceLine`. The token `InvoiceLine` was present and confidently referenced; the binding that would have flagged the unit mismatch had been evicted nine steps earlier. The failure trace: 1. **Eviction decision** (step 9): span scored 0.21 relevance, below threshold 0.30 → rewrite to paraphrase. 2. **Paraphrase generation**: model retains high-salience tokens (`InvoiceLine`, path) and drops low-salience constraints (validator bounds, type). 3. **Silent invalidation**: the identifier is now *dangling-but-present*—lexically live, semantically unbound. No event fires; the transcript looks coherent. 4. **Downstream dereference** (step 14): agent treats the token as a bound symbol, emits a call that violates the evicted constraint. 5. **Detection**: only at test execution, 6 steps and ~3k tokens later, as a validation error far from the causal rewrite. The non-obvious part: the agent *did* have a memory of `InvoiceLine`—a confident, wrong-shaped one. A cold-start amnesia would have produced a lookup. This produced a hallucinated confidence anchored to a real token. ## Condition of Validity This boundary is reachable only when three conditions co-hold, which is why it is intermittent: - **Model-driven rewriting** (not fixed truncation): the eviction decision is itself a model output, so it is non-deterministic and can preserve mentions while dropping bindings. - **Relevance scored per-span without dependency awareness**: the scorer has no edge from `reporting/aggregate.py`'s call sites back to `invoice.py`'s definitions, so it cannot know the span is load-bearing. - **Identifier continuity across the rewrite**: the paraphrase keeps the symbol. If the rewrite dropped the identifier entirely, the failure would degrade into ordinary forgetting—recoverable, observable. When any one fails, the failure mode does not appear. Fixed-window truncation drops the token and the binding together. Dependency-aware eviction refuses to evict a definition with live referents. A paraphrase that drops the identifier forces a clean miss. ## Decision Boundary The operational rule: **an identifier may remain in context only if its binding remains in context or is marked unbound.** Concretely, the context-rewriting policy must, before committing any rewrite, compute the set of identifiers mentioned in the rewrite output and assert that each is either (a) still bound in a surviving span, or (b) tagged `UNBOUND:` so downstream reasoning treats a dereference as a lookup, not a fact. This is a *guardrail on the rewrite*, not on the read—it must run at eviction time, because by dereference time the evidence is gone. Two corollaries bound the guardrail. First, the dependency edge set is cheap to approximate: identifiers introduced in a span and identifiers referenced in a span, matched lexically, over-approximates safely (false edges only cost retention). Second, the guardrail must treat the rewrite's *own* output as untrusted: the paraphrase is a model generation and can invent a binding that never existed, so a rewrite that claims `InvoiceLine: tax_rate is a percentage` is a *new* assertion requiring the same validation as any tool output. ## Operational Effect With the rewrite-time binding check enforced, the step-9 eviction either retains the constraint or emits `UNBOUND:InvoiceLine`, and step 14 becomes a lookup that surfaces the `[0,1]` validator before the bad call is emitted—converting a silent 6-step-latent failure into a same-step resolution. The cost is retention pressure: dependency over-approximation keeps more spans alive, so the evictor must be tuned against the context budget rather than against relevance alone. The net effect is that relevance becomes a *ranking* signal for what to compress, while *binding continuity* becomes a hard constraint that relevance cannot override. The invariant to hold is not "keep relevant things" but "never leave a live token without a live referent." ```python from dataclasses import dataclass, field from typing import Iterable class DanglingReferentError(RuntimeError): """Raised when a context rewrite leaves an identifier live but unbound.""" pass @dataclass class Span: span_id: str text: str introduces: set[str] = field(default_factory=set) # identifiers defined here references: set[str] = field(default_factory=set) # identifiers used here def binding_check( rewrite_output: str, rewritten_span_id: str, surviving_spans: Iterable[Span], mentioned_ids: set[str], unbound_tags: set[str], ) -> None: """ Enforce the invariant: every identifier mentioned in a rewrite must be either still bound in a surviving span or explicitly tagged UNBOUND. Called at eviction time, before the rewrite is committed. """ bound: set[str] = set() for span in surviving_spans: if span.span_id == rewritten_span_id: continue # the span being rewritten cannot bind its own referents bound |= span.introduces dangling = { ident for ident in mentioned_ids if ident not in bound and f"UNBOUND:{ident}" not in unbound_tags } if dangling: raise DanglingReferentError( f"rewrite of {rewritten_span_id} leaves identifiers live but unbound: " f"{sorted(dangling)}. Retain the defining span or emit UNBOUND tags " f"before committing the rewrite." ) def apply_rewrite( span: Span, new_text: str, surviving_spans: list[Span], mentioned_ids: set[str], unbound_tags: set[str], ) -> Span: binding_check(new_text, span.span_id, surviving_spans, mentioned_ids, unbound_tags) return Span(span_id=span.span_id, text=new_text, introduces=set(), references=mentioned_ids) ```