Skip to content

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

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

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

Conversation

@cursor

@cursor cursor Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

After snapshot restore, restore_from_file() assigned fresh HLC timestamps instead of the values stored in the snapshot. Legitimate post-restore causal writes (and gossip replays with proper HLC ordering) were rejected as TimestampRegression, causing silent data loss in disaster-recovery and multi-node gossip scenarios.

Concrete trigger:

  1. Write remember("k", "v1", hlc=(5000, 10, "nodeA"))
  2. Snapshot and restore
  3. Attempt successor write remember("k", "v2", hlc=(5000, 11, "nodeA")) → rejected because restored node got a fresh wall-clock HLC far larger than the legitimate successor

Root cause

restore_from_file() constructed MemoryNode without passing hlc, so each restored node received a new _hlc.now() value. gossip.receive() and bulk_write() also ignored HLC fields on incoming events.

Fix

  • Add _parse_hlc() for snapshot/wire HLC normalisation (with legacy fallback from ts_ns)
  • Restore HLC on snapshot load and advance global _hlc
  • Pass HLC through bulk_write and gossip.receive
  • Reject stale gossip updates; skip HLC-less updates on existing keys

Validation

  • Added regression tests for restore round-trip and gossip HLC ordering
  • Full suite: 192 passed, 8 skipped
Open in Web View Automation 

After snapshot restore, nodes were assigned fresh HLC timestamps instead
of the stored values from the snapshot. Post-restore causal writes with
legitimate successor HLCs were rejected as TimestampRegression, causing
silent data loss in disaster-recovery and multi-node gossip scenarios.

- Add _parse_hlc() for snapshot/wire HLC normalisation
- Restore HLC on snapshot load and advance global _hlc
- Pass HLC through bulk_write and gossip receive
- Reject stale gossip updates; skip HLC-less updates on existing keys
- 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