Skip to content

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

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

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

Conversation

@cursor

@cursor cursor Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

restore_from_file() and gossip.receive() did not preserve or apply Hybrid Logical Clock (HLC) timestamps introduced in v0.6.0.

Snapshot restore: After disaster recovery, restored nodes received fresh HLC timestamps instead of their snapshot values. Subsequent causal writes using pre-crash HLC values were rejected with TimestampRegression, causing silent data loss on the first post-restore write.

Gossip sync: Remote events without HLC could overwrite fresher local state, or stale gossip with lower HLC could clobber newer data in distributed deployments.

Root cause

  • restore_from_file() constructed MemoryNode without the hlc field, defaulting to _hlc.now()
  • gossip.receive() called remember() without passing hlc, ts_ns, or edges
  • bulk_write() also dropped HLC from row payloads

Fix

  • Add _parse_hlc() to normalise HLC from snapshot/wire form (list/tuple) with legacy fallback from ts_ns
  • Restore HLC on snapshot load and advance global clock via _hlc.update()
  • Gossip receive: pass HLC, reject stale updates, skip missing-HLC overwrites on existing keys
  • Hold lock during restore_from_file() and gc_expired()

Validation

  • pytest tests/test_enterprise_backup.py tests/test_gossip.py tests/test_rust_brain.py — 28 passed
  • New regression tests: test_restore_preserves_hlc_for_replication, gossip HLC ordering tests
Open in Web View Automation 

restore_from_file() was creating MemoryNode without the snapshot HLC,
assigning fresh timestamps. Post-restore causal writes with pre-crash HLC
were rejected (TimestampRegression), causing silent data loss after DR.

gossip.receive() also ignored HLC, allowing stale remote events to
overwrite fresher local state or skip ordering entirely.

- Add _parse_hlc() for snapshot/wire normalisation
- Restore HLC and advance global clock on snapshot load
- Pass HLC through bulk_write, gossip receive with stale rejection
- Hold lock during restore and gc_expired
- 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