Skip to content

fix(playback): treat a pause with no active device as done - #707

Merged
LargeModGames merged 1 commit into
mainfrom
fix/pause-no-active-device
Oct 5, 2026
Merged

LargeModGames merged 1 commit into
mainfrom
fix/pause-no-active-device

Conversation

@LargeModGames

@LargeModGames LargeModGames commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes #704.

With startup behavior set to Pause and no Spotify device active, spotatui opened the full-screen error page on launch with Spotify API 404 Not Found failed: ... NO_ACTIVE_DEVICE.

Pause never transfers playback to a device at startup, so the startup pause is a bare PUT me/player/pause. With nothing active, Spotify answers 404 NO_ACTIVE_DEVICE. The saved-device retry is skipped because native streaming can claim the command, and the "native backend pending" suppression no longer applies because deferred startup has just cleared that flag. So pause_playback called handle_error.

A pause that finds no active device has nothing to pause, so the requested state already holds. pause_playback now logs that case and returns. The check sits after the native suppression, so the "Reconnecting native streaming" status during recovery is unchanged, and it is outside any #[cfg], so it covers the streaming startup, the non-streaming startup in runtime/startup.rs and the GUI.

The test reuses the HTTP stub helpers from the metadata.rs tests, which are now pub(crate).

Testing

  • New test pause_with_no_active_device_is_not_an_error serves the real 404 body from a local listener. Without the fix it fails with:
    left: "Spotify API 404 Not Found failed: {\"error\":{\"status\":404,\"message\":\"Player command failed: No active device found\",\"reason\":\"NO_ACTIVE_DEVICE\"}} [PUT /v1/me/player/pause]"
    right: ""
    
  • cargo fmt --all -- --check: exit 0
  • cargo clippy --no-default-features --features telemetry,tui -- -D warnings: Finished, exit 0
  • cargo clippy --no-default-features --features telemetry -- -D warnings: Finished, exit 0
  • cargo clippy -- -D warnings: Finished, exit 0
  • cargo test --no-default-features --features telemetry,tui:
    test result: ok. 1422 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 7.57s
    
  • cargo test:
    test infra::network::playback::tests::pause_with_no_active_device_is_not_an_error ... ok
    test result: ok. 1812 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 7.60s
    

I have not done the manual repro with a live account yet (Pause startup, all Spotify clients closed, with and without enable_streaming).

Additional notes

  • CLI: spotatui playback --toggle only pauses when Spotify just reported is_playing. If the device disappears between that poll and the pause, the command now exits 0 instead of non-zero. I think that is the right result, since nothing is playing.
  • The pause no longer marks a cached playback context as paused in this case. At startup there is no context, and the next playback poll corrects a stale one. Writing it here would raise direct_playback_context_reads.

💬 Questions or want to chat with other contributors? Join the spotatui Discord.

Summary by CodeRabbit

  • Bug Fixes
    • Pausing playback when no Spotify device is active now completes without displaying a full-screen error. Other playback errors continue to be handled as before.

With startup behavior Pause and no Spotify device active, the startup
pause got 404 NO_ACTIVE_DEVICE and opened the full-screen error page.
Nothing plays anywhere in that case, so the pause already holds: log it
and return instead of reporting an error.
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — configured

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: LargeModGames/spotatui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 65db771d-ad77-4820-8d31-1ee99165b82f
📥 Commits

Reviewing files that changed from the base of the PR and between ad2c690 and b030b27.

📒 Files selected for processing (2)
  • src/infra/network/metadata.rs
  • src/infra/network/playback.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

When Spotify reports NO_ACTIVE_DEVICE during a pause request, the app now returns without displaying a full-screen error. A regression test checks the resulting API error and route state.

Changes

Pause handling

Layer / File(s) Summary
Handle and test no-active-device responses
src/infra/network/playback.rs, src/infra/network/metadata.rs
pause_playback returns without surfacing an error for NO_ACTIVE_DEVICE. The regression test checks that no API error is recorded and the app does not navigate to the Error route. Network test helpers are now visible within the crate.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to b030b

Pausing without an active Spotify device should no longer show the startup error. No issue requiring a fix before merge was identified.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title uses the established fix(playback): prefix and clearly describes the change to treat NO_ACTIVE_DEVICE during pause as a successful no-op.
Linked Issues check ✅ Passed Issue [#704] requires Pause startup to avoid a Spotify 404 error when no device is active. pause_playback now returns on NO_ACTIVE_DEVICE after native-streaming suppression, instead of calling `ha…
Out of Scope Changes check ✅ Passed The playback change addresses [#704]. The visibility changes in metadata.rs expose existing HTTP test helpers for the new regression test. No unrelated changes appear in the reviewed diff.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
✨ Simplify code
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.95918% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/infra/network/playback.rs 97.7% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@LargeModGames
LargeModGames merged commit af8ba87 into main Oct 5, 2026
35 checks passed
@LargeModGames
LargeModGames deleted the fix/pause-no-active-device branch October 5, 2026 20:12
LargeModGames added a commit that referenced this pull request Oct 7, 2026
… (#694)

# Summary

Fixes #693. When I move playback from spotatui to my phone or CarPlay,
it jumped back to spotatui after a few seconds.

The PR has two parts. The first is the fix itself, the second came out
of testing it.

## 1. The idle poll no longer takes playback back after a handoff

What happens: after the handoff the playback poll gets `204 No Content`
for a moment (nobody active).
`reconcile_native_idle_device_if_preferred` then does `transfer(None)` +
`activate()` because my saved device is the native one. The limit of 2
attempts doesn't help, because every rebuild after the handoff is a new
player instance and that resets the attempts.

- remember the handoff on `App` (`native_handed_off`, private, set on
`RebuildIdle`)
- while it's set the idle poll leaves the app state alone (no transfer,
no `mark_native_streaming_device_available`)
- cleared when the poll sees spotatui as the active device again, it's
picked in the device list, or playback is started in spotatui
- the reclaim now logs at info, the skip at debug (before there was no
log line at all, that's why it was hard to find)

## 2. Play in spotatui after a handoff

With part 1, play in spotatui did nothing after a handoff, because the
rebuilt device has no track. So a bare resume (Space) while handed off
now works like the official client:

- if another device still holds the playback (e.g. the phone, paused,
app open), it goes the normal Connect way and resumes there, like Enter
- if no device holds it anymore (phone app closed, Spotify answers 204),
it transfers the last playback over (before `activate()`, Spirc ignores
a transfer after that) and plays it once it's loaded, with a status
message
- only one transfer per handoff; if it couldn't be sent it stays
available, otherwise a second press takes the normal start path
- the pending play is cancelled by any pause (also on the Connect route)
and by the first `Playing`, so a pause from the phone sticks
- Space while the pulled-back song already plays pauses it, also before
Spotify confirms spotatui as the active device

Startup and normal reconnects behave like before.

# Testing

```
$ cargo fmt --all -- --check
(no diff)
$ cargo clippy --locked --no-default-features --features telemetry,tui -- -D warnings
    Finished ...
$ cargo test --locked --no-default-features --features telemetry,tui
test result: ok. 1434 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
$ cargo clippy --locked -- -D warnings
    Finished ...
$ cargo test --locked
test result: ok. 1840 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
```

The `get_artist_recovers_from_related_artists_403/404` tests fail for me
now and then in the full run ("test timed out"). Same on plain `main`, I
think it's the shared API pacing in the tests.

Also tested it for real with a release build (`--debug`), NixOS +
iPhone/CarPlay:
- switched from spotatui to the phone: playback stays on the phone
(before it came back after 10-25s, checked again with 0.42.0)
- paused on the phone with the app open, then Space in spotatui: resumes
on the phone, like Enter
- paused on the phone and closed the app (Spotify then reports no
device): Space in spotatui pulls the last song over and plays it
- after that pull-back, paused from the phone right away: it stays
paused; Space again plays normally, no second transfer
- Space twice in a row right after the handoff: the second press takes
the normal start path and it plays
- Space while the pulled-back song plays, before Spotify confirms
spotatui: it pauses
- picked spotatui again on the phone: works normally
- on startup it still takes the device like before (`idle playback poll:
transferring playback to the native device`)
- compared with the Spotify web player: playing on the phone stays
there, a paused phone (app open, also after 11 minutes) resumes there, a
gone phone gets the last song pulled over, a pause from the phone
sticks. spotatui behaves the same in all of these

# Additional notes

This is my first PR here and I'm not that familiar with Rust, so I had
some help from AI (Claude) tracking down the cause. I read through the
diff and tested it as described above, but please have a close look.

About the Codecov report: most of the missing lines are the native
player paths (librespot events, transfer, play), which the tests can't
run without a real `StreamingPlayer`. The decisions are pure functions
with tests, and the poll part (paused phone, then 204) has a test
through `get_current_playback` with a stub server, like the one in #707.

Related to #676 but doesn't fix it (that one is in the librespot fork).
After such a stop, play in spotatui now picks the last playback up again
though.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* After playback is handed off to a phone, CarPlay, or another Spotify
device, spotatui no longer automatically takes playback back during
polling.
* Playback stays on the receiving device until you select Play in
spotatui. If Spotify reports that another device still holds playback,
playback resumes there; otherwise, it resumes on spotatui.
* Pausing during a handoff cancels a pending resume, preventing
unintended playback.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: LargeModGames <[email protected]>
Co-authored-by: LargeModGames <[email protected]>
LargeModGames added a commit that referenced this pull request Oct 11, 2026
# Summary

Version bump and changelog for v0.44.0. No application code changes.

- `Cargo.toml` and `Cargo.lock` go to 0.44.0, and `SECURITY.md` names
0.44 as the supported version.
- `CHANGELOG.md`: `## [Unreleased]` is now `## [v0.44.0] 2026-10-12`. I
checked every PR merged since v0.43.0 against it and added 24 entries
that were missing, for #524, #569, #570, #574, #593, #618, #623, #624,
#651, #652, #656, #675, #684, #700, #701, #706, #707, #709, #718, #719,
#722, #730, #741 and #742.
- Five older entries blamed the Web API, Development Mode or the token
refresh, which #752 removed. They now describe what a v0.44 user sees.
The #752 entry also says that related artists are empty for now.
- The agent plugin goes to 0.2.0 (both manifests and the marketplace
entry), because its skill now lists the ten new MCP tools.
- README and `docs/roadmap.md`: rspotify is only models and ids now,
`--debug` logs every Spotify request, recommendations work again, and
related artists come back empty.
- The `spotatui.wiki` submodule moves to the commit that replaces the
client-id setup with the pairing login.

# Testing

- `cargo update -p spotatui --offline`, then `cargo metadata --locked`:
ok
- `cargo check --locked`: ok (`Checking spotatui v0.44.0`)

# Additional notes

This is the first release without a client id. Every Spotify user logs
in once more with the pairing code, and Spotify in spotatui needs
Premium.

---
<sub>💬 Questions or want to chat with other contributors? Join the
[spotatui Discord](https://spotatui.com/discord).</sub>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Search and sort playlists using loaded tracks, play playlists
randomly, and browse artist albums across pages.
* Spotify sessions now support HTTP proxies; listening parties stay
connected with keep-alives.
* **Improvements**
* Playback handoffs, polling, and slow Spotify operations have been
adjusted for smoother playback.
* Skipped downloads can be canceled, and AI DJ/MCP playback can continue
when off-screen.
* **Bug Fixes**
* Fixed issues with theme color startup, key handling, focus navigation,
cursor placement, playlist sorting, and Qobuz retries.
* **Documentation**
  * Updated installation, keybinding, and Spotify guidance.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Pause" Startup Behavior Throws Error On App Start

1 participant