Skip to content

fix(streaming): preserve external device handoffs - #438

Merged
LargeModGames merged 7 commits into
mainfrom
fix/spotatui-hijack-playback-device
Aug 12, 2026
Merged

LargeModGames merged 7 commits into
mainfrom
fix/spotatui-hijack-playback-device

Conversation

@shilicioo

@shilicioo shilicioo commented Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #437

When playback moves from spotatui to another Spotify Connect device, spotatui now rebuilds an idle backend without reclaiming playback. Unexpected connection failures still restore the session, and an explicit Play action still selects spotatui normally.

Pins librespot to the merged disconnect-reason change: LargeModGames/spotatui-librespot@f775c39

Testing

  • cargo fmt --all
  • cargo clippy --locked -- -D warnings
  • cargo clippy --no-default-features --features telemetry -- -D warnings
  • cargo test — 842 passed
  • cargo test --no-default-features --features telemetry — 572 passed
  • Manual Spotify Connect handoff and unstable-network recovery testing

Summary by CodeRabbit

  • Bug Fixes
    • Improved streaming recovery after Spotify Connect handoffs.
    • Prevented playback from being incorrectly reclaimed after transferring to another device.
    • Unexpected streaming disconnects now restore playback and queued tracks when appropriate.
    • Idle connections recover without automatically reselecting the previous device.
    • Local shutdowns remain stopped without triggering recovery.
    • Preserved external playback and cleared stale recovery state when appropriate.
    • Improved replay of published queue positions during recovery.
  • Documentation
    • Added an Unreleased changelog entry describing the updated streaming behavior.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: bee8bd7c-7e5c-4ea9-b788-d60cce6ef1fb

📥 Commits

Reviewing files that changed from the base of the PR and between d836d29 and b477b3e.

📒 Files selected for processing (2)
  • src/infra/network/mod.rs
  • src/infra/queue/dispatch.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/infra/network/mod.rs

📝 Walkthrough

Walkthrough

Native streaming recovery distinguishes local stops, Spotify Connect handoffs, and unexpected disconnects. Handoffs rebuild an idle backend without reclaiming playback. Unexpected disconnects restore playback, while queue replay and device selection remain restoration-aware.

Changes

Native streaming recovery

Layer / File(s) Summary
Recovery reason and request contracts
src/infra/player/events.rs, src/infra/player/streaming.rs, src/infra/network/mod.rs, src/infra/network/playback.rs, src/runtime.rs
Disconnect reasons classify recovery behavior. StreamingRecoveryRequest records restore_playback. Auto-selection events and methods carry the external-playback yield flag.
Reason-specific disconnect handling
src/infra/player/events.rs, src/core/app.rs, src/infra/network/playback.rs
Local stops do not enqueue recovery. External handoffs rebuild an idle backend and clear non-restoring state. Unexpected disconnects request playback restoration. Stale restore generations are ignored.
External playback ownership checks
src/infra/network/playback.rs
Recovery detects active playback on another device. When yielding applies, native activation and transfer are skipped and stale native recovery state is cleared.
Queue replay wiring and release support
src/infra/network/mod.rs, src/infra/queue/dispatch.rs, src/infra/network/playback.rs, CHANGELOG.md, Cargo.toml, flake.nix
Streaming routes restoration-aware queue replay events. Tests cover ownership and recovery behavior. The changelog and librespot build inputs reflect the updated integration.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant NativeSession
  participant events_rs
  participant PlaybackNetwork
  participant SpotifyConnect
  NativeSession->>events_rs: emit disconnect reason
  events_rs->>PlaybackNetwork: apply restoration decision
  PlaybackNetwork->>SpotifyConnect: inspect active device
  SpotifyConnect-->>PlaybackNetwork: report external playback
  PlaybackNetwork-->>events_rs: skip native transfer when another device is active
Loading

Possibly related PRs

🚥 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 required fix prefix, identifies streaming, and clearly describes preserving external device handoffs.
Linked Issues check ✅ Passed The changes implement passive reconnects for external handoffs and preserve recovery for unexpected shutdowns, satisfying issue #437.
Out of Scope Changes check ✅ Passed The changes support issue #437, including recovery logic, queue replay, dependency pinning, tests, and documentation.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/spotatui-hijack-playback-device
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/spotatui-hijack-playback-device

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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/infra/player/events.rs`:
- Around line 46-51: Update should_replay_published_queue_slot to require
request.reselect_device in addition to request.restore_playback and
queue_now_is_spotify, so replay occurs only after native-device confirmation.
Adjust the related test to verify that an unconfirmed restoration request does
not replay the queue slot.
🪄 Autofix

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: 3d4acc90-ab3b-40c1-bbb0-50bb83a7170a

📥 Commits

Reviewing files that changed from the base of the PR and between e474b2a and 6a9c705.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock, !Cargo.lock
📒 Files selected for processing (5)
  • CHANGELOG.md
  • Cargo.toml
  • src/core/app.rs
  • src/infra/player/events.rs
  • src/infra/player/streaming.rs

Comment thread src/infra/player/events.rs Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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/infra/network/playback.rs`:
- Around line 2294-2305: Update the state assignments at the recovery-yield
paths around the existing activation handling so app.is_streaming_active remains
false whenever external_playback_active is true. Propagate the
external_playback_active condition into both assignments currently setting the
flag at the referenced recovery branches, while preserving true only when the
native device is confirmed active.
🪄 Autofix

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: 603b81d8-dc31-416f-910a-e8792f941506

📥 Commits

Reviewing files that changed from the base of the PR and between a791406 and ae8e2f5.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • src/infra/network/mod.rs
  • src/infra/network/playback.rs
  • src/infra/player/events.rs
  • src/runtime.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • CHANGELOG.md
  • src/infra/player/events.rs

Comment thread src/infra/network/playback.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts native streaming recovery behavior so that when playback is handed off to another Spotify Connect device, spotatui rebuilds an idle streaming backend without reclaiming playback—addressing #437 and improving correctness of recovery decisions using librespot’s disconnect reason.

Changes:

  • Classify SessionDisconnected handling by SessionDisconnectReason and gate recovery actions (reselect/replay) behind explicit restore_playback intent.
  • Extend AutoSelectStreamingDevice / auto_select_streaming_device plumbing with yield_to_external_playback to avoid transferring playback away from an actively playing external device during recovery.
  • Pin librespot to the upstream disconnect-reason change, update Nix hash, and document the behavior change in the changelog.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/runtime.rs Updates startup auto-select event to pass the new yield_to_external_playback flag.
src/infra/player/streaming.rs Re-exports librespot disconnect reason alongside player events for downstream handling.
src/infra/player/events.rs Implements disconnect-reason-based recovery policy; adds restore_playback intent and request merge semantics; adds targeted unit tests.
src/infra/network/playback.rs Extends streaming device auto-select API to optionally yield to external playback during recovery; adds stale-restore guard.
src/infra/network/mod.rs Updates IoEvent::AutoSelectStreamingDevice variant signature and dispatch wiring.
src/core/app.rs Ensures recovery requests created from app-driven recovery set restore_playback: true.
flake.nix Updates librespot output hash to match the pinned revision.
CHANGELOG.md Adds Unreleased entry describing the fixed handoff/recovery behavior.
Cargo.toml Pins librespot patch dependencies to the commit containing disconnect-reason support.
Cargo.lock Updates lockfile sources to the new librespot revision.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 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/infra/network/mod.rs`:
- Around line 71-74: Update event_bypasses_spotify_auth to include
ReplayPublishedSpotifyQueueSlot, ensuring this no-op fallback bypasses Spotify
authentication when the queue router does not consume the event.

In `@src/infra/queue/dispatch.rs`:
- Around line 48-54: Add streaming-feature regression tests covering playing and
paused queue-slot replay, yielded external playback, event consumption, and
network fallback around the replay handling in replay_published_spotify_slot and
the IoEvent::ReplayPublishedSpotifyQueueSlot dispatch path. Then run cargo fmt
--all, the specified telemetry Clippy and test commands, and the full cargo run
validation.
🪄 Autofix

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: 760995e8-a683-4931-bd90-6627c388bcf2

📥 Commits

Reviewing files that changed from the base of the PR and between ae8e2f5 and d836d29.

📒 Files selected for processing (4)
  • src/infra/network/mod.rs
  • src/infra/network/playback.rs
  • src/infra/player/events.rs
  • src/infra/queue/dispatch.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/infra/player/events.rs

Comment thread src/infra/network/mod.rs Resolved
Comment thread src/infra/queue/dispatch.rs Resolved
@LargeModGames
LargeModGames merged commit 5a80b25 into main Aug 12, 2026
22 checks passed
@LargeModGames
LargeModGames deleted the fix/spotatui-hijack-playback-device branch August 12, 2026 16:59
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.

Native recovery hijacks playback from another Spotify Connect device

3 participants