[GH-ISSUE #73] Reordering of queue has unexpected behaviours #56

Closed
opened 2026-02-28 14:24:59 +03:00 by kerem · 13 comments
Owner

Originally created by @devgianlu on GitHub (Aug 21, 2024).
Original GitHub issue: https://github.com/devgianlu/go-librespot/issues/73

Android: reordering tracks will duplicate the track being moved
iPhone: https://community.volumio.com/t/new-2023-spotify-plugin/63381/362

Originally created by @devgianlu on GitHub (Aug 21, 2024). Original GitHub issue: https://github.com/devgianlu/go-librespot/issues/73 Android: reordering tracks will duplicate the track being moved iPhone: https://community.volumio.com/t/new-2023-spotify-plugin/63381/362
kerem 2026-02-28 14:24:59 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@aykevl commented on GitHub (Oct 4, 2024):

I debugged this a bit.

The issue appears to be that added tracks need an uid to make things like reordering work correctly. Adding an uid fixes this.

Spotify apps add a uid in the form of q0, q1, q2, etc.

Interestingly a similar bug is present when transferring between the Android app and open.spotify.com, or between different instances of open.spotify.com: if you add a few songs to the queue, then transfer to a different device, and then add some more songs, the queue now has multiple queued tracks of the same uid because the new device started counting from 0 again. That will really mess up the queue when you try to reorder these songs.
This is clearly a Spotify bug though. I'd say we can do better :)
(Maybe it's only a bug in open.spotify.com? I haven't tried transferring between native apps yet).

<!-- gh-comment-id:2393282383 --> @aykevl commented on GitHub (Oct 4, 2024): I debugged this a bit. The issue appears to be that added tracks need an uid to make things like reordering work correctly. Adding an uid fixes this. Spotify apps add a uid in the form of `q0`, `q1`, `q2`, etc. Interestingly a similar bug is present when transferring between the Android app and open.spotify.com, or between different instances of open.spotify.com: if you add a few songs to the queue, then transfer to a different device, and then add some more songs, the queue now has multiple queued tracks of the same uid because the new device started counting from 0 again. That will really mess up the queue when you try to reorder these songs. This is clearly a Spotify bug though. I'd say we can do better :) (Maybe it's only a bug in open.spotify.com? I haven't tried transferring between native apps yet).
Author
Owner

@aykevl commented on GitHub (Oct 4, 2024):

The same issue is present when transferring from Spotify Android to the desktop app (on MacOS). The UIDs start counting again from 0, and reordering the queue messes up the whole queue. So this issue seems really widespread among Spotify apps.

<!-- gh-comment-id:2394516664 --> @aykevl commented on GitHub (Oct 4, 2024): The same issue is present when transferring from Spotify Android to the desktop app (on MacOS). The UIDs start counting again from 0, and reordering the queue messes up the whole queue. So this issue seems really widespread among Spotify apps.
Author
Owner

@devgianlu commented on GitHub (Oct 4, 2024):

I wonder if this is somehow related to #54

<!-- gh-comment-id:2394540975 --> @devgianlu commented on GitHub (Oct 4, 2024): I wonder if this is somehow related to #54
Author
Owner

@aykevl commented on GitHub (Oct 4, 2024):

Yeah I was thinking the same. We can fix this bug and see if that helps.

I'll probably send a PR tomorrow.

<!-- gh-comment-id:2394563830 --> @aykevl commented on GitHub (Oct 4, 2024): Yeah I was thinking the same. We can fix this bug and see if that helps. I'll probably send a PR tomorrow.
Author
Owner

@justinerickson commented on GitHub (Oct 4, 2024):

Interesting, is there an easy way to see the UIDs assigned?

I'm particularly curious to see if I can check how they look when playing on Echo/Alexa or Google Home as so far they seem to be stable with multiple devices adding to the same Spotify Jam and reordering the play queue. Though unsure if I'm getting lucky or they're doing something different. I am using Spotify MacOS and iPhone mostly but also didn't see issue with a quick test with open.spotify.com (but was just a quick test). Btw in case helpful Spotify Jam seemed to work well prior to the new plug-in (ie with volspotconnect2) though unsure if Spotify API changed since then.

Let me know if there is anything I can help capture/test to diagnose and/or see if the new PR tomorrow runs into other issues.

<!-- gh-comment-id:2394699388 --> @justinerickson commented on GitHub (Oct 4, 2024): Interesting, is there an easy way to see the UIDs assigned? I'm particularly curious to see if I can check how they look when playing on Echo/Alexa or Google Home as so far they seem to be stable with multiple devices adding to the same Spotify Jam and reordering the play queue. Though unsure if I'm getting lucky or they're doing something different. I am using Spotify MacOS and iPhone mostly but also didn't see issue with a quick test with open.spotify.com (but was just a quick test). Btw in case helpful Spotify Jam seemed to work well prior to the new plug-in (ie with volspotconnect2) though unsure if Spotify API changed since then. Let me know if there is anything I can help capture/test to diagnose and/or see if the new PR tomorrow runs into other issues.
Author
Owner

@aykevl commented on GitHub (Oct 5, 2024):

Interesting, is there an easy way to see the UIDs assigned?

The way I did it is by opening Developer Tools (Firefox) of open.spotify.com, and in the network tab filtering for WebSocket connections (you will need to reload the page for it to become visible). If you select the one WebSocket connection and go to the Response tab, you can see all the messages exchanged. One of the more frequent messages you see is a cluster update, which contains payloads[0].cluster.player_state.next_tracks.
The same probably also works in Chrome.

Note that the API is different between the desktop app and open.spotify.com, but the player state appears to be the same data structure.

I'm particularly curious to see if I can check how they look when playing on Echo/Alexa or Google Home as so far they seem to be stable with multiple devices adding to the same Spotify Jam and reordering the play queue.

I would be very curious about that!
I'm not using Spotify Jam, just normal "connect to a different device". I guess Spotify Jam might work differently?

<!-- gh-comment-id:2394989233 --> @aykevl commented on GitHub (Oct 5, 2024): > Interesting, is there an easy way to see the UIDs assigned? The way I did it is by opening Developer Tools (Firefox) of open.spotify.com, and in the network tab filtering for WebSocket connections (you will need to reload the page for it to become visible). If you select the one WebSocket connection and go to the Response tab, you can see all the messages exchanged. One of the more frequent messages you see is a cluster update, which contains `payloads[0].cluster.player_state.next_tracks`. The same probably also works in Chrome. Note that the API is different between the desktop app and open.spotify.com, but the player state appears to be the same data structure. > I'm particularly curious to see if I can check how they look when playing on Echo/Alexa or Google Home as so far they seem to be stable with multiple devices adding to the same Spotify Jam and reordering the play queue. I would be very curious about that! I'm not using Spotify Jam, just normal "connect to a different device". I guess Spotify Jam might work differently?
Author
Owner

@aykevl commented on GitHub (Oct 5, 2024):

Fixed here: https://github.com/devgianlu/go-librespot/pull/114

By the way, to reproduce the reordering issue among official Spotify apps (controlled from Spotify Android):

  • clear the queue
  • switch to a different device
  • add a track to the queue
  • switch to a different device (could be the first again)
  • add a different track to the queue
  • reorder the tracks

You may have to do the last step more than once to see the bug. The bug is that after a reorder, both tracks in the queue are now the same (in fact, if you select one, the other will be selected as well at the same time).

<!-- gh-comment-id:2395007591 --> @aykevl commented on GitHub (Oct 5, 2024): Fixed here: https://github.com/devgianlu/go-librespot/pull/114 By the way, to reproduce the reordering issue among official Spotify apps (controlled from Spotify Android): * clear the queue * switch to a different device * add a track to the queue * switch to a different device (could be the first again) * add a different track to the queue * reorder the tracks You may have to do the last step more than once to see the bug. The bug is that after a reorder, both tracks in the queue are now the same (in fact, if you select one, the other will be selected as well at the same time).
Author
Owner

@justinerickson commented on GitHub (Oct 5, 2024):

I tried combos of adding songs, reordering, finishing songs to dequeue, across Spotify MacOS, Spotify iOS, and open.spotify.com playing on my Echo Dot. It is able to successfully keep monotonically increasing the UID.

It is able to do so even when I reorder such that we dequeue the highest uid (as well as finish playing the previously dequeued highest uid. I'm unsure where it preserves the highest uid as I don't see it anywhere in the payloads JSON. I can see that Spotify is keeping my Recently Played songs in the Spotify MacOS app though

Here is my specific set of steps (and checks I did to confirm it works with Echo Dot). I also attached the final state of next_tracks JSON values
next_tracks_json.txt

Steps taken

  1. Set all to play on Echo Dot (without Spotify Jam)
  2. Added songs to queue from Spotify MacOS, iOS, and open.spotify.com
  3. Check: Correctly number with unique UIDs prior to reordering across all 3 devices
  4. Shuffle songs on multiple devices in random orders
  5. Check: preserves original unique UIDs in new ordering
  6. Finish current song (causes q3 to queue)
  7. Add a new song from Spotify MacOS, iOS, and open.spotify.com
  8. Check: New song is added as q10, q11, q12 (kept q3 unused)
  9. Put q12 (highest number as next in queue) and q1 at end of queue
  10. Finished current song so q12 starts playing
  11. Check: New song added as q13 (see current track preserves uid: “q12”)
  12. Put q13 as next song
  13. Finish playing q12 and q13 (current song is now q6)
  14. Add new song from iOS app
  15. Check: New song added as q14 (unsure how??)
  16. Moved q14 top of queue and finish current and q14
  17. Add new song from open.spotify.com
  18. Check: New song added as q15 (still unsure how??)
  19. Captured ending state below

uids to device mapping
Just added songs prior to shuffling
q0 = Spotify MacOS
q1 = Spotify iOS
q2 = Spotify iOS
q3 = open.spotify.com
a4 = Spotify MacOS
q5 = open.spotify.com
q6 = open.spotify.com

Added after shuffling
q7 = Spotify MacOS
q8 = Spotify iOS
q9 = open.spotify.com

After song finishes & q3 becomes current song
q10 = Spotify MacOS
q11 = open.spotify.com
q12 = Spotify iOS

After making the highest number song finish playing (not just dequeue)
q13 = Spotify MacOS
q14 = Spotify iOS
q15 = open.spotify.com

<!-- gh-comment-id:2395174408 --> @justinerickson commented on GitHub (Oct 5, 2024): I tried combos of adding songs, reordering, finishing songs to dequeue, across Spotify MacOS, Spotify iOS, and open.spotify.com playing on my Echo Dot. It is able to successfully keep monotonically increasing the UID. It is able to do so even when I reorder such that we dequeue the highest uid (as well as finish playing the previously dequeued highest uid. I'm unsure where it preserves the highest uid as I don't see it anywhere in the payloads JSON. I can see that Spotify is keeping my Recently Played songs in the Spotify MacOS app though Here is my specific set of steps (and checks I did to confirm it works with Echo Dot). I also attached the final state of next_tracks JSON values **[next_tracks_json.txt](https://github.com/user-attachments/files/17267328/next_tracks_json.txt)** **Steps taken** 1. Set all to play on Echo Dot (without Spotify Jam) 2. Added songs to queue from Spotify MacOS, iOS, and [open.spotify.com](http://open.spotify.com/) 3. Check: Correctly number with unique UIDs prior to reordering across all 3 devices 4. Shuffle songs on multiple devices in random orders 5. Check: preserves original unique UIDs in new ordering 6. Finish current song (causes q3 to queue) 7. Add a new song from Spotify MacOS, iOS, and open.spotify.com 8. Check: New song is added as q10, q11, q12 (kept q3 unused) 9. Put q12 (highest number as next in queue) and q1 at end of queue 10. Finished current song so q12 starts playing 11. Check: New song added as q13 (see current track preserves uid: “q12”) 12. Put q13 as next song 13. Finish playing q12 and q13 (current song is now q6) 14. Add new song from iOS app 15. Check: New song added as q14 (unsure how??) 16. Moved q14 top of queue and finish current and q14 17. Add new song from [open.spotify.com](http://open.spotify.com/) 18. Check: New song added as q15 (still unsure how??) 19. Captured ending state below **uids to device mapping** Just added songs prior to shuffling q0 = Spotify MacOS q1 = Spotify iOS q2 = Spotify iOS q3 = [open.spotify.com](http://open.spotify.com/) a4 = Spotify MacOS q5 = [open.spotify.com](http://open.spotify.com/) q6 = [open.spotify.com](http://open.spotify.com/) Added after shuffling q7 = Spotify MacOS q8 = Spotify iOS q9 = [open.spotify.com](http://open.spotify.com/) After song finishes & q3 becomes current song q10 = Spotify MacOS q11 = [open.spotify.com](http://open.spotify.com/) q12 = Spotify iOS After making the highest number song finish playing (not just dequeue) q13 = Spotify MacOS q14 = Spotify iOS q15 = [open.spotify.com](http://open.spotify.com/)
Author
Owner

@justinerickson commented on GitHub (Oct 5, 2024):

Ahh I missed where you said switch to a different device for playing after reordering, above was all on same playing device. I do see the bug where Spotify resets uid to "q0" after each playing device switch.

Here is what I see when I switch devices (between Echo Dot, Google Home, and Spotify MacOS):

  • Each time I switch device, any newly added items in queue start at "q0" again causing duplicates
  • Queue seems to play just fine and items don't disappear like what I was seeing with Volumio
  • Reordering seems to work on non duplicate uid songs (though janky UI if you are watching the queue per last point)
  • Reordering with duplicate uid songs seems to often not actual reorder, though doesn't seem to drop songs (with janky UI in all cases per last point)
  • Spotify UI falls temporarily out of sync when reordering or new song plays with duplicate uid (close / reopen queue panel seems to fix this)

Attached is next_tracks JSON after switching between devices a few times and adding songs in between. Then reodering and playing one of the uid:"q0" songs.
next_tracks_swapdevices_json.txt

Seems like each device ideally would set the next uid to the max uid of the next_tracks objects (possibly max of next_tracks uid's + current song uid) instead of resetting to q0. Just saw your PR already does this with next_track uids. Doesn't seem like there is much value in doing max of next_tracks + current song uid since going back oddly does not re-enqueue the current track

Note: The bug I was seeing with Volumio that reordering from multiple devices was causing items to disappear even when playing on the single Volumio device the entire time.

<!-- gh-comment-id:2395194524 --> @justinerickson commented on GitHub (Oct 5, 2024): Ahh I missed where you said switch to a different device for playing after reordering, above was all on same playing device. I do see the bug where Spotify resets uid to "q0" after each playing device switch. Here is what I see when I switch devices (between Echo Dot, Google Home, and Spotify MacOS): * Each time I switch device, any newly added items in queue start at "q0" again causing duplicates * Queue seems to play just fine and items don't disappear like what I was seeing with Volumio * Reordering seems to work on non duplicate uid songs (though janky UI if you are watching the queue per last point) * Reordering with duplicate uid songs seems to often not actual reorder, though doesn't seem to drop songs (with janky UI in all cases per last point) * Spotify UI falls temporarily out of sync when reordering or new song plays with duplicate uid (close / reopen queue panel seems to fix this) Attached is next_tracks JSON after switching between devices a few times and adding songs in between. Then reodering and playing one of the uid:"q0" songs. [next_tracks_swapdevices_json.txt](https://github.com/user-attachments/files/17267433/next_tracks_swapdevices_json.txt) Seems like each device ideally would set the next uid to the max uid of the next_tracks objects (possibly max of next_tracks uid's + current song uid) instead of resetting to q0. Just saw [your PR](https://github.com/aykevl/go-librespot/commit/18c67d5d9ecae76a21ed5dd5d447307d782aea80) already does this with next_track uids. Doesn't seem like there is much value in doing max of next_tracks + current song uid since going back oddly does not re-enqueue the current track Note: The bug I was seeing with Volumio that reordering from multiple devices was causing items to disappear even when playing on the single Volumio device the entire time.
Author
Owner

@aykevl commented on GitHub (Oct 5, 2024):

@justinerickson thank you for the in-depth testing! Then it really looks like a Spotify bug here, that we can only work around.

One other option would be to assign random UIDs, I tried this and it works but figured that keeping the pattern of q0, q1, etc might be better for compatibility.

<!-- gh-comment-id:2395205405 --> @aykevl commented on GitHub (Oct 5, 2024): @justinerickson thank you for the in-depth testing! Then it really looks like a Spotify bug here, that we can only work around. One other option would be to assign random UIDs, I tried this and it works but figured that keeping the pattern of q0, q1, etc might be better for compatibility.
Author
Owner

@justinerickson commented on GitHub (Oct 5, 2024):

No problem and agreed your PR looks like the best workaround for swapping playing devices.

For the original issue where attempting to reorder songs that were added to a Volumio queue (without changing playing device) was causing them to disappear is a symptom of not setting "uid"? If so, this hopefully that fixes the other issues I was seeing with the queue disappearing periodically when trying to use multiple Spotify apps to add songs to the same Volumio playing device queue.

<!-- gh-comment-id:2395208322 --> @justinerickson commented on GitHub (Oct 5, 2024): No problem and agreed your PR looks like the best workaround for swapping playing devices. For the original issue where attempting to reorder songs that were added to a Volumio queue (without changing playing device) was causing them to disappear is a symptom of not setting "uid"? If so, this hopefully that fixes the other issues I was seeing with the queue disappearing periodically when trying to use multiple Spotify apps to add songs to the same Volumio playing device queue.
Author
Owner

@justinerickson commented on GitHub (Oct 21, 2024):

FYI I manually updated my setup with this fix and from initial testing so far seems to fix all the multi-user Spotify Jams/enqueuing issues. Will post if any new surprises. Thanks for the fix (and pointers on how to inspect the Spotify payloads)!!!

<!-- gh-comment-id:2427544257 --> @justinerickson commented on GitHub (Oct 21, 2024): FYI I manually updated my setup with this fix and from initial testing so far seems to fix all the multi-user Spotify Jams/enqueuing issues. Will post if any new surprises. Thanks for the fix (and pointers on how to inspect the Spotify payloads)!!!
Author
Owner

@pachulo commented on GitHub (Feb 2, 2025):

Hi! I am still experiencing weird behaviour when reordering tracks on the queue from the Android's Spotify app: it seems like the changes of order are ignored.
Sorry, the queue works OK; I'm experiencing weird behaviour when reordering tracks from the "Next From:". Those changes are ignored when listening through go-librespot.

Thanks for all the work involved!

<!-- gh-comment-id:2629325133 --> @pachulo commented on GitHub (Feb 2, 2025): Hi! ~I am still experiencing weird behaviour when reordering tracks on the queue from the Android's Spotify app: it seems like the changes of order are ignored.~ Sorry, the queue works OK; I'm experiencing weird behaviour when reordering tracks from the "Next From:". Those changes are ignored when listening through go-librespot. Thanks for all the work involved!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/go-librespot#56
No description provided.