Skip to content

fix(rust_brain): preserve HLC timestamps on snapshot restore and gossip - #61

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

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

Conversation

@cursor

@cursor cursor Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

restore_from_file() did not preserve Hybrid Logical Clock (HLC) timestamps from snapshots. After disaster-recovery restore, nodes received fresh (wall, 0, uuid) HLCs instead of their saved causal timestamps. Legitimate post-restore writes and gossip replays with pre-crash HLCs raised TimestampRegression and were silently dropped — causing data loss in distributed deployments after backup restore.

gossip.receive() also ignored incoming HLCs, allowing stale events to overwrite fresher data or rejecting valid causal updates.

Root cause

v0.6.0 added HLC-based monotonic ordering but restore_from_file(), bulk_write(), and gossip.receive() were not updated to preserve/pass HLC values.

Fix

  • Add _parse_hlc() helper for wire/snapshot normalization
  • restore_from_file(): restore HLC from snapshot, update global HLC, hold lock during restore
  • bulk_write(): pass through hlc field from rows
  • gossip.receive(): apply incoming HLC, reject stale updates, skip missing-HLC updates on existing keys

Validation

  • Reproduced bug: restore assigned fresh HLC; causal successor write raised TimestampRegression
  • After fix: HLC preserved, successor writes succeed, stale replays rejected
  • tests/test_enterprise_backup.py::test_restore_preserves_hlc_for_replication (new)
  • tests/test_gossip.py: 3 new HLC ordering tests
  • Targeted suite: 27 passed
  • Full suite: 184 passed, 8 skipped (7 pre-existing env failures unrelated to this change)
Open in Web View Automation 

restore_from_file() assigned fresh HLC timestamps instead of preserving
snapshot values, causing TimestampRegression on legitimate post-restore
writes and silent gossip data loss. Also pass HLC through bulk_write and
gossip.receive() with stale-event rejection.

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