Skip to content

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

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

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

Conversation

@cursor

@cursor cursor Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

v0.6.0 added Hybrid Logical Clock (HLC) monotonic enforcement, but restore_from_file(), bulk_write(), and gossip.receive() did not round-trip HLC timestamps. After disaster-recovery restore, restored nodes received fresh HLC values instead of the snapshot values. Valid causal successor writes and gossiped updates were then rejected with TimestampRegression — silent data loss in production failover scenarios.

Concrete trigger: Snapshot a node with hlc=(5000, 10, "nodeA"), restore, then attempt remember("k", "v2", hlc=(5000, 11, "nodeA")) — raises TimestampRegression because restore assigned a fresh wall-clock HLC.

Root cause

restore_from_file() created MemoryNode without passing hlc, so the dataclass default factory generated a new timestamp. bulk_write() and gossip.receive() similarly omitted HLC passthrough.

Fix and validation

  • Add _parse_hlc() for snapshot/wire normalisation with legacy fallback
  • restore_from_file: restore HLC, update global clock, hold lock during mutation
  • bulk_write: pass HLC from row payloads
  • gossip.receive: apply HLC, reject stale overwrites, skip missing-HLC updates on existing keys
  • 6 new regression tests in tests/test_hlc_snapshot_gossip.py

Validation: 29 targeted tests passed (test_hlc_snapshot_gossip.py, test_enterprise_backup.py, test_gossip.py, test_rust_brain.py).

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