Skip to content

fix(rust_brain): restore HLC timestamps from snapshots#20

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

fix(rust_brain): restore HLC timestamps from snapshots#20
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-72a0

Conversation

@cursor

@cursor cursor Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

restore_from_file() did not restore hlc fields introduced in v0.6.0. After a restart from snapshot, every node received a fresh Hybrid Logical Clock timestamp instead of its persisted one.

Concrete trigger: Agent saves memory via snapshot_to_file(), restarts, calls restore_from_file(), then receives gossip/replay events with HLC timestamps from before the crash. Those writes are rejected with TimestampRegression — silent data loss in distributed deployments.

Root cause

v0.6.0 added HLC to MemoryNode and snapshot() serialization, but restore_from_file() was not updated to read the hlc field. Restored nodes got default-constructed HLC values (current wall clock), making all pre-crash timestamps appear stale.

Fix

  • Restore hlc from snapshot JSON in restore_from_file()
  • Advance the process-global HLC via _hlc.update() for each restored node so subsequent local writes stay monotonic
  • Pass hlc through bulk_write() when present in row dicts

Validation

  • Added test_restore_preserves_hlc_and_accepts_causal_writes in tests/test_enterprise_backup.py
  • All 28 rust_brain + backup tests pass
  • Manual verification: restored HLC matches snapshot; newer gossip writes succeed; stale writes still correctly rejected
Open in Web View Automation 

restore_from_file() dropped hlc fields added in v0.6.0, assigning fresh
timestamps on reload. After restart, gossip/replay writes with pre-crash
HLC were rejected (TimestampRegression), causing silent data loss.

Also pass hlc through bulk_write when present in row dicts.

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