Skip to content

fix(rust_brain): preserve HLC on restore and in gossip receive#22

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

fix(rust_brain): preserve HLC on restore and in gossip receive#22
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-9df3

Conversation

@cursor

@cursor cursor Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

v0.6.0 switched monotonic write enforcement from ts_ns to Hybrid Logical Clock (HLC), but two replication paths were not updated:

  1. restore_from_file() — snapshots include HLC in node payloads, but restore ignored them and assigned fresh local clocks. After a crash-recovery restore, legitimate post-restore writes/replication with pre-crash HLC timestamps are rejected (TimestampRegression), causing silent data loss on distributed recovery.

  2. gossip.receive() — gossip events were applied without HLC, so stale remote events received a fresh local timestamp and could overwrite newer local data on the same key.

Root cause

HLC was added to remember() and to_dict() in v0.6.0, but restore_from_file(), bulk_write(), and gossip.receive() were not updated to round-trip or apply remote HLC values.

Fix

  • Add _parse_hlc() helper with legacy ts_ns fallback for pre-v0.6.0 snapshots
  • restore_from_file(): restore HLC per node and advance the process clock via _hlc.update()
  • bulk_write(): pass through HLC when present
  • gossip.receive(): apply remote HLC via update_hlc(), reject stale writes, skip unordered updates to existing keys when HLC is missing

Validation

  • Reproduced both bugs before fix (restore HLC mismatch + gossip stale overwrite)
  • Added regression tests in test_enterprise_backup.py and test_gossip.py
  • Full suite: 192 passed, 8 skipped
Open in Web View Automation 

v0.6.0 switched monotonic enforcement from ts_ns to HLC but two call
paths were not updated:

- restore_from_file() dropped HLC from snapshots, assigning fresh clocks
  that blocked legitimate post-restore replication and broke causal order.
- gossip.receive() omitted HLC, so late-arriving events got a fresh local
  timestamp and could overwrite newer data on the same key.

Restore now round-trips HLC (with ts_ns fallback for legacy snapshots) and
advances the process clock. Gossip applies remote HLCs via update_hlc(),
rejects stale writes, and skips unordered updates to existing keys when
no HLC is present.

Regression tests added for both paths.

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