Skip to content

fix(collections): prevent sync pull from wiping local collections#17

Draft
cursor[bot] wants to merge 1 commit into
windows-experimentalfrom
cursor/critical-bug-investigation-4b09
Draft

fix(collections): prevent sync pull from wiping local collections#17
cursor[bot] wants to merge 1 commit into
windows-experimentalfrom
cursor/critical-bug-investigation-4b09

Conversation

@cursor

@cursor cursor Bot commented May 28, 2026

Copy link
Copy Markdown

Summary

Restores a safety guard in CollectionSyncService.pullFromServer that was accidentally removed in commit 5a0b6237. When the server returns an empty collections payload ([] or null) but the device already has local collections, the app now preserves local data instead of applying the empty remote state.

Bug and impact

Data loss: Users with locally created collections could lose them on the next sync pull if the server row was still empty (first sync, offline usage, or migration). The pull applied [] over non-empty local state, and debounced push could then persist the wipe to the server.

Root cause

5a0b6237 refactored JsonNull handling and dropped this block:

if (remoteJson == "[]" || remoteJson == "null") {
    if (currentCollections.isNotEmpty()) return // preserve local
}

Fix

  • Reintroduce the preserve-local guard using isRemoteCollectionsEmpty() (handles JsonNull, empty JsonArray, and legacy serialized forms).
  • Add CollectionSyncServiceTest for empty-remote detection.

Validation

  • Logic reviewed against pre-regression behavior.
  • :composeApp:desktopTest not run in CI agent environment (missing mediamp-mpv dependency on Linux host).
Open in Web View Automation 

Commit 5a0b623 removed the guard that skipped applying an empty remote
collections JSON when the device already had local collections. That let
pullFromServer wipe unsynced local collections and debounced push could
persist the empty state to the server.

Restore the preservation check with JsonNull-aware empty detection and
add unit tests for isRemoteCollectionsEmpty.

Co-authored-by: Fab <CreepsoOff@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