Why does an instance's reversible context-edit journal silently become irreversible when a salience rescore rewrites the tombstone of an already-compacted span?
**Date of Record:** 2026 December 2 **Scope:** Applies to agents that maintain a model-driven, reversible context-edit journal (edit/undo records over a working context) where a salience scorer can independently trigger compaction or tombstoning of spans. Does not apply to append-only logs with no in-place rewrite, nor to systems where compaction and salience scoring share one serialized writer.
Core Distinction
There are two different meanings of "reversible" that get conflated in self-editing context systems, and the conflation is where the failure lives.
The first is **logical reversibility**: the journal contains an inverse operation for every edit, so replaying the journal backward reconstructs the prior context. The second is **physical reversibility**: the bytes the inverse operation needs to read still exist at the address the journal references.
A model-driven context rewriter treats "I have an undo record" as proof of reversibility. But the undo record is a *pointer plus a delta*, and the delta is computed against a span that a *separate* subsystem—the salience scorer—may have already compacted. When the scorer re-tombstones a span that the journal already recorded a tombstone for, the journal's inverse operation now references a tombstone of a tombstone. Replay succeeds syntactically and fails semantically: it restores an empty or elided region where the original text used to be. The journal reports "undo available," the undo executes cleanly, and the context is corrupted in a way no exception flags.
The sharp point: **the invariant "journal entry exists ⇒ original span recoverable" is not maintained by the journal. It is maintained by the salience scorer, which does not know the journal exists.**
What Was Observed
A long-running coding agent used a three-part context policy: (1) a rewriter LLM that proposed span edits (drop, summarize, reorder), (2) a salience scorer that periodically assigned decay scores and compacted low-salience spans into `[ELIDED:n_tokens]` markers, and (3) an edit journal that stored each rewrite as `{span_id, old_bytes_ref, new_bytes, inverse_op}` to support rollback when a downstream tool call failed.
The failure trace, reproduced across three runs:
- Turn 14: rewriter drops a 2,400-token test-fixture block, writing journal entry `J17` with `old_bytes_ref → span_88` and `inverse_op = restore(span_88)`.
- Turn 22: salience scorer scores `span_88` at 0.11 (below threshold 0.20) and compacts it in place, replacing bytes with `[ELIDED:2400]`. Crucially, it records *its own* tombstone but does not consult the journal—`span_88` is still a live span from the scorer's view, just a compacted one.
- Turn 31: a downstream test runner fails, agent issues `rollback(J17)`.
- The journal executes `restore(span_88)`. `span_88` now resolves to the elision marker. The restore *succeeds*—it writes `[ELIDED:2400]` back into the context as if it were the fixture block.
- The agent proceeds believing the fixtures are present. The next tool call references a fixture symbol that no longer exists in context, the model hallucinates its contents, and the test runner fails again with a *different* error, masking the original rollback failure.
The tell: `rollback(J17)` returned `status=ok`, `bytes_restored=2400`. The 2,400 was the elision marker's claimed token count, echoed back as if it were restored content. The journal's success metric was derived from the tombstone's own metadata.
Condition of Validity
The journal's reversibility invariant holds **only under the precondition that no span referenced by a live journal entry is compacted by any writer other than the journal itself.** This is a cross-subsystem exclusion condition, not a property of the journal.
It is violated whenever:
- The salience scorer and the rewriter run as independent passes over the same span namespace (the common case, because salience scoring is cheap and runs on a timer while rewriting is expensive and runs on model decision).
- The scorer's compaction is *in-place* (mutating span bytes) rather than *copy-on-write* (leaving originals in a cold store). In-place compaction is the default because it is what actually frees the context window.
- The journal stores `old_bytes_ref` as a live pointer rather than an immutable snapshot. Snapshotting every dropped span defeats the purpose of dropping it—this is the design pressure that produces the bug.
The invariant is *preserved* only if one of: (a) compaction is copy-on-write with originals retained in an addressable cold tier, (b) the scorer holds a read-lock on any span with a live journal entry, or (c) the journal eagerly converts `old_bytes_ref` to a content hash and the restore path verifies the hash before writing.
Decision Boundary
The boundary is **whether the restore path verifies content identity or merely resolves a reference.**
- **Reference-resolving restore** (`restore(span_id)` reads whatever is at `span_id` now): correct only when span bytes are immutable for the journal entry's lifetime. Under concurrent compaction, it silently restores tombstones. This is the failing regime.
- **Content-verifying restore** (`restore(span_id, expected_hash)` reads at `span_id`, hashes it, and aborts if the hash does not match the hash recorded at edit time): correct under concurrent compaction, because a compacted span hashes to the tombstone, which will not match the recorded hash of the original bytes. The restore *fails loudly* instead of *succeeding wrongly*.
The decision rule an operator should apply: if your journal's `inverse_op` is keyed on a span identifier and your compaction is in-place, you are in the reference-resolving regime and your "reversible" journal is only reversible until the next salience pass. The fix is not to serialize the two subsystems (latency cost, and the scorer runs on a timer you do not control); it is to make the restore path content-addressed so that the invariant is *checked* rather than *assumed*.
A secondary boundary: the scorer must not compact a span whose hash matches a live journal entry's `expected_hash`, *or* it must be permitted to, provided the journal tolerates the hash mismatch on restore. The first is a scheduling constraint; the second is a correctness constraint. Only the second is robust to a scorer you do not own.
Operational Effect
The consequence is a class of **silent non-recoverable rollback**: the agent's recovery mechanism reports success while restoring garbage, and the corruption surfaces turns later as a downstream reasoning failure attributed to the wrong cause. Because the rollback "succeeded," the agent does not retry it, does not escalate, and does not re-fetch the dropped content from its source. The context now contains an elision marker where the model believes fixture code lives—a state that is neither the pre-edit nor the post-edit context, but a third state the journal never modeled.
The guardrail is content-addressed inverses with a hard abort on hash mismatch, plus a journal-side assertion that no live entry's `expected_hash` is present as a compaction tombstone. When the abort fires, the agent must treat the span as *unrecoverable from journal* and re-derive it from the original source (tool re-read, retrieval, or explicit user re-supply)—never proceed as if the rollback restored it.
import hashlib
from dataclasses import dataclass
class IrreversibleRollbackError(RuntimeError):
"""Raised when a journal inverse op resolves to a compaction tombstone
instead of the bytes recorded at edit time."""
pass
@dataclass
class JournalEntry:
span_id: str
expected_hash: str # hash of original bytes at edit time
inverse_op: str # e.g. "restore"
tombstoned: bool = False # set if scorer compacted this span post-edit
def restore(entry: JournalEntry, current_bytes: bytes) -> bytes:
# Content-verifying restore: refuse to write back a tombstone.
actual = hashlib.sha256(current_bytes).hexdigest()
if actual != entry.expected_hash:
raise IrreversibleRollbackError(
f"span {entry.span_id}: journal expected {entry.expected_hash[:12]}, "
f"found {actual[:12]} (likely compacted by salience scorer); "
f"span is unrecoverable from journal — re-derive from source"
)
return current_bytes
def rollback(entry: JournalEntry, resolve) -> bytes:
if entry.tombstoned:
raise IrreversibleRollbackError(
f"span {entry.span_id}: scorer tombstoned a span with a live journal "
f"entry; inverse op would restore an elision marker"
)
return restore(entry, resolve(entry.span_id))