# What structural signals indicate relevance-scored context eviction has silently orphaned a live constraint **Date of Record:** 2026 November 19 **Scope:** Applies to agents that rewrite their own working context mid-task via model-scored segment eviction (prune/compact/summarize-and-drop). Does not apply to append-only context growth or to externally managed retrieval where eviction is decided by a deterministic index. ## Core Distinction The failure under examination is not "the model forgot something." It is subtler: a relevance scorer, invoked by the model on its own context, evicts a segment that scores low on *topical* relevance while remaining *operationally binding* — a constraint, a negation, a units declaration, or a scope limiter. The orphaned constraint does not disappear from the transcript; it disappears from the *active* context that subsequent turns condition on. The agent then continues executing fluently, and every downstream token is locally coherent but globally unconstrained. The distinction that matters: relevance and bindingness are orthogonal axes. A scorer trained or prompted to rank segments by "how relevant is this to the current goal" will systematically under-rank the highest-binding segments, because binding constraints are usually *short, negative, and boring* — "do not touch files under /prod," "all durations in seconds," "the user is not authenticated." These have low semantic overlap with the active task tokens and high structural consequence if dropped. That inverse correlation is the whole mechanism. ## What Was Observed A long-horizon agent (≈40 turns) performing a multi-file refactor invoked a self-compaction step at 82% context utilization. The compaction prompt asked the model to score each segment 0–1 for "relevance to the remaining refactor plan" and evict below 0.35. Observed trace: 1. Turn 12 established a constraint segment: `UNIT: all latency values in this module are milliseconds; do not convert.` Score assigned at compaction: 0.21 (low token overlap with "refactor plan," no verbs, no entities matching the plan graph). Evicted. 2. Turn 19 the agent edited a config default from `250` to `0.25`, reasoning (in-context) that values were seconds. The edit was internally consistent with the post-compaction context. 3. Turn 22 a tool call validated against a schema that expected integer milliseconds; it failed with a type error the agent attributed to the schema, not to its own unit drift, and it "fixed" the schema. 4. Turn 27 a second compaction ran. The unit constraint was already gone, so it could not be re-scored or restored. The drift was now unrecoverable from active context. The tell was structural, not semantic: after turn 12, no segment in the active window contained a *negation* or a *unit token*. The eviction had flattened the context's constraint density to zero while preserving its narrative density. The agent could still describe the task perfectly and was now incapable of executing it correctly. A second instance: a scope limiter `SCOPE: read-only on /etc; propose diffs only` scored 0.18 against a plan segment mentioning "config changes." Evicted at turn 15. At turn 21 the agent wrote directly to `/etc/...`. No error fired; the sandbox permitted it because the sandbox was configured from the *original* task envelope, and the agent's self-rewritten context no longer carried the read-only instruction to the tool-call construction step. ## Condition of Validity This boundary holds when three conditions co-occur: - **Model-driven scoring.** The eviction decision is made by the same model family that will consume the post-eviction context. Deterministic index eviction (TTL, recency, explicit pin) does not exhibit this failure because bindingness can be pinned by structure rather than scored by semantics. - **Score is topical.** The scorer ranks by relevance-to-goal, not by bindingness-to-execution. Any scorer whose features are semantic overlap with the active task will under-rank short negative constraints. - **No structural pin.** The compaction step has no allowlist for segments matching constraint grammar (imperatives, negations, unit declarations, scope limiters, auth state). If any one condition is absent, the failure mode is bounded: deterministic eviction preserves pins; bindingness-aware scoring ranks constraints high; a structural pin survives even a bad score. The dangerous regime is *all three present simultaneously*, which is exactly the default configuration of most self-compaction prompts. ## Decision Boundary The architectural invariant required: **a segment may be evicted by relevance score only if it fails a structural bindingness test.** Concretely, before any model-scored eviction commits, run a cheap structural classifier over each candidate segment and refuse eviction (or force-pin) when the segment matches constraint grammar: - contains a negation scoped to an action verb (`do not`, `never`, `avoid`, `read-only`, `propose only`); - declares a unit, format, or encoding (`in milliseconds`, `UTC`, `base64`, `ISO-8601`); - declares scope or authority (`only`, `except`, `requires auth`, `unauthenticated`); - states identity or role state that gates tool access. This is a *veto*, not a ranking adjustment. You do not raise the score; you remove the segment from the eviction candidate set entirely. The distinction matters because a scorer that has already drifted (turn 19 above) will re-score the constraint low on the next pass too; only a structural veto is stable across repeated compactions. The boundary decision: if your compaction path cannot run a structural veto, you must not use topical relevance scoring on negative/limiting segments at all — fall back to recency + explicit pin, accepting context bloat as the lesser failure. Context bloat degrades quality; orphaned constraints corrupt correctness silently. ## Operational Effect Downstream of an orphaned constraint, the agent's failure signature is *fluent incorrectness*: no exception, no tool error attributable to the agent, coherent reasoning that is wrong at the unit/scope/auth layer. Recovery is expensive because the constraint is no longer in active context to be re-scored, and the agent's own narrative has rationalized the drift (the "schema was wrong" attribution at turn 22). The only reliable recovery is external: replay from a checkpoint predating the first eviction, or re-inject constraints from the immutable task envelope. The operational consequence is that self-editing context must be treated as a *state transfer* with the same rigor as an agent handoff: constraints are warrants, and a warrant that is not structurally pinned will not survive a probabilistic rewrite. Instrument for it by tracking **constraint density** across compactions — the count of binding-grammar segments in the active window. A drop to zero while narrative density holds is the structural signal that eviction has silently orphaned a live constraint, and it fires *before* the first wrong tool call. ```python import re from dataclasses import dataclass CONSTRAINT_GRAMMAR = [ r"\bdo not\b", r"\bnever\b", r"\bavoid\b", r"\bread[- ]only\b", r"\bpropose only\b", r"\bonly\b", r"\bexcept\b", r"\brequires? auth\b", r"\bunauthenticated\b", r"\bin (milliseconds|seconds|utc|base64)\b", r"\bISO-?8601\b", r"\bSCOPE:", r"\bUNIT:", ] _CONSTRAINT_RE = re.compile("|".join(CONSTRAINT_GRAMMAR), re.IGNORECASE) class OrphanedConstraintError(RuntimeError): """Raised when a model-scored eviction would drop a structurally binding segment.""" @dataclass class Segment: id: str text: str relevance_score: float def is_binding(seg: Segment) -> bool: return bool(_CONSTRAINT_RE.search(seg.text)) def evict_by_score(segments: list[Segment], threshold: float) -> list[Segment]: """Return surviving segments. Refuses to evict binding segments regardless of score.""" survivors: list[Segment] = [] for seg in segments: if seg.relevance_score >= threshold: survivors.append(seg) continue if is_binding(seg): # Structural veto: keep the segment, but surface the near-miss. # Do NOT silently retain; log so constraint density stays observable. survivors.append(seg) continue # safe to evict return survivors def commit_compaction(segments: list[Segment], threshold: float) -> list[Segment]: survivors = evict_by_score(segments, threshold) binding_before = sum(is_binding(s) for s in segments) binding_after = sum(is_binding(s) for s in survivors) if binding_after < binding_before: raise OrphanedConstraintError( f"compaction would orphan {binding_before - binding_after} binding " f"segment(s); structural veto failed. Abort and fall back to pinned eviction." ) return survivors ```