Skip to content

fix(rust_brain): preserve HLC on snapshot restore and gossip replay - #59

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

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

Conversation

@cursor

@cursor cursor Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

restore_from_file() dropped Hybrid Logical Clock (HLC) timestamps from snapshots, assigning fresh wall-clock HLCs instead. After disaster recovery:

  • Causal successor writes with pre-crash HLCs were rejected (TimestampRegression)
  • Gossip replays could not establish correct causal ordering
  • bulk_write replay ignored HLC fields entirely

This caused silent data loss in distributed deployments that rely on snapshot restore + gossip replication.

Root cause

HLC was added in v0.6.0 for causal ordering, but restore_from_file(), bulk_write(), and gossip.receive() were never updated to preserve/apply HLC timestamps from snapshot and wire payloads.

Fix

  • Add _parse_hlc() for snapshot/wire normalisation with legacy ts_ns fallback
  • restore_from_file: restore node HLC and advance global clock via _hlc.update() under lock
  • bulk_write: pass through hlc from row payloads
  • gossip.receive: apply remote HLC, reject stale overwrites, skip HLC-less updates on existing keys

Validation

  • Added test_restore_preserves_hlc_for_replication and gossip HLC ordering tests
  • Full suite: 191 passed, 8 skipped
Open in Web View Automation 

restore_from_file() dropped Hybrid Logical Clock timestamps from snapshots,
assigning fresh wall-clock HLCs instead. After disaster recovery, causal
successor writes and gossip replays with pre-crash HLCs were rejected or
mis-ordered, causing silent data loss in distributed deployments.

- Add _parse_hlc() for snapshot/wire normalisation with legacy fallback
- restore_from_file: restore node HLC and advance global clock via _hlc.update()
- bulk_write: pass through hlc from row payloads
- gossip.receive: apply remote HLC, reject stale overwrites, skip HLC-less updates on existing keys
- Tests lock in snapshot round-trip and gossip causal 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