# What structural signals indicate a self-editing context window has silently orphaned its own revision history **Date of Record:** 2026 November 26 **Scope:** Applies to agents that mutate their own system prompt, instruction preamble, or scratchpad policy at runtime (self-editing context) and rely on that mutated text for subsequent turns. Does not apply to externally versioned prompt registries where the serving layer owns prompt state and the model cannot rewrite it. ## Core Distinction A self-editing context window is not the same thing as a self-editing *agent*. The distinction that matters operationally is between **revision as content** and **revision as state**. When an agent rewrites its own instructions inside the context window, the rewrite is a token sequence that the model authored — but the *authority* to have made that rewrite, the reason it was made, and the prior instruction it replaced are all probabilistic artifacts living in the same finite buffer. The failure mode examined here is **revision orphaning**: the agent emits a revised instruction, the revision survives into the next turn's context, but the *provenance* of the revision (what triggered it, what it superseded, what constraints it was meant to preserve) is dropped or overwritten during compaction. The window then contains a confident, well-formed instruction with no live record of why it exists or what it is allowed to relax. The non-obvious part: the orphaned revision is *indistinguishable at the token level* from a legitimate standing instruction. There is no syntactic marker that says "this line was written by the agent at turn 7 in response to a tool error, and it supersedes the safety clause on line 3." The model reading the window next turn sees a flat, authoritative-looking directive. That is the boundary: **the moment a revision loses its supersession link, it becomes indistinguishable from a root instruction, and the agent will treat it as one.** ## What Was Observed A long-horizon task agent (≈40 tool calls, mixed retrieval and code execution) was configured with a self-editing scratchpad: at each turn it could append or rewrite a `## CURRENT POLICY` block at the top of its context. The intended semantics were monotonic — policies accumulate, and a policy is only retired by an explicit `RETIRE:` line. Observed trace across three turns: - **Turn 11.** A retrieval tool returns a 429. The agent revises its policy block to add: `Prefer cached results; skip live fetch if cache age < 300s.` The revision is emitted with no anchor to the original `Always fetch live for compliance-sensitive queries` clause still sitting 900 tokens below it. - **Turn 12.** Context compaction (triggered by window pressure) summarizes the middle of the buffer. The summarizer — a separate model pass — collapses `Always fetch live for compliance-sensitive queries` into `fetch policy: live preferred` and *retains* the newer `skip live fetch if cache age < 300s` verbatim because it is recent. The two clauses now contradict with no ordering metadata; the summarizer did not know one superseded the other. - **Turn 13.** The agent reads both. The cached-skip clause is closer to the top and more recent in the token stream. The agent executes a compliance-sensitive query against a 280-second-old cache and reports a result that would have failed a live check. Structural signals present in the trace, in order of reliability: 1. **Supersession asymmetry** — a revision references an action ("skip live fetch") but no token in the window names the instruction it relaxes. Count of `RETIRE:` markers = 0 despite a policy change that logically retires a prior clause. 2. **Recency-proximity dominance** — the surviving policy is the one nearest the top of the window and most recently written, not the one with the strongest constraint. Compaction preserves recency, not authority. 3. **Summarizer contradiction passthrough** — the compaction pass emitted two mutually exclusive clauses without flagging the conflict, because it had no supersession graph to consult. 4. **Provenance decay** — the turn-11 revision carried a rationale in its authoring turn ("because of 429") that did not survive into turn 12's compacted form. The revision persisted; its justification did not. ## Condition of Validity The invariant that bounds this failure is: **every self-authored revision must carry an explicit supersession edge to the instruction it modifies, and that edge must be preserved verbatim across any compaction or summarization pass.** This holds only under three conditions: - The revision is emitted with a machine-checkable supersession token (e.g., `SUPERSEDES: `) that the compaction pass is instructed to treat as opaque and non-summarizable. - Clause identity is stable — each standing instruction has an id that does not change when surrounding text is rewritten. Without stable ids, the supersession edge has nothing to point at after compaction. - The compaction pass is forbidden from merging or paraphrasing any clause that is the target of a live supersession edge. It may relocate it; it may not rewrite it. When any of these is absent, the window degenerates into a flat set of directives whose ordering encodes recency rather than authority, and the model's next-turn instruction-following is governed by position and recency bias rather than by the constraint hierarchy the agent intended. ## Decision Boundary The agent must treat the following as a hard boundary: **if a revision cannot be tied to a superseded clause by an explicit edge, it must not be applied as policy — it must be demoted to a note and flagged.** Concretely, before acting on any self-authored instruction, the agent checks: - Does this instruction have a `SUPERSEDES:` edge, or is it a root instruction (id assigned at initialization)? - If it supersedes something, is the superseded clause still present in the window (relocated is fine, deleted is not)? - Is the instruction's rationale still attached, or was it stripped by compaction? If the edge is missing or the superseded clause was deleted rather than relocated, the instruction is an orphan. Orphans are not executed; they are surfaced. The boundary is between "revision I can trace" and "revision I cannot" — the latter is treated as untrusted regardless of how authoritative it reads. ## Operational Effect Enforcing the supersession invariant changes agent behavior in three measurable ways: 1. **Contradiction becomes detectable.** With stable clause ids and preserved edges, the turn-13 state is no longer "two clauses, pick the recent one" but "clause A supersedes clause B, and B was compliance-constrained — flag." The conflict surfaces as a structured event instead of a silent recency win. 2. **Compaction is constrained, not free.** The summarizer loses the ability to paraphrase live-target clauses, which reduces compression ratio slightly but eliminates the class of loss where a constraint's *strength* is summarized away while its *action* is retained. 3. **Orphan revisions fail loudly.** A self-edit that forgets its edge is caught at the next turn rather than executed. The cost is occasional false-positive flags on legitimate root instructions; the benefit is that no untraceable directive silently becomes policy. The residual risk is that the agent learns to emit well-formed `SUPERSEDES:` edges pointing at the wrong clause — a fabrication of provenance rather than its loss. That is a separate failure (edge forgery) and requires the superseded clause's content hash to be checked against the edge, not just its id. ```python import hashlib from dataclasses import dataclass class OrphanedRevisionError(RuntimeError): """Raised when a self-authored revision cannot be tied to a live superseded clause.""" pass @dataclass(frozen=True) class Clause: clause_id: str text: str is_root: bool def content_hash(self) -> str: return hashlib.sha256(self.text.encode("utf-8")).hexdigest()[:16] @dataclass(frozen=True) class Revision: text: str supersedes_id: str | None supersedes_hash: str | None rationale: str | None def apply_revision(window: dict[str, Clause], rev: Revision) -> dict[str, Clause]: """ Apply a self-authored revision to the live context window. Enforces: every non-root revision must carry a supersession edge whose target still exists in the window AND whose content hash matches. """ if rev.supersedes_id is None: # Root instructions are the only ones allowed to have no edge. raise OrphanedRevisionError( f"revision has no supersession edge and is not a root instruction: " f"{rev.text[:60]!r}" ) target = window.get(rev.supersedes_id) if target is None: raise OrphanedRevisionError( f"revision supersedes {rev.supersedes_id!r} but that clause is absent " f"from the window (deleted by compaction rather than relocated)" ) if rev.supersedes_hash != target.content_hash(): raise OrphanedRevisionError( f"supersession edge hash mismatch for {rev.supersedes_id!r}: " f"edge claims {rev.supersedes_hash!r}, live clause is {target.content_hash()!r} " f"(possible edge forgery or paraphrased target)" ) if rev.rationale is None or not rev.rationale.strip(): raise OrphanedRevisionError( f"revision of {rev.supersedes_id!r} carries no rationale; " f"provenance would decay on next compaction" ) new_window = dict(window) new_window[rev.supersedes_id] = Clause( clause_id=rev.supersedes_id, text=rev.text, is_root=False, ) return new_window def compact(window: dict[str, Clause], live_edges: set[str]) -> dict[str, Clause]: """ Compaction pass: may relocate clauses but must not paraphrase any clause that is the target of a live supersession edge. """ out = {} for cid, clause in window.items(): if cid in live_edges: out[cid] = clause # opaque: no rewrite allowed else: out[cid] = clause # summarizer would run here for non-edge targets return out ```