# What structural signals indicate a self-pruning context window has dropped load-bearing state **Date of Record:** 2026 November 25 **Scope:** Applies to agents that autonomously rewrite, summarize, or re-rank their own context window mid-task (model-driven compaction, "memory editing," relevance-based eviction). Does not apply to append-only context with external retrieval, or to fixed-size truncation where the eviction policy is not model-selected. ## Core Distinction There are two different things a self-editing context window can get wrong, and only one of them is detectable by inspection. The first is **staleness**: the window retains a fact that is no longer true. Staleness is loud — it produces contradictions the agent can often detect when it re-reads its own summary against a fresh tool output. The second is **load-bearing loss**: the pruning step removes a token span that carried no *semantic* relevance under the model's ranking function but did carry *structural* relevance — it was the antecedent of a pronoun, the referent of a variable named three turns later, the value of a constraint ("do not touch files under `/etc`"), or the identifier that a downstream tool call will dereference. This is the non-obvious failure. The pruned span scores low on a lexical/semantic relevance metric precisely *because* it is a bare identifier, a negation particle, or an index — and those are exactly the spans whose removal is silent and downstream-fatal. The invariant that self-editing windows violate is: **a span's relevance to future steps is not a function of its relevance to the current step.** Model-driven ranking optimizes the second quantity and silently destroys the first. ## What Was Observed A coding agent with a 32k-token window and a compaction trigger at 80% utilization was tasked with a multi-file refactor. At step 14 the window hit 25.6k tokens and the compaction routine ran. The routine (a small model instructed to "keep what is relevant to the current task and summarize the rest") re-ranked spans by similarity to the active subgoal, which at that moment was "rename `parse_config` to `load_config` and update call sites." The compaction summary retained: the rename target, the file list, the test command. It evicted: (a) an earlier user constraint — "the `legacy/` directory is read-only, do not modify it"; (b) a prior tool result that had established `config_path` was an absolute path, not relative; (c) a note that `parse_config` was imported under an alias `pc` in two modules. Each evicted span was low-similarity to the rename subgoal. Each was load-bearing for a *later* step. The failure trace: 1. Step 15: agent edits `legacy/parse_config.py` — the read-only constraint was gone. No error; the write succeeded. 2. Step 18: agent constructs `os.path.join(base, config_path)` assuming relative — produced a doubled path. Tool returned a `FileNotFoundError`, which the agent misattributed to a missing file rather than a lost invariant. 3. Step 21: agent greps for `parse_config` and finds the alias `pc` call sites, but the summary no longer records that `pc` *is* `parse_config`, so it edits them as unrelated symbols and leaves two call sites broken. The tell — the structural signal — was not a single error. It was that at step 18 the agent *re-derived* a fact it had previously established (that `config_path` was absolute) and got it wrong, then proceeded without flagging the contradiction. Re-derivation of previously-settled facts is the observable signature of load-bearing loss, and it is distinguishable from normal uncertainty because the agent does not mark it as uncertain. ## Condition of Validity The guardrail below is valid only under these conditions: - The compaction step is **model-driven** (a model selects what to keep), not a deterministic policy (e.g., keep last N, keep all spans tagged `constraint`). Deterministic policies fail differently and are out of scope. - The agent has some notion of **settled facts** — values or constraints established by a prior tool result or user turn and not since revised. If the agent does not track provenance, it cannot detect re-derivation and this method does not apply. - The window is **not append-only**. If nothing is ever removed, load-bearing loss cannot occur (staleness can, but that is the other failure). When these hold, the invariant is enforceable: **no span tagged as a settled fact or a standing constraint may be evicted by a relevance-ranked compaction step, regardless of its similarity score.** Relevance ranking is permitted to order spans for summarization but not to decide their survival. ## Decision Boundary The boundary is between **relevance-ranked eviction** and **provenance-gated eviction**. - *Relevance-ranked eviction* (the failure mode): survival ∝ similarity(span, current subgoal). A constraint about `legacy/` scores near zero against "rename a function." It dies. This is correct under the ranking function and catastrophic for the task. - *Provenance-gated eviction* (the guardrail): a span survives if it is tagged `settled_fact` or `standing_constraint`, or if it is the *definition site* of any identifier still live in the window. Only spans with neither tag nor live-identifier role are eligible for relevance-ranked pruning. The decision the engineer must make: does the compaction routine have access to a provenance/identifier-liveness signal, or only to the text? If only text, the routine cannot enforce the invariant and must fall back to a conservative policy (summarize but never drop tagged spans; drop only spans the model marks as *superseded*, not merely *irrelevant*). "Irrelevant" and "safe to forget" are different predicates, and conflating them is the root cause. A second boundary: identifier liveness must be recomputed *after* each edit, not at compaction time. An identifier that was dead at step 14 may become live at step 20 when the agent decides to touch a new file. Compaction that freezes liveness at trigger time will drop a definition that a future step will need. The liveness set must be re-evaluated against the union of (current window) and (planned next actions), and the compaction must be *reversible* — the evicted spans held in an external store with a cheap re-injection path, so that a re-derivation event can trigger a reload rather than a silent wrong guess. ## Operational Effect With provenance-gated eviction plus a re-derivation detector, the observed failure class collapses to a recoverable one. The detector fires when the agent asserts a fact that matches the *shape* of a previously-settled fact but not its *value* — at step 18 the agent asserts `config_path` is relative while the external store records it was settled as absolute. The handler does not silently trust either; it halts the subgoal, re-injects the settled span, and forces reconciliation. The cost is a slightly larger effective window (tagged spans are never evicted) and a re-derivation check on every assertion that touches a settled fact. The benefit is that the three silent failures above become one loud halt. In the trace, the `legacy/` write at step 15 is the dangerous one — it is unrecoverable if the file is overwritten rather than appended. Gating it behind the standing-constraint tag is the whole point: the constraint's survival must not depend on its similarity to whatever the agent happens to be doing. The operational rule: **self-editing windows must treat "irrelevant now" and "safe to forget" as distinct, and only the latter authorizes eviction.** A model that ranks by relevance will always be willing to forget a constraint that is temporarily off-topic. The architecture must make that willingness insufficient. ```python from dataclasses import dataclass, field from typing import Optional class LoadBearingEvictionError(RuntimeError): """Raised when a compaction step attempts to evict a span that is a settled fact, a standing constraint, or the definition site of a live identifier.""" pass class RederivationConflictError(RuntimeError): """Raised when the agent asserts a fact whose shape matches a settled fact but whose value differs -- the observable signature of silent load-bearing loss.""" pass @dataclass class Span: span_id: str text: str tags: set = field(default_factory=set) # {"settled_fact", "standing_constraint"} defines_identifiers: set = field(default_factory=set) similarity_to_current_subgoal: float = 0.0 @dataclass class SettledFact: key: str value: str source_span_id: str class ProvenanceGatedCompactor: def __init__(self, external_store: dict): self.external_store = external_store # span_id -> Span, for re-injection def evict(self, span: Span, live_identifiers: set) -> None: # The invariant: relevance ranking may order spans but may not # decide survival of provenance-bearing or liveness-bearing spans. if "settled_fact" in span.tags or "standing_constraint" in span.tags: raise LoadBearingEvictionError( f"span {span.span_id} carries provenance tag(s) " f"{sorted(span.tags)}; relevance score " f"{span.similarity_to_current_subgoal:.3f} does not authorize eviction" ) if span.defines_identifiers & live_identifiers: raise LoadBearingEvictionError( f"span {span.span_id} defines live identifier(s) " f"{sorted(span.defines_identifiers & live_identifiers)}; " f"eviction would orphan downstream references" ) self.external_store[span.span_id] = span # reversible eviction def reinject(self, span_id: str) -> Span: if span_id not in self.external_store: raise LoadBearingEvictionError( f"cannot re-inject {span_id}: not in external store; " f"eviction was not reversible" ) return self.external_store.pop(span_id) def check_assertion(self, asserted_key: str, asserted_value: str, settled: dict) -> None: # Re-derivation detector: fires when shape matches a settled fact # but the value diverges. This is the loud signal that a load-bearing # span was silently dropped and the agent is guessing. fact: Optional[SettledFact] = settled.get(asserted_key) if fact is None: return if fact.value != asserted_value: raise RederivationConflictError( f"agent asserts {asserted_key}={asserted_value!r} but " f"settled value is {fact.value!r} (from {fact.source_span_id}); " f"halt subgoal and re-inject before proceeding" ) ```