Skip to content

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

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

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

Conversation

@cursor

@cursor cursor Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

v0.6.0 added Hybrid Logical Clock (HLC) monotonic enforcement on writes, but three replication paths did not round-trip HLC timestamps:

  • restore_from_file() — restored nodes received fresh HLC values instead of snapshot values
  • bulk_write() — ignored hlc field in row payloads
  • gossip.receive() — ignored hlc/ts_ns on incoming events

Impact: After disaster-recovery snapshot restore, valid causal successor writes and gossip replays are rejected with TimestampRegression, causing silent data loss in distributed deployments.

Root cause

HLC enforcement was added to remember() in v0.6.0, but snapshot restore, bulk import, and gossip apply paths were not updated to preserve or apply stored HLC values.

Fix

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

Validation

  • Reproduced pre-fix: restore assigned (wall, 0, uuid) instead of (5000, 10, nodeA); causal write failed
  • Post-fix reproduction passes
  • Added regression tests in test_enterprise_backup.py and test_gossip.py
  • Full suite: 191 passed, 8 skipped
Open in Web View Automation 

v0.6.0 added HybridLogicalClock enforcement but restore_from_file(),
bulk_write(), and gossip.receive() did not round-trip HLC timestamps.
After disaster-recovery restore, nodes received fresh HLC values, causing
TimestampRegression on valid causal successor writes and silent rejection
of gossiped updates.

- Add _parse_hlc() for snapshot/wire normalisation with legacy fallback
- restore_from_file: restore hlc, update global clock, hold lock
- bulk_write: pass hlc from row payloads
- gossip.receive: apply hlc, reject stale overwrites, skip missing-hlc updates
- 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