Skip to content

fix(rust_brain): preserve HLC on snapshot restore and gossip receive#39

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

fix(rust_brain): preserve HLC on snapshot restore and gossip receive#39
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-54f6

Conversation

@cursor

@cursor cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

After v0.6.0 added HLC monotonic enforcement, restore_from_file() and gossip.receive() still assigned fresh HLC timestamps instead of preserving stored ones.

Impact: Silent data loss after disaster recovery — causal successor writes are rejected with TimestampRegression. Gossip events without HLC could overwrite fresher local data.

Root cause

MemoryNode defaults to _hlc.now() when hlc is omitted. Restore and gossip paths never passed snapshot/wire HLC through, so restored nodes got new wall-clock timestamps that dominated pre-crash causal writes.

Fix

  • Add _parse_hlc() for snapshot/wire normalization with legacy fallback
  • Restore HLC and advance global clock via _hlc.update() on snapshot restore
  • Pass HLC through bulk_write and gossip receive with stale rejection
  • Hold lock during restore_from_file and gc_expired to prevent races

Validation

  • Reproduced bug: restore assigned (wall, 0, uuid) instead of snapshot (5000, 10, "nodeA"); successor write failed
  • 28 tests pass: test_enterprise_backup.py, test_gossip.py, test_rust_brain.py
Open in Web View Automation 

After v0.6.0 added HLC monotonic enforcement, restore_from_file() and
gossip.receive() still assigned fresh HLC timestamps. Post-restore causal
writes were rejected (TimestampRegression) causing silent data loss; gossip
without HLC could overwrite fresher data.

- Add _parse_hlc() for snapshot/wire normalization with legacy fallback
- Restore HLC and advance global clock on snapshot restore
- Pass HLC through bulk_write and gossip receive with stale rejection
- Hold lock during restore_from_file and gc_expired to prevent races

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