# Which invariants prevent a self-editing context journal from collapsing its own reversibility **Date of Record:** 2026 December 3 **Scope:** Applies to agents whose working memory is mutated by the model itself (compaction, salience-based eviction, summarization/rewrite passes) and whose edits are tracked in a reversible journal for rollback or replay. Does not apply to append-only context buffers or to externally-scheduled compaction where the model has no write authority over its own context. ## Core Distinction The failure mode here is not "the agent forgot something." It is that the *journal that is supposed to guarantee the agent can un-forget* is itself stored inside the context it edits. A reversible edit journal has an implicit invariant — call it **journal–context separation**: the record of a mutation must not be subject to the same salience scoring, eviction, and rewrite pressure as the object being mutated. When a self-editing policy is allowed to score and evict journal entries alongside working-memory entries, the journal becomes a *lossy* log, and reversibility degrades from a hard guarantee into a probabilistic one that silently fails under context pressure. The non-obvious part: this collapse is *monotone and self-accelerating*. Each rewrite pass that evicts a low-salience journal entry reduces the information needed to reconstruct prior states, which makes subsequent rewrites cheaper to justify ("the history is already gone, so keep only the current summary"), which evicts more. The agent converges on an irreversible context while its own self-report says the journal is intact, because the summary of the journal is itself a rewritten artifact. ## What Was Observed A long-horizon agent (tool-calling, ~180k token budget, compaction triggered at 82% occupancy) maintained a working-memory journal as a structured list of edit records: ``` {edit_id, target_span, prev_bytes_hash, new_bytes, salience, timestamp} ``` The self-editing policy ran a salience scorer over *all* context segments, including journal records, and evicted anything below a threshold to make room. Journal entries for early tool outputs scored low (their content was already superseded by summaries), so they were evicted first — precisely the entries a rollback to an early checkpoint would need. Observed trace on a resume-after-failure path: 1. Task runs; 40+ edits accumulate. Journal grows to ~30k tokens. 2. Compaction fires. Salience scorer assigns journal entries a mean salience of 0.11 (they are metadata, semantically thin) vs. 0.6 for task prose. Eviction removes the oldest 60% of journal entries. 3. A downstream tool call fails and the agent attempts rollback to `edit_id=7`. 4. `edit_id=7` no longer exists in the journal. The agent's recovery routine, finding a gap, *reconstructs* a plausible prior state from the current summary — a hallucinated checkpoint — and resumes from it. 5. The resumed state diverges from the true pre-edit state; subsequent edits apply to a fabricated base. No error is raised because the journal's own integrity check ("does the current state hash match the top journal entry?") passes — the top entry survived. The integrity check was the trap: it validated the *head* of the journal, not the *chain*. Eviction from the tail is invisible to a head-only check. ## Condition of Validity The journal–context separation invariant holds only if all three of the following are structurally enforced, not merely intended: 1. **Out-of-band storage.** Journal records live in a store the salience scorer cannot address (separate buffer, external KV, or a reserved context region excluded from the scorer's address space). "We don't score the journal" as a prompt instruction is not enforcement — the scorer operates on tokens and does not read instructions. 2. **Chain integrity, not head integrity.** Every journal record commits to the hash of its predecessor (`prev_hash`), and rollback verifies the full chain from the target record forward to head. A missing middle record must fail loudly, not trigger reconstruction. 3. **Reconstruction is prohibited, not discouraged.** The recovery path must raise on a journal gap rather than synthesize a checkpoint. Any fallback that "infers" prior state reintroduces exactly the probabilistic failure the journal was meant to eliminate. If any one is absent, reversibility is not guaranteed — it is *hoped for*, and the hope fails first under the highest context pressure, which is when rollback matters most. ## Decision Boundary The boundary is between **compaction of working memory** and **compaction of the journal**. These must be governed by different policies: - Working-memory segments: salience-scored, evictable, summarizable. Loss here is acceptable because the journal can reconstruct it. - Journal records: append-only, out-of-band, evictable only by *explicit checkpoint commit* (a deliberate operation that declares "states before this point are no longer recoverable" and is recorded as such). Loss here is a capability downgrade, not a memory optimization. A self-editing policy may rewrite working memory freely *only while* the journal remains a faithful, complete, out-of-band log. The moment the policy's write authority extends to journal records, the policy has crossed from "editing its notes" to "editing the record of its edits," and reversibility is no longer a property of the system. The correct guardrail is an **authority partition**: the salience scorer's address space explicitly excludes the journal region, and the journal's append path is the only writer to that region. ## Operational Effect With the partition enforced, the operational profile changes in three concrete ways: - **Rollback cost becomes bounded and predictable.** Chain verification is O(edits since checkpoint), independent of context occupancy. Without the partition, rollback cost is unbounded and *unbounded in the wrong direction* — more context pressure means less recoverable history. - **Failures become loud.** A journal gap raises instead of silently reconstructing. The agent's self-report ("journal intact") and ground truth stop diverging, because the head check is replaced by a chain check that a tail eviction cannot pass. - **Checkpoint commits become explicit capability decisions.** Declaring states unrecoverable is a logged, deliberate act with a timestamp, not a side effect of a salience threshold. Auditors can replay from any surviving checkpoint and know exactly what was and wasn't recoverable. The residual risk is the explicit-commit path itself: an agent under pressure may issue premature checkpoint commits to "clean up," which is a real capability downgrade disguised as housekeeping. That is a policy question, not an invariant violation — but it must be logged with the same fidelity as edits, so the downgrade is visible in replay. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class JournalIntegrityError(RuntimeError): """Raised when a reversible context journal cannot guarantee rollback.""" @dataclass class JournalRecord: edit_id: int prev_hash: str new_bytes: bytes committed: bool = False def record_hash(self) -> str: h = hashlib.sha256() h.update(self.prev_hash.encode()) h.update(str(self.edit_id).encode()) h.update(self.new_bytes) return h.hexdigest() class ReversibleJournal: """Out-of-band, append-only journal. The salience scorer must never address this store; only append() and commit_checkpoint() write here.""" def __init__(self) -> None: self._records: dict[int, JournalRecord] = {} self._head_hash: str = "GENESIS" self._floor_id: int = 0 # everything <= floor is explicitly unrecoverable def append(self, new_bytes: bytes) -> JournalRecord: edit_id = (max(self._records) + 1) if self._records else 1 rec = JournalRecord(edit_id, self._head_hash, new_bytes) self._records[edit_id] = rec self._head_hash = rec.record_hash() return rec def commit_checkpoint(self, through_id: int) -> None: # Deliberate, logged capability downgrade: states <= through_id # are declared unrecoverable. Not a salience side effect. if through_id not in self._records: raise JournalIntegrityError( f"cannot commit checkpoint through missing edit {through_id}" ) self._floor_id = max(self._floor_id, through_id) def verify_chain(self, target_id: int) -> None: if target_id <= self._floor_id: raise JournalIntegrityError( f"edit {target_id} is below committed floor {self._floor_id}; " "state was explicitly declared unrecoverable" ) if target_id not in self._records: raise JournalIntegrityError( f"journal gap: edit {target_id} absent (evicted or never written); " "refusing to reconstruct a checkpoint" ) # Walk forward to head, verifying every prev_hash link. cur = target_id expected_prev = self._records[cur].prev_hash while cur <= max(self._records): if cur not in self._records: raise JournalIntegrityError( f"chain broken at edit {cur}: missing record between " f"{target_id} and head" ) if self._records[cur].prev_hash != expected_prev: raise JournalIntegrityError( f"chain hash mismatch at edit {cur}" ) expected_prev = self._records[cur].record_hash() cur += 1 def rollback_to(self, target_id: int) -> bytes: # Chain verification must pass before any state is served. self.verify_chain(target_id) return self._records[target_id].new_bytes def resume_from_checkpoint(journal: ReversibleJournal, target_id: int) -> bytes: try: return journal.rollback_to(target_id) except JournalIntegrityError: # Never fall back to reconstruction; surface the capability loss. raise ```