Skip to content

fix(web): serialize addTrackToPlaylist saga to stop dropping bulk-added tracks#14422

Closed
dylanjeffers wants to merge 1 commit into
mainfrom
claude/fix-playlist-add-track-race
Closed

fix(web): serialize addTrackToPlaylist saga to stop dropping bulk-added tracks#14422
dylanjeffers wants to merge 1 commit into
mainfrom
claude/fix-playlist-add-track-race

Conversation

@dylanjeffers
Copy link
Copy Markdown
Contributor

Summary

  • addTrackToPlaylist saga used takeEvery so concurrent dispatches raced: each captured the cached playlist, mutated locally, then wrote back only after the slow updatePlaylistArtwork finished. With overlapping sagas, the later write overwrote the earlier one with a captured-stale playlist, dropping the earlier added track on both the cache and the backend (the confirmer's SDK update used the same captured playlist).
  • Reported by a user as: adding tracks to a (new) playlist appears to "do nothing" — paste 5 URLs, end up with 1 track. The add-tracks-by-URL modal's 30 ms inter-dispatch delay was a workaround that didn't cover the artwork-generation window.
  • Fix: switch the watcher to actionChannel + a serial take loop so each add runs to completion (cache write + confirmer queued) before the next one starts reading.

Test plan

  • Open a new (or existing) playlist on web; paste 5 track URLs into the "Add tracks by URL" modal; confirm all 5 tracks appear in the playlist and persist after refresh.
  • Add 5 tracks one-by-one via the track menu's "Add to Playlist" → confirm all 5 persist.
  • Add a single track via paste-URL → still works and toast appears once.
  • Remove tracks from the playlist (existing flow) → still works, no regression.
  • Add a track, then immediately click Apply in playlist edit mode after staging a removal → both the addition and the removal are reflected after the save settles.

🤖 Generated with Claude Code

…racks

The saga used `takeEvery`, so two ADD_TRACK_TO_PLAYLIST dispatches in close
succession would run concurrently. Each invocation read the cached playlist,
mutated a local copy to append its track, and only wrote the result back
after `updatePlaylistArtwork` finished (canvas image generation, often
100–300ms). When a second saga read between the first saga's read and write,
both captured the same "N tracks" baseline; both wrote "N+1", each with only
their own added track; the later write won and dropped the earlier track.
The confirmer's SDK update used the same captured-stale playlist, so the
backend lost the missing tracks too.

This was reproducible via the add-tracks-by-URL modal — 5 pasted URLs would
often land as just 1 track in the playlist, both in the UI and on refresh.
The modal's 30ms inter-dispatch delay was a workaround that couldn't cover
the full artwork-generation window.

Switch to an actionChannel + serial take loop so adds for the same (or
different) playlists process one-at-a-time. Each saga now sees the prior
saga's optimistic update before reading its own baseline.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 29, 2026

⚠️ No Changeset found

Latest commit: 5a6aaf1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

🌐 Web preview ready

Preview URL: https://audius-web-preview-pr-14422.audius.workers.dev

Unique preview for this PR (deployed from this branch).
Workflow run

@dylanjeffers
Copy link
Copy Markdown
Contributor Author

Closing — diagnosis was wrong. The user has confirmed the failing flow is single-track add via the track menu / drag-drop (not bulk paste-URL), and the bug started in the last 1–2 days, which doesn't match the pre-existing concurrency race this PR addresses. Re-investigating.

@dylanjeffers dylanjeffers deleted the claude/fix-playlist-add-track-race branch May 29, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant