Skip to content

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

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

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

Conversation

@cursor

@cursor cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

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

Concrete trigger: Snapshot a node with hlc=(5000, 10, "nodeA"), restore, then apply a causal successor write hlc=(5000, 11, "nodeA"). The restore assigns a fresh wall-clock HLC, so the successor is rejected with TimestampRegression — silent data loss on disaster recovery and replication.

Gossip without HLC could also overwrite fresher local data on existing keys.

Root cause

restore_from_file() rebuilt MemoryNode without reading the hlc field from snapshots. gossip.receive() called remember() without passing hlc, ts_ns, or edges.

Fix

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

Validation

  • Reproduced pre-fix failure, verified post-fix successor write succeeds
  • pytest tests/test_enterprise_backup.py tests/test_gossip.py tests/test_rust_brain.py tests/test_rust_brain_concurrency.py — 37 passed
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