Skip to content

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

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

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

Conversation

@cursor

@cursor cursor Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

restore_from_file() dropped Hybrid Logical Clock (HLC) timestamps from snapshots, assigning fresh HLCs instead. After disaster recovery, causal successor writes from the original writer raised TimestampRegressionsilent data loss on replication and gossip sync.

Trigger scenario: Node writes memory with hlc=(5000, 10, "nodeA"), snapshots to disk, crashes, restores. A causal successor write hlc=(5000, 11, "nodeA") is rejected because restore assigned a fresh HLC (wall, 0, uuid).

Root cause

v0.6.0 added HLC enforcement to remember() but restore_from_file() and gossip.receive() were not updated to preserve/forward HLC timestamps.

Fix

  • 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: forward HLC/ts_ns, update clock, skip stale/missing HLC
  • Lock restore mutation under self._lock for thread safety

Validation

  • New regression tests for snapshot round-trip and gossip HLC ordering
  • Full suite: 191 passed, 8 skipped
Open in Web View Automation 

restore_from_file() dropped HLC timestamps from snapshots, assigning fresh
HLCs instead. After disaster recovery, causal successor writes from the
original writer raised TimestampRegression — silent data loss on replication.

- 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: forward HLC/ts_ns, update clock, skip stale/missing HLC
- Lock restore mutation under self._lock for thread safety

Regression tests for snapshot 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