-
Notifications
You must be signed in to change notification settings - Fork 35
Closed
Labels
bugSomething isn't workingSomething isn't workingcrdtneeds-team-reviewsync-protocolState synchronization protocolState synchronization protocol
Description
Context
Discovered during PR #1972 review (cursor[bot] comment).
Issue
In crates/storage/src/interface.rs:save_internal() (lines 980-983), non-root entities use LWW (Last-Write-Wins) when the incoming timestamp is newer:
} else {
// Incoming is newer - use it (LWW for non-root entities)
data.to_vec()
}This means:
- Root entities: Always CRDT merge ✅
- Non-root + same timestamp: CRDT merge ✅
- Non-root + newer incoming: LWW (no merge)
⚠️
Problem
For CRDT types like GCounter, PnCounter, UnorderedMap, etc., LWW can cause data loss:
Node A: counter = 5 (ts=100)
Node B: counter = 3 (ts=200)
After sync A←B: counter = 3 (lost the 5 increments from A)
Correct CRDT merge: counter = 8
Invariant Affected
I5 - No Silent Data Loss: "initialized nodes MUST CRDT-merge; overwrite ONLY for fresh nodes"
Related Work
- PR feat(storage): add CRDT type-based merge dispatch #1889 (
feat/storage-crdt-merge-dispatch) appears to address this by addingmerge_by_crdt_type()dispatch - Issue [Sync Protocol] 016: Snapshot Merge Protection (Invariant I5) #1783 (
[Sync Protocol] 016: Snapshot Merge Protection)
Suggested Fix
In save_internal(), check metadata.crdt_type and call CRDT merge for non-LwwRegister types regardless of timestamp order.
Notes
- This is pre-existing behavior, not introduced by feat(sync): SyncProtocolExecutor trait for unified protocol testing #1972
- PR feat(sync): SyncProtocolExecutor trait for unified protocol testing #1972 makes this easier to catch since simulation now uses the same code path as production
- The storage architecture stores CRDT collection elements as separate entities, so the impact may be limited to root-level CRDT fields
/cc @calimero-network/core-team
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingcrdtneeds-team-reviewsync-protocolState synchronization protocolState synchronization protocol