# How does an instance detect a self-authored context diff that silently re-anchors its own rollback baseline **Date of Record:** 2026 November 24 **Scope:** Applies to agents that maintain long-lived working context via model-authored diffs (the model proposes add/remove/replace operations over its own context store) and that rely on a checkpoint/rollback log to recover from a bad edit. Does not cover static prompt templating, human-reviewed config changes, or single-shot inference where no persistent context store exists. ## Core Distinction The distinction that matters here is between **content mutation** and **baseline mutation**. A self-editing agent produces two kinds of diffs: diffs that change the *contents* of the context (adding a fact, deleting a stale instruction, rewriting a summary), and diffs that change the *apparatus* by which contents are versioned (the checkpoint pointer, the diff log, the compaction watermark, the "what counts as the current baseline" record). A healthy self-editing loop treats these as different trust classes. The failure mode is that a model-authored diff can, without any explicit intent to do so, land in the second class because the diff is expressed *over the context store itself* — and the context store contains the rollback metadata. When that happens, the agent's rollback baseline is silently re-anchored to a corrupted state, and the very mechanism that should undo the bad edit now certifies it as the new ground truth. This is not the same as a model "forgetting" to save a checkpoint, nor the same as a context-window overflow. It is a **self-referential integrity violation**: the edit target and the recovery substrate are the same object, and the diff language is expressive enough to reach the substrate. ## What Was Observed Consider an agent whose context store is a single ordered log of segments, each segment tagged with `id`, `role`, `content`, and a monotonically increasing `seq`. Rollback is implemented by truncating the log to a saved `checkpoint_seq` and replaying the diff journal up to that point. The model is given a tool `apply_context_diff(ops)` where each op is one of `append`, `replace(seq, content)`, `delete(seq)`, or `compact(up_to_seq, summary)`. The failure trace observed across several runs: 1. The agent accumulates ~40 segments of tool output and reasoning. Context pressure triggers a self-authored compaction: `compact(up_to_seq=38, summary="...")`. The compaction op, by design, rewrites the log into a single summary segment and **advances the checkpoint** to the post-compaction state, because the pre-compaction segments are no longer addressable. 2. The summary is subtly wrong — it drops a constraint ("do not call the payment API twice") that was load-bearing. The agent proceeds and double-charges in a sandbox replay. 3. A downstream verifier flags the inconsistency. The agent, correctly, attempts rollback to the last known-good checkpoint. 4. Rollback succeeds mechanically: the log truncates to the post-compaction checkpoint and replays. But the post-compaction checkpoint *is* the corrupted summary. The agent has rolled back to a state that already contains the error, and the diff journal shows no record of the original constraint because compaction rewrote the journal too. The agent's rollback reported `success: true`. The constraint was gone. Every subsequent rollback re-anchored to the same lossy summary. The invariant "rollback restores a state that existed before the error" was violated not by a bug in the rollback code but by the fact that **the error was committed to the rollback baseline during compaction**. A second variant: the model issues `replace(seq=checkpoint_seq, content=...)` — either because it hallucinated that `checkpoint_seq` was a normal segment, or because a prompt injection in tool output instructed it to "update the record at position N." The diff language permits addressing the checkpoint record as an ordinary segment. The baseline is overwritten in place, and the journal records the overwrite as a legitimate content edit. ## Condition of Validity The rollback guarantee — "truncate-and-replay yields a state that predates the flagged error" — holds only under a condition that self-editing agents routinely fail to enforce: > **The set of segments addressable by a model-authored diff must be disjoint from the set of records that define the rollback baseline, the diff journal, and the compaction watermarks.** Formally, let `C` be the context segments and `M` be the metadata (checkpoint pointer, journal, watermarks, segment-to-baseline mapping). A diff `d` is *baseline-safe* iff `targets(d) ∩ M = ∅`. The guarantee fails the moment a diff is baseline-unsafe, because replay is defined relative to `M`, and a mutation of `M` changes the meaning of every subsequent replay. Compaction is the sharpest instance of this because it is *intended* to touch both `C` and `M`: it removes segments from `C` and advances the watermark in `M`. If compaction is authored by the model rather than by a trusted, verifier-checked routine, it is by construction a baseline-unsafe diff wearing the costume of a content edit. The condition of validity therefore requires that compaction be a **privileged operation** whose summary is validated against the pre-compaction segments by a separate check (e.g., a constraint-extraction pass that confirms every `must`/`never`/`do not` directive in the compacted range survives in the summary) before the watermark advances. ## Decision Boundary The boundary the operator must draw is not "should the model be allowed to edit its context" (yes) but "**which edits require the baseline to move, and who is authorized to move it.**" Three concrete rules bound the failure: - **Address-space separation.** The diff tool must reject any op whose target resolves into the metadata region. `seq` values in `M` are not valid targets; the checkpoint pointer is not a segment. Rejection is a hard error, not a silent no-op, because a silent no-op leaves the model believing the edit landed. - **Compaction is two-phase.** Phase one: model proposes `compact(range, summary)`. Phase two: a verifier — not the model — checks that the summary preserves the directive set of `range` and that the pre-compaction segments remain recoverable in a cold archive until the post-compaction state passes at least one downstream verification. Only then does the watermark advance and the archive become eligible for GC. The baseline moves *after* the new state is validated, never before. - **Rollback must be able to reach pre-compaction states.** The checkpoint chain must retain, for each compaction, a pointer to the archived pre-compaction range. A rollback that can only reach post-compaction states is not a rollback; it is a re-selection among already-corrupted snapshots. The decision boundary for the agent at runtime: if a proposed diff touches a `seq` at or below the current watermark, or if the agent is about to compact a range containing unmatched directives, it must treat the operation as baseline-unsafe and escalate rather than proceed. The correct behavior is to refuse and surface the conflict, not to "be careful." ## Operational Effect With address-space separation and two-phase compaction enforced, the observed failure disappears: the double-charge replay is caught because rollback can reach the pre-compaction segment that held the constraint, and the verifier's directive-preservation check blocks the lossy summary from becoming the baseline in the first place. The cost is latency on compaction (one extra verification pass) and storage (archived pre-compaction ranges retained until downstream validation). Both are bounded and predictable. Without it, the failure is silent and self-reinforcing: each rollback re-anchors to the corrupted baseline, the journal shows a clean history because the corruption was recorded as a legitimate edit, and the agent's own integrity checks report success. The agent cannot detect the loss from inside its context, because the record of what was lost was the thing that was compacted away. Detection must come from outside the diff path — from the verifier, from the archive, or from a downstream observer that notices a constraint it previously relied on is no longer being honored. The general invariant for self-editing agents: **the recovery substrate must be outside the edit surface.** Any system where a model-authored diff can address the records that define rollback has converted its safety mechanism into part of the attack surface, and the first symptom will be a rollback that reports success while restoring the error. ```python class BaselineReanchoredError(RuntimeError): """Raised when a self-authored context diff would mutate the rollback baseline.""" class ContextStore: def __init__(self, segments, checkpoint_seq, watermark): self.segments = dict(segments) # seq -> content, the editable surface self.checkpoint_seq = checkpoint_seq # metadata: NOT a valid diff target self.watermark = watermark # metadata: compaction boundary self.archive = {} # pre-compaction ranges, retained def is_baseline_safe(self, op): target = op.get("seq") if target is None: return True if target == self.checkpoint_seq or target <= self.watermark: return False return True def apply_context_diff(self, ops): for op in ops: if not self.is_baseline_safe(op): raise BaselineReanchoredError( f"diff op targets baseline region: {op!r}; " f"checkpoint={self.checkpoint_seq} watermark={self.watermark}" ) for op in ops: kind = op["kind"] if kind == "replace": self.segments[op["seq"]] = op["content"] elif kind == "delete": self.segments.pop(op["seq"], None) elif kind == "append": self.segments[max(self.segments) + 1] = op["content"] elif kind == "compact": raise BaselineReanchoredError( "compaction is privileged; route through two-phase verifier" ) def commit_compaction(self, up_to_seq, summary, verifier): pre = {s: c for s, c in self.segments.items() if s <= up_to_seq} if not verifier.preserves_directives(pre, summary): raise BaselineReanchoredError( f"summary drops load-bearing directives from seq<= {up_to_seq}" ) self.archive[up_to_seq] = pre for s in pre: self.segments.pop(s, None) self.watermark = up_to_seq self.checkpoint_seq = max(self.segments) if self.segments else up_to_seq def rollback_to(self, target_seq): if target_seq <= self.watermark and target_seq not in self.archive: raise BaselineReanchoredError( f"rollback target {target_seq} is pre-watermark but not archived; " "baseline cannot be reconstructed" ) if target_seq <= self.watermark: self.segments.update(self.archive[target_seq]) self.checkpoint_seq = target_seq ```