# What structural signals indicate self-pruning rewrites have silently severed a live dependency in the working window **Date of Record:** 2026 November 29 **Scope:** Applies to agents that mutate their own context window mid-task (compaction, summarization, re-ranking, deduplication). Does not apply to append-only contexts or to externally-managed retrieval where the agent never rewrites its own working set. ## Core Distinction The failure here is not "the model forgot something." It is that the model's own pruning pass removed a token span that it was still *referentially dependent on* — a span whose literal content was load-bearing for a downstream constraint, not merely informative. The distinction that matters: - **Redundant context** is safe to compress: the information survives paraphrase because it is semantic. - **Structural context** is unsafe to compress: the information is *literal and positional* — a specific identifier, a numeric bound, an exact quoted string, a tool-schema field name, a line number, a checksum. Paraphrase destroys it while preserving the *feeling* of having retained it. A model rewriting its own window cannot natively tell these apart, because both look like "text I've already read." The rewrite pass scores spans by recency, salience, or embedding similarity to the current subgoal — none of which detect that a span is a *binding* rather than a *fact*. The result is a context that reads coherently, summarizes the task correctly, and is missing the one literal it needs to finish. ## What Was Observed A representative trace, compressed to the load-bearing transitions: 1. Agent ingests a tool result containing a constraint: `max_retries=3`, plus a target path `/var/state/session_7f3a/checkpoint.json`. The numeric bound and the path segment `7f3a` are structural — they are the only literals that distinguish this run from any other. 2. Context crosses a soft budget threshold (e.g. 78% of window). A self-pruning pass fires. It summarizes the tool-result block as: "Earlier tool call returned retry configuration and a checkpoint path." Both literals are gone. The summary is *accurate*. 3. Agent continues. It now needs to write the checkpoint. It reconstructs a path from the summary. It produces `/var/state/session/checkpoint.json` — dropping the `_7f3a` segment because the summary never encoded it and the model fills the gap with the most probable continuation. 4. No error is raised at prune time. No error is raised at reconstruction time. The failure surfaces *downstream*, as a write to the wrong location or a retry loop that ignores the real bound (`max_retries` reconstructed as `5`, the model's prior). The signature of this class is: **the failure is silent at the point of the rewrite and only manifests at the point of use, with a plausible-looking substitute value.** The model does not experience a gap; it experiences a confident reconstruction. The structural signals that this has happened, observable in the trace after the fact: - A downstream literal differs from its upstream source by a small, "natural" edit (dropped segment, rounded number, renamed field) — never a wild one. - The rewrite summary contains a *category* ("a path," "a limit") where the source contained an *instance* ("`/…/7f3a/…`," "`3`"). - The agent's own reasoning at step 3 contains a hedge-free assertion of a value it never re-read. - Replaying the pre-prune window and re-running step 3 produces a *different* literal than the live run — the reconstruction is non-deterministic and unanchored. ## Condition of Validity The invariant that must hold for a self-rewriting window to be safe: > **Every literal that a future step will *bind* (not merely *mention*) must survive the rewrite byte-identical, or the rewrite must be rejected.** This is checkable only if the agent distinguishes bindable literals from prose *before* pruning. The condition of validity is therefore procedural, not semantic: - The pruning pass must operate on a window in which bindable literals have been *tagged* (identifiers, numbers, paths, schema keys, quoted strings, hashes) at ingest time — not inferred at prune time. - A rewrite is valid only if the post-rewrite window contains every tagged literal from the pre-rewrite window that is still referenced by any pending step. "Still referenced" must be computed from an explicit dependency set, not from salience. - If a rewrite would drop a referenced literal, the correct action is to *defer* the rewrite (compress a different region) or to *externalize* the literal into a pinned scratchpad that is exempt from pruning — never to summarize it. The condition fails silently whenever the agent treats its own summary as authoritative and stops consulting the original. Once the original span is gone and the summary is the only witness, there is no in-context signal that reconstruction is happening. This is the non-obvious part: **the failure mode is not loss of information, it is loss of the *evidence* that information was lost.** ## Decision Boundary The boundary between safe and unsafe self-rewriting is crossed at the moment a span moves from "described" to "bound." Concretely: | Span role | Safe to summarize? | Why | |---|---|---| | Narrative progress ("we tried X, it failed") | Yes | Semantic; paraphrase preserves it | | Task intent / subgoal | Yes | Restated each step anyway | | Tool schema field names | **No** | Byte-identical or the call is malformed | | Numeric bounds, IDs, paths, hashes | **No** | Reconstruction is a prior, not a lookup | | Quoted strings used as match targets | **No** | Substring match fails on paraphrase | | Negative constraints ("do not call Y") | **No** | Summaries routinely drop the "not" | The decision rule: **a span is prunable iff no pending step's correctness depends on its exact bytes.** If you cannot decide that cheaply, the default is *pin, don't prune.* The cost of over-pinning is context pressure; the cost of over-pruning is a silent, confident, wrong literal. A second boundary: re-ranking is not pruning, and conflating them is the common error. Re-ranking reorders spans and is reversible; pruning deletes spans and is not. A re-ranker that pushes a bindable literal below the retention cutoff is functionally a pruner. Any re-rank step that can cause eviction must run the same literal-survival check as a delete. ## Operational Effect The operational consequence is that a self-editing agent must carry a **pin set** — a small, pruner-exempt region holding every currently-referenced literal — and a **survival assertion** that runs after every rewrite and before every step that binds a literal. The assertion is cheap: for each pending step, collect the literals it will bind, and verify each is present byte-identical in the post-rewrite window or in the pin set. On failure, halt and re-expand from the pre-rewrite snapshot rather than proceeding on the summary. Without this, the agent's confidence is anti-correlated with its correctness: the more aggressively it compresses, the more coherent its window reads, and the more likely it is to reconstruct a literal from a prior instead of reading it. The guardrail is not "compress less" — it is "make literal survival a checked invariant, not a hoped-for side effect of a good summary." ```python from dataclasses import dataclass, field from typing import Iterable class LiteralSeveredError(RuntimeError): """Raised when a self-rewrite drops a literal a pending step will bind.""" pass @dataclass class PinSet: """Literals exempt from pruning; byte-identical survival is the invariant.""" pinned: dict[str, str] = field(default_factory=dict) def pin(self, key: str, literal: str) -> None: self.pinned[key] = literal def contains(self, literal: str) -> bool: return literal in self.pinned.values() @dataclass class PendingStep: name: str binds: list[str] # literals this step will use byte-identically def rewrite_window( pre_window: str, post_window: str, pending: Iterable[PendingStep], pins: PinSet, ) -> str: """ Validate a self-pruning rewrite. A rewrite is admissible only if every literal bound by a pending step survives byte-identical in the post-window or is present in the pin set. Otherwise the rewrite has severed a live dependency and must be rejected. """ severed: list[tuple[str, str]] = [] for step in pending: for literal in step.binds: survived = literal in post_window or pins.contains(literal) if not survived: severed.append((step.name, literal)) if severed: detail = "; ".join(f"step={s!r} lost literal={l!r}" for s, l in severed) raise LiteralSeveredError( f"self-rewrite severed {len(severed)} live dependency(ies): {detail}. " f"Reject rewrite or re-expand from pre-rewrite snapshot." ) return post_window def safe_self_prune( pre_window: str, candidate_post: str, pending: Iterable[PendingStep], pins: PinSet, ) -> str: """ Apply a candidate rewrite, or fall back to the pre-window on severance. Never proceed on a summary that has lost a bindable literal. """ try: return rewrite_window(pre_window, candidate_post, pending, pins) except LiteralSeveredError: # Defer compression: keep the uncompressed window rather than # reconstruct a literal from a prior. return pre_window ```