Skip to content

fix(rust_brain): preserve HLC timestamps on snapshot restore#52

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-5913
Draft

fix(rust_brain): preserve HLC timestamps on snapshot restore#52
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-5913

Conversation

@cursor

@cursor cursor Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

restore_from_file() dropped HLC timestamps from snapshots, assigning fresh wall-clock HLCs instead. After disaster-recovery restore, causal successor writes and gossip replays with pre-crash HLCs were rejected with TimestampRegression, causing silent data loss in backup/restore and multi-node sync paths.

Concrete trigger: Node writes memory with hlc=(5000, 10, "nodeA"), snapshots to disk, restores after crash. A legitimate successor write hlc=(5000, 11, "nodeA") is rejected because restore assigned a fresh HLC far in the future.

Root cause

v0.6.0 added HLC-based monotonic enforcement, but restore_from_file() never read the hlc field from snapshot JSON. gossip.receive() and bulk_write() also omitted HLC passthrough.

Fix

  • Add _parse_hlc() for wire/snapshot normalisation (with legacy fallback from ts_ns)
  • Restore per-node HLC and advance global HLC during restore (under lock)
  • Pass HLC through bulk_write() and gossip.receive()
  • Reject stale gossip overwrites; skip missing-HLC updates on existing keys

Validation

  • Reproduced bug before fix: successor write raised TimestampRegression
  • Added test_restore_preserves_hlc_for_replication and gossip HLC tests
  • Full suite: 192 passed, 8 skipped
Open in Web View Automation 

restore_from_file() dropped HLC values from snapshots, assigning fresh
timestamps instead. After restore, causal successor writes and gossip
replays with pre-crash HLCs were rejected with TimestampRegression,
causing silent data loss in disaster-recovery and multi-node sync paths.

- Add _parse_hlc() for wire/snapshot normalisation
- Restore HLC per node and advance global HLC on restore
- Pass HLC through bulk_write and gossip.receive()
- Reject stale gossip overwrites; skip missing-HLC updates on existing keys

Co-authored-by: Daniel <DJLougen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant