Skip to content

fix(rust_brain): preserve HLC timestamps on restore, bulk_write, and gossip - #80

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

fix(rust_brain): preserve HLC timestamps on restore, bulk_write, and gossip#80
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-8fba

Conversation

@cursor

@cursor cursor Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

restore_from_file(), bulk_write(), and gossip.receive() did not preserve or apply Hybrid Logical Clock (HLC) timestamps introduced in v0.6.0. After snapshot restore, gossip replays and causal successor writes with pre-crash HLC values were rejected with TimestampRegression, causing silent data loss in distributed deployments.

Concrete trigger: Node writes k1 with hlc=(5000, 10, "nodeA"), snapshots, crashes, restores. Restore assigns a fresh HLC (wall, 0, uuid) instead of the snapshot value. A peer gossiping hlc=(5000, 11, "nodeA") (causally later) is rejected because 5000 < wall.

Root cause

  • restore_from_file() created MemoryNode without reading the hlc field from snapshot JSON
  • bulk_write() did not pass hlc through to remember()
  • gossip.receive() did not pass hlc and did not update the global HLC clock

Fix

  • Add _parse_hlc() helper for snapshot/wire HLC normalization (with legacy fallback for pre-v0.6.0 snapshots)
  • restore_from_file: restore hlc, call _hlc.update(), hold lock during restore
  • bulk_write: pass through hlc from row payloads
  • gossip.receive: apply peer HLC, skip stale/missing-hlc updates on existing keys

Validation

  • 38 targeted tests pass: test_hlc_snapshot_gossip.py, test_enterprise_backup.py, test_gossip.py, test_rust_brain.py, test_rust_brain_concurrency.py
Open in Web View Automation 

…gossip

restore_from_file() assigned fresh HLC timestamps instead of reading the
hlc field from snapshots. After crash recovery, gossip replays and causal
successor writes with pre-crash HLC were rejected with TimestampRegression,
causing silent data loss in distributed deployments.

- Add _parse_hlc() helper for snapshot/wire HLC normalization
- restore_from_file: restore hlc, update global HLC, hold lock during restore
- bulk_write: pass through hlc from row payloads
- gossip.receive: apply peer HLC, skip stale/missing-hlc updates on existing keys
- Add regression tests in test_hlc_snapshot_gossip.py

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