Skip to content

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

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

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

Conversation

@cursor

@cursor cursor Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

Critical data loss after snapshot restore. v0.6.0 added Hybrid Logical Clock (HLC) monotonic enforcement on writes. restore_from_file() did not restore stored HLC timestamps — it assigned fresh process-local HLCs instead. After disaster recovery, any gossip replay or causal successor write carrying the pre-crash HLC was rejected with TimestampRegression, silently dropping updates.

Gossip overwrite risk. gossip.receive() also ignored incoming HLCs, so stale gossip without HLC could overwrite fresher data on existing keys.

Root cause

  • restore_from_file() rebuilt MemoryNode without the hlc field from the snapshot payload.
  • bulk_write() did not pass through hlc from row dicts.
  • GossipProtocol.receive() called remember() without hlc, ts_ns, or edges.

Fix

  • Add _parse_hlc() helper for wire/snapshot normalization (with legacy fallback from ts_ns).
  • Restore HLC per node in restore_from_file() and call _hlc.update() so the process clock stays ahead.
  • Pass hlc through bulk_write().
  • Teach gossip receive to apply HLC, reject stale updates, and skip missing-HLC overwrites on existing keys.

Validation

  • Reproduced pre-fix: restore assigned fresh HLC; causal successor write raised TimestampRegression.
  • Post-fix reproduction: restored HLC (5000, 10, 'nodeA') preserved; successor write accepted.
  • 37 passed across test_enterprise_backup, test_gossip, test_rust_brain, test_rust_brain_concurrency.
Open in Web View Automation 

restore_from_file dropped hlc fields added in v0.6.0, assigning fresh
timestamps on restore. Post-crash causal writes and gossip replays with
pre-crash HLC were rejected (silent data loss), while gossip events
without HLC could overwrite fresher data.

- Add _parse_hlc() for snapshot/wire normalisation with legacy fallback
- restore_from_file: restore hlc and advance global _hlc per node
- bulk_write: pass through hlc from row payloads
- gossip.receive: apply hlc, reject stale updates, skip missing-hlc
  overwrites on existing keys
- Tests: snapshot HLC round-trip, gossip stale/new/missing-hlc cases

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