0
Fork 0
mirror of https://github.com/zeronsh/comet.git synced 2026-11-16 18:57:19 +00:00

engine: a snapshot load stops at the last delta that applies

Review finding (HIGH) on the delta store. merge_deltas imported every
delta with import_batch and ignored its ImportStatus. A delta whose ops
build on ops the store doesn't hold (a lost middle row: salvage after
damage, a second writer) parks as pending and returns Ok. The export
then dropped those ops, while the load paired it with the NEWEST delta's
cursor, so the room never resent them: a permanent hole. And one
undecodable delta threw the whole batch back to the base.

- R1: the base, then each delta one at a time, in ordinal order. The run
  stops at the first error, or at a status with pending set. A stop
  rebuilds from the base and the clean run only, so no parked op rides
  along. The cursor is the LAST CLEANLY APPLIED delta's (still only if
  it was saved on this base), and the room resends the rest.
- R5: snapshot_cursor returns what the loader returns. With deltas on
  disk it merges (its one caller, EngineChatSink::new, runs at chat
  open); without, it reads the column as before.
- R4: ChatPersistence::new notes deltas already on disk (left by a
  crash). Its next compaction (eviction, shutdown) folds them even if
  the chat never changes.

Tests, each failing on 6f4e0e511:
- a_lost_middle_delta_ends_the_load_at_the_last_whole_one: was
  ("base one", 13), a hole marked received; now ("base one", 11).
- good_then_garbage_then_good_stops_at_the_garbage: was ("base", 10);
  now ("base one", 11).
- deltas_left_by_a_crash_fold_at_the_next_compaction: was 3 deltas left;
  now 0, and the reload equals memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: zeronsh[bot] <346184242+zeronsh[bot]@users.noreply.github.com>
This commit is contained in:
Wing 2026-11-11 00:23:48 -07:00
commit a18277f509
2 changed files with 182 additions and 26 deletions