Repository navigation
feat: client-side Spotify-style shuffle for native streaming - #380
Conversation
Own the shuffled play order in-app (LoadRequest::from_tracks with spirc shuffle off) so every track plays once per pass and queue suspend/resume reloads the same order instead of reshuffling the context. Lazy-loads the full playlist/Liked Songs context in the background (3000-track cap), restores original order on shuffle-off, and reshuffles each repeat-all lap.
- drop the write-only context_uri field from NativeSpotifyShuffleSession - extract reanchor_by_rank for the duplicated re-anchor blocks in finish_full_context_fetch - extract a shared paginate_uris helper for the playlist/saved-track fetch loops
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughNative streaming playback now owns stable Spotify-style shuffle sessions for supported contexts. Sessions load and merge context tracks, track duplicate-aware playback indexes, survive queue suspension and resume, reshuffle repeat-all laps, and clear when playback targets or devices change. ChangesNative Spotify shuffle
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant App
participant Network
participant SpotifyAPI
participant StreamingPlayer
User->>App: Enable shuffle and start context
App->>Network: ToggleNativeShuffleSession
Network->>SpotifyAPI: Fetch context tracks
SpotifyAPI-->>Network: Track URIs
Network->>StreamingPlayer: Load shuffled URI order
StreamingPlayer-->>App: TrackChanged
App->>Network: ReshuffleNativeShuffleLap or ResumeNativeShuffleSession
Network->>StreamingPlayer: Reload session order
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
src/infra/queue/dispatch.rs (1)
688-700: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd regression coverage for both resume outcomes.
Test that
Some(index)preserves the existing shuffle order and thatNoneclears or finishes the session. Because this branch is behindfeature = "streaming", slim telemetry tests alone will not exercise it. As per coding guidelines, add or adjust tests when behavior changes.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/infra/queue/dispatch.rs` around lines 688 - 700, Add regression tests for the SpotifyShuffled resume handling around ResumeNativeShuffleSession: cover Some(index) preserving the existing shuffle order and None clearing or finishing the session. Ensure the tests enable the streaming feature and exercise the dispatch branch rather than only slim telemetry paths.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/core/app.rs`:
- Around line 3937-3950: The manual Next flow must pass SuspendCause::ManualSkip
when suspending the native Spotify shuffle context. Update the caller path in
next_track and the suspend_native_spotify_context_for_queue invocation so manual
skips reach resume_index_after_queue with ManualSkip, while preserving
AutoAdvance for automatic queue advancement.
In `@src/core/queue.rs`:
- Around line 75-80: Update the SpotifyShuffled suspend state and the native
shuffle session lifecycle so suspended resumes cannot outlive the session they
belong to. Prefer storing the session generation alongside resume_index and have
resume_native_shuffle_session() validate it against the active
native_spotify_shuffle before applying the index; alternatively, ensure
clear_native_shuffle_session() also clears queue_suspended.
In `@src/tui/ui/popups.rs`:
- Around line 188-191: Update the SuspendedContext::SpotifyShuffled match arm to
inspect resume_index: return spotify_mirror(max) only for Some(_), and return an
empty Vec for None so exhausted shuffle sessions produce no preview tracks.
---
Nitpick comments:
In `@src/infra/queue/dispatch.rs`:
- Around line 688-700: Add regression tests for the SpotifyShuffled resume
handling around ResumeNativeShuffleSession: cover Some(index) preserving the
existing shuffle order and None clearing or finishing the session. Ensure the
tests enable the streaming feature and exercise the dispatch branch rather than
only slim telemetry paths.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: e6a196fc-0f15-493a-b141-50b5ff6b2982
📒 Files selected for processing (10)
CHANGELOG.mdsrc/core/app.rssrc/core/queue.rssrc/infra/network/metadata.rssrc/infra/network/mod.rssrc/infra/network/native_shuffle.rssrc/infra/network/playback.rssrc/infra/player/events.rssrc/infra/queue/dispatch.rssrc/tui/ui/popups.rs
- Bind a suspended shuffle resume to its session generation so a session replaced while the queue drains cannot inherit a stale index. The resume handler applies the index only while the live session's generation matches, and clears only the session it actually suspended. - Pass the suspend cause through suspend_native_spotify_context_for_queue: a manual Next uses ManualSkip (advances under repeat-one) while an auto track-end uses AutoAdvance (replays under repeat-one). - Show no queue-preview rows for an exhausted shuffle session (None resume). - Add regression tests for generation forwarding and repeat-one cause behavior.
|
@coderabbitai All four findings are addressed in 0489994. 1. Bind the suspended shuffle resume to the shuffle session (Major). 2. Pass 3. Respect an exhausted resume index in the preview. 4. Regression coverage. Verified with |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
git show --no-ext-diff --stat --oneline 0489994
printf '\n=== Changed paths ===\n'
git diff-tree --no-commit-id --name-only -r 0489994
printf '\n=== Relevant symbols and tests ===\n'
rg -n -C 4 \
'SpotifyShuffled|ResumeNativeShuffleSession|SuspendCause|suspend_native_spotify_context_for_queue|queue_preview_tracks|resume_native_shuffle_session|generation.*resume|repeat.one|repeat_one' \
src/core/app.rs src/core/queue.rs src/infra/network/mod.rs src/infra/network/native_shuffle.rs src/infra/queue/dispatch.rs src/tui/ui/popups.rs \
|| true
printf '\n=== Commit patch ===\n'
git show --no-ext-diff --format=fuller --find-renames 0489994 -- \
src/core/app.rs src/core/queue.rs src/infra/network/mod.rs src/infra/network/native_shuffle.rs src/infra/queue/dispatch.rs src/tui/ui/popups.rsLength of output: 46532 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '=== Resume handler ==='
sed -n '595,655p' src/infra/network/native_shuffle.rs
printf '%s\n' '=== Full-context fetch generation validation and suspended remap ==='
sed -n '770,945p' src/infra/network/native_shuffle.rs
printf '%s\n' '=== All SpotifyShuffled construction sites ==='
rg -n -C 5 'SpotifyShuffled\s*\{' src --glob '*.rs'
printf '%s\n' '=== Suspend-cause definitions and call sites ==='
rg -n -C 4 'enum SuspendCause|SuspendCause::(ManualSkip|AutoAdvance)|suspend_native_spotify_context_for_queue\s*\(' \
src --glob '*.rs'Length of output: 30032
I did not independently execute the reported formatting, clippy, or test commands, but the implementation and test coverage match the stated fixes. ✏️ Learnings added
|
What
Client-side ("Spotify-style") shuffle for native streaming. When shuffle is on and you start a playlist, album, or Liked Songs with spotatui as the playback device, the app now owns the shuffled play order itself (a flat, pre-shuffled URI list loaded via
LoadRequest::from_trackswith Spirc-side shuffle off) instead of delegating shuffle to Spirc/Spotify.Why
Spirc/Spotify regenerate the shuffle order on every context reload. Because the native queue suspends and resumes the context on each queued track, a queue interruption could reshuffle the remaining order and replay tracks you had already heard. Owning the order in-app means a suspend/resume reloads the same order at the right index, so every track plays exactly once per pass.
Behavior
--no-default-features --features telemetry) CI build is unaffected: the pure order/merge helpers are unconditional and unit-tested, the streaming orchestration is#[cfg(feature = "streaming")].Commits
feat: the client-side shuffle session, background context fetch, queue suspend/resume integration, and lap reshuffle.refactor: post-review cleanup (dropped a write-only session field, extracted the duplicated re-anchor logic and the playlist/saved-track pagination loops).docs: CHANGELOG entry.Testing
cargo fmt --allcargo clippy -- -D warnings(streaming) andcargo clippy --no-default-features --features telemetry -- -D warnings(slim)cargo test --no-default-features --features telemetry(462 passed, including the new shuffle helper tests)Summary by CodeRabbit