Skip to content

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

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

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

Conversation

@cursor

@cursor cursor Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

restore_from_file() dropped hlc fields from v0.6.0 snapshots, assigning fresh process-local HLCs instead. After disaster recovery:

  • Causal successor writes from the original writer were rejected with TimestampRegressionsilent data loss for replayed/gossiped updates
  • Gossip events without HLC could overwrite fresher data on existing keys

Root cause

HLC was added in v0.6.0 for monotonic causal ordering, but restore_from_file() and gossip.receive() never restored/applied stored HLCs. bulk_write() also omitted HLC passthrough.

Fix

  • Add _parse_hlc() for snapshot/wire normalisation (with legacy fallback from ts_ns)
  • Restore hlc per node and advance global _hlc during restore
  • Pass hlc through bulk_write when present
  • Gossip receive: apply HLC, reject stale updates, skip missing-HLC overwrites on existing keys
  • Hold lock during restore and gc_expired

Validation

Reproduced on main: restore assigned (wall, 0, uuid) instead of snapshot (5000, 10, "nodeA"); successor write raised TimestampRegression.

After fix: 192 passed, 8 skipped (full suite). New regression tests in test_enterprise_backup.py and test_gossip.py.

Open in Web View Automation 

restore_from_file() dropped hlc fields from snapshots, assigning fresh
process-local HLCs instead. After disaster recovery, causal successor
writes from the original writer were rejected with TimestampRegression,
and gossip without HLC could overwrite fresher data.

- Add _parse_hlc() for snapshot/wire normalisation
- Restore hlc per node and advance global _hlc during restore
- Pass hlc through bulk_write when present
- Gossip receive: apply HLC, reject stale updates, skip missing-HLC overwrites
- Hold lock during restore and gc_expired
- Regression tests for restore round-trip and gossip HLC 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