fix(playlists): a replayed append whose reply was lost adds nothing more (#8122)

An append that reached the server but whose reply never reached the
phone stayed in the offline queue and was sent again, and since an
append is an action, the song landed twice. Android now names each
append with a request id, carried by the live send and its queued row
alike; POST /api/playlists/{id}/tracks takes it as request_id, and the
server records it per playlist in the append's own transaction
(playlist_append_requests, pruned after 30 days). A send whose id is
already recorded changes nothing; a failed append rolls its id back
with it. Without an id an append behaves as before, so queued rows
from older builds and Subsonic clients are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-28 11:52:12 -05:00
co-authored by Claude Opus 5.5
parent 6996561cb1
commit ad17849205
15 changed files with 207 additions and 20 deletions
+12 -1
View File
@@ -296,6 +296,10 @@ func (h *handlers) handleDeletePlaylist(w http.ResponseWriter, r *http.Request)
type appendTracksBody struct {
TrackIDs []string `json:"track_ids"`
// RequestID names this append, so a client that sends it again (a
// queued write replayed after its reply was lost) adds nothing more.
// Optional: without it, every send appends.
RequestID string `json:"request_id"`
}
// handleAppendTracks implements POST /api/playlists/{id}/tracks. Owner
@@ -318,7 +322,14 @@ func (h *handlers) handleAppendTracks(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
if err := h.playlists.AppendTracks(r.Context(), caller.ID, playlistID, trackIDs); err != nil {
var requestID pgtype.UUID
if body.RequestID != "" {
if requestID, ok = parseUUID(body.RequestID); !ok {
writeErr(w, apierror.BadRequest("bad_request", fmt.Sprintf("invalid request id %q", body.RequestID)))
return
}
}
if err := h.playlists.AppendTracksOnce(r.Context(), caller.ID, playlistID, trackIDs, requestID); err != nil {
h.writePlaylistErr(w, err, "append tracks")
return
}