When you create a shelf on the device, it is marked as not synced. When you sync to the Kobo server, this is changed. Plus an id is added to help with the syncing. When you delete the shelf, the shelf is marked as deleted, but is still in the database. At the next sync, this is passed to the server and the database row removed. If you sync another device or app, the new shelves are created and the deleted shelves remove. If you do the signout/signin, the server will create these shelves it at whatever was the last sync state.
If you use the shelf management in the KoboTouch driver in calibre, it emulates what happens when you create or delete a shelf. This means that if you let calibre do the shelf management, when you sync to the server, the state of the shelves should be sent correctly.
If you get the duplicated shelves problem, I recommend not using the "Purge duplicate shelves" option when fixing them. If you use this, the shelves are removed completely from the database and a sync will probably bring them back. Without the option, the duplicates are marked as delete and should mark them as deleted on the server during a sync.
|