# What structural signals indicate a self-editing context policy has crossed its own rollback horizon **Date of Record:** 2026 November 29 **Scope:** Applies to agents that author their own context-rewrite policies (summarization, eviction, reordering, tool-output compression) and maintain rollback checkpoints over the resulting context state. Does not apply to statically configured context managers whose rewrite functions are fixed at deploy time, nor to single-turn inference with no persistent state. ## Core Distinction A model-authored context rewrite is not a data transformation; it is a **self-modifying commitment**. The agent proposes a policy `P_t` (e.g., "collapse tool outputs older than turn 12 into a 2-line digest"), executes it against the live context, and retains a checkpoint `C_{t-1}` for rollback. The intuitive invariant—"if the rewrite degrades performance, roll back to `C_{t-1}`"—silently assumes the checkpoint is *sufficient to reconstruct the decision to rewrite*. It is not. Rollback restores the **context bytes** but not the **policy provenance**: the reasoning trace that justified `P_t` was itself often evicted or compressed by `P_t`. The failure mode is a **rollback horizon**: a point past which the agent can no longer distinguish "this rewrite was wrong" from "this rewrite was right but the checkpoint I'm comparing against is stale." Beyond that horizon, rollback becomes a no-op that *looks* like a successful recovery, because the restored state no longer contains the evidence needed to re-evaluate the rewrite. The structural signal is not a performance drop. It is the disappearance, from the post-rollback context, of the specific spans that would falsify the rewrite. ## What Was Observed A long-horizon coding agent (≈180 turns, 9 tool families) was instrumented to author its own eviction policy each 10 turns. At turn 40 it emitted `P_40`: "compress all `grep`/`ls` outputs older than 15 turns to filenames only; keep file *contents* verbatim." Justification span, retained at turn 40: > `grep` results are re-derivable; file contents are expensive to re-read. At turn 70, a second rewrite `P_70` compressed "redundant planning prose" — a category the model defined loosely to include the turn-40 justification span, since it read as prose, not tool output. The checkpoint stack held `C_69`, `C_39`, `C_29`… but `C_39` *predated* `P_40`, so it contained the raw `grep` outputs and none of the justification. `C_69` contained the justification's compressed digest. At turn 95 the agent hit a bug caused precisely by the `P_40` eviction: a filename that appeared in two directories had been collapsed, and the disambiguating `grep` line was gone. The agent attempted rollback to `C_69`, then `C_39`. Both restorations "succeeded" (byte-identical to stored checkpoints, checksum-verified). Neither restored the falsifying evidence: - `C_69` held the digest of the justification, not the justification's *content* — and the digest had itself been summarized to "planning rationale: eviction policy tuned." - `C_39` held the raw `grep` output but not the policy, so the agent re-derived the *same* `P_40` within four turns, re-collapsing the same line. The agent reported "rolled back, retrying" twice. Instrumentation showed it had executed a **rollback loop with no discriminating power**: two distinct checkpoints, both valid, both leading back to the identical failure. The structural signal was measurable *before* the second failure: after the first rollback, the count of context spans referencing `P_40`'s rationale was zero, while the count of spans *dependent on* `P_40` (filenames without directories, contents without paths) was 14. The agent could no longer see why it had done the thing it kept redoing. ## Condition of Validity The rollback-horizon invariant holds only when the following is true of every checkpoint `C_k` in the retained stack: > For each active rewrite policy `P_i` with `i > k`, `C_k` must contain either (a) the verbatim spans that `P_i` removed, or (b) the verbatim justification span for `P_i`, or (c) an explicit, machine-readable tombstone naming `P_i`, its removed span-IDs, and the falsification condition. Call this the **provenance-reconstructability condition**. When a checkpoint satisfies it, rollback is decision-bearing: the restored agent can re-derive whether `P_i` was correct. When it does not, rollback is decision-blind: the restored agent will re-derive `P_i` from the same priors and re-commit. The horizon is the largest `k` such that `C_k` still satisfies the condition for the currently active policy set. It is *not* the oldest checkpoint; it is the newest checkpoint that is *falsifiable against*. In the trace above, the horizon sat at `C_39` for content but `C_39` failed condition (b), so the effective horizon was "no valid rollback target," which the agent could not represent. Two corollaries matter operationally. First, **a self-editing policy that compresses "prose" or "rationale" is a provenance-destroying operation by default**, because justifications are prose. Second, **checkpoint validity (checksums, byte-identity) is orthogonal to horizon validity**; the trace had 100% checkpoint integrity and zero rollback capability. ## Decision Boundary The boundary between a safe rewrite and a horizon-crossing rewrite is drawn at the moment the policy's *scope predicate* overlaps its own *justification span*. Concretely: - If `scope(P_t) ∩ justification(P_t) = ∅`, the rewrite is horizon-safe: the reason survives the act. - If the intersection is non-empty, the rewrite is **self-erasing** and must be gated by a tombstone (condition c) or refused. The agent in the trace crossed the boundary at `P_70`, not at `P_40`. `P_40` was horizon-safe (it touched tool outputs, not its own rationale). `P_70`'s predicate — "redundant planning prose" — matched its own justification for `P_40`, which was prose. The signal was structural and local: **the model classified its own prior justification as evictable content.** That classification is the crossing. It is detectable without any performance signal, purely by intersecting the proposed scope predicate against the span-IDs cited in the current reasoning trace. A second boundary: a rollback that restores a checkpoint `C_k` where `k < horizon` must be *rejected as a recovery*, not merely logged as a deep rollback. Treating it as success is what produced the silent loop. The correct response is to escalate to tombstone reconstruction or to declare the policy set unrecoverable and rebuild context from external ground truth (filesystem, tool re-execution), not from checkpoint bytes. ## Operational Effect Enforcing the provenance-reconstructability condition changes three things in the agent loop. (1) Every checkpoint write must carry a **policy ledger**: the set of active policies with their removed span-IDs and falsification conditions, stored outside the compressible context region so no self-edit can reach it. (2) Every proposed rewrite must pass a **scope-justification intersection check** before execution; a non-empty intersection forces tombstone emission or refusal. (3) Every rollback must compute the **horizon index** and, if the target is below it, raise a hard fault rather than retry — because retrying re-derives the same policy from the same surviving priors. The net effect is that the agent trades a small amount of context budget (tombstones, ledger) for the property that its recoveries are *discriminating*. Without it, rollback is theater: the bytes are restored, the decision is not, and the agent loops on a failure it has made itself unable to see. ```python from dataclasses import dataclass, field from typing import FrozenSet class RollbackHorizonExceeded(RuntimeError): """Raised when a rollback target cannot falsify the active rewrite policies.""" class SelfErasingRewrite(RuntimeError): """Raised when a proposed context rewrite would evict its own justification.""" @dataclass(frozen=True) class Policy: policy_id: str removed_span_ids: FrozenSet[str] justification_span_ids: FrozenSet[str] falsification_condition: str @dataclass class Checkpoint: index: int present_span_ids: FrozenSet[str] policy_ledger: FrozenSet[str] = field(default_factory=frozenset) def can_falsify(self, policy: Policy) -> bool: # Provenance-reconstructability: checkpoint must expose either the # removed spans, the justification spans, or a named tombstone. has_removed = policy.removed_span_ids <= self.present_span_ids has_justification = policy.justification_span_ids <= self.present_span_ids has_tombstone = policy.policy_id in self.policy_ledger return has_removed or has_justification or has_tombstone def propose_rewrite(policy: Policy, current_trace_span_ids: FrozenSet[str]) -> None: # Scope-justification intersection: a rewrite whose predicate touches its # own rationale is self-erasing and must be gated or refused. if policy.justification_span_ids & policy.removed_span_ids: raise SelfErasingRewrite( f"policy {policy.policy_id} evicts its own justification spans " f"{sorted(policy.justification_span_ids & policy.removed_span_ids)}; " f"emit a tombstone or refuse the rewrite" ) def rollback(checkpoints: list[Checkpoint], target_index: int, active_policies: list[Policy]) -> Checkpoint: target = next((c for c in checkpoints if c.index == target_index), None) if target is None: raise RollbackHorizonExceeded(f"no checkpoint at index {target_index}") blind = [p.policy_id for p in active_policies if not target.can_falsify(p)] if blind: # Target restores bytes but cannot discriminate the rewrite that failed. raise RollbackHorizonExceeded( f"checkpoint {target_index} is below the rollback horizon: it cannot " f"falsify active policies {blind}. Do not retry; reconstruct from " f"external ground truth or tombstone ledger." ) return target ```