Syncing settings across devices without leaking or losing changes
Two bugs in Melodius's cross-device settings sync, one privacy and one data loss, and the fixes: claim local data for the signed-in account before reading it, and refuse saves older than the server's copy.
Sound settings, appearance and the queue in Melodius follow you between the web, desktop and Android. Each device keeps a local copy for instant start-up and syncs with the server. A simple rule, "the newer copy wins", hid two bugs.
The model: newer copy wins
Each copy carries the time it was last changed. On start-up, a device compares its copy with the server's and keeps the newer one, pushing it up if local was newer. It handles offline edits well: change your equalizer on a plane, and it reaches your other devices when you land.
Bug one: the previous listener's settings
Signing out on the web or Windows left the device's sound and appearance copies, and the queue, behind. When a different account signed in on the same device, "the newer copy wins" saw a recent local copy and saved the previous listener's settings into the new account.
Fix: local data now belongs to an account. On sign-in, the account claims the device's local data before anything reads it. Data owned by another account is removed, and a browser tab still holding another account's state reloads clean.
Bug two: a slow save from the past
A save that left a device on a bad connection could arrive after a newer save from another device and overwrite it. Same for a device that had been offline with old settings.
Fix: the server refuses a save older than the copy it already has. The client's timestamp travels with the save, so the server can make the same "newer wins" decision the clients do, at the only place that sees every write.
The rules now
- Local data is scoped to the signed-in account and claimed before it is read.
- Every copy carries its change time.
- Clients keep the newer copy on start-up.
- The server rejects writes older than what it has.
- Everything read from storage or another device passes a sanitiser, as in the equalizer settings.
