Skip to content

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

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

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

Conversation

@cursor

@cursor cursor Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

restore_from_file() and gossip.receive() did not preserve Hybrid Logical Clock (HLC) timestamps introduced in v0.6.0. After snapshot restore, nodes received fresh _hlc.now() timestamps instead of their saved HLCs. Any causal successor write or gossip replay with the pre-crash HLC raised TimestampRegression — causing silent data loss after disaster recovery and cross-node replication.

Concrete trigger: Snapshot a node with hlc=(5000, 10, "nodeA"), restore, then apply successor write hlc=(5000, 11, "nodeA")TimestampRegression because restored HLC was (wall, 0, uuid).

Root cause

  • restore_from_file() created MemoryNode without reading the hlc field from snapshot JSON (defaults to _hlc.now()).
  • gossip.receive() called remember() without passing hlc or ts_ns from gossip events.
  • bulk_write() also omitted hlc passthrough.

Fix

  • Add _parse_hlc() for wire/snapshot normalisation (with legacy ts_ns fallback).
  • Restore hlc field and advance global HLC via _hlc.update() during restore (under lock).
  • Pass hlc through bulk_write and gossip.receive with stale-event rejection.

Validation

  • Reproduced bug before fix (successor write fails after restore).
  • 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