Skip to content

fix(rust_brain): preserve HLC on snapshot restore and gossip replay - #75

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

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

Conversation

@cursor

@cursor cursor Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

restore_from_file(), bulk_write(), and gossip.receive() did not preserve Hybrid Logical Clock (HLC) timestamps introduced in v0.6.0. After a snapshot restore, the store assigns fresh HLC values instead of the saved ones. Any subsequent write with a causally valid pre-crash HLC (gossip replay, bulk import, or peer sync) raises TimestampRegression and is silently dropped — data loss after disaster recovery.

Concrete trigger: Snapshot a node with HLC (5000, 10, "nodeA"), restore, then apply a causally later write with HLC (5000, 11, "nodeA"). The write is rejected because restore assigned a fresh wall-clock HLC.

Root cause

  • restore_from_file() created MemoryNode without reading the hlc field from the snapshot, defaulting to _hlc.now().
  • bulk_write() did not pass hlc from row payloads.
  • gossip.receive() did not apply or update HLC on incoming events.

Fix

  • Add _parse_hlc() helper for wire/snapshot normalization.
  • restore_from_file(): restore stored HLC, update global clock via _hlc.update(), hold lock during mutation.
  • bulk_write(): round-trip HLC from row payloads.
  • gossip.receive(): apply HLC, reject stale updates, skip missing-HLC overwrites on existing keys.

Validation

  • Reproduced the bug before fix (causal successor write rejected after restore).
  • 29 targeted tests pass: test_hlc_snapshot_gossip.py, test_enterprise_backup.py, test_gossip.py, test_rust_brain.py.
Open in Web View Automation 

restore_from_file() assigned fresh HLC timestamps instead of reading
them from the snapshot, causing causally valid writes (gossip replay,
bulk_write, post-restore updates) to raise TimestampRegression and
silently drop data. Also fix bulk_write and gossip.receive() to
round-trip HLC timestamps.

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