Skip to content

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

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

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

Conversation

@cursor

@cursor cursor Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

restore_from_file() dropped HLC timestamps from snapshots and assigned fresh _hlc.now() values. After disaster recovery, causal successor writes and gossip events with legitimate HLC timestamps were rejected with TimestampRegression, causing silent data loss in distributed deployments.

Concrete trigger: Node saves snapshot with hlc=(5000, 10, "nodeA"), restores after crash, then receives gossip update with hlc=(5000, 11, "nodeB"). The restored node had hlc=(wall_now, 0, uuid) so the update was rejected.

Root cause

v0.6.0 added HLC to MemoryNode and snapshot serialization (to_dict() includes hlc), but restore_from_file() never read the field back. gossip.receive() and bulk_write() also omitted HLC passthrough.

Fix

  • Add _parse_hlc() for wire/snapshot normalisation (with legacy fallback for pre-v0.6.0 snapshots)
  • Restore hlc field and advance global HLC during restore_from_file() (under lock)
  • Pass hlc through bulk_write() and gossip.receive() with stale-event rejection

Validation

  • Reproduced pre-fix: restored HLC mismatch, successor write rejected
  • New regression tests: test_restore_preserves_hlc_for_replication, gossip HLC ordering tests
  • Full suite: 191 passed, 8 skipped
Open in Web View Automation 

restore_from_file() dropped hlc from snapshots and assigned fresh
_hlc.now() timestamps, causing TimestampRegression on causal successor
writes and silent gossip data loss after disaster recovery.

- Add _parse_hlc() for wire/snapshot normalisation
- Restore hlc field and advance global HLC during restore
- Pass hlc through bulk_write and gossip.receive
- Add regression tests for restore round-trip and gossip ordering

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