Skip to content

audio: use versioned Spotify storage resolution - #1738

Draft
dereksix wants to merge 2 commits into
librespot-org:devfrom
dereksix:agent/spotify-storage-resolve-v2
Draft

dereksix wants to merge 2 commits into
librespot-org:devfrom
dereksix:agent/spotify-storage-resolve-v2

Conversation

@dereksix

Copy link
Copy Markdown

What changed

  • Thread the selected audio format from the player through AudioFile and CdnUrl into SpClient.
  • Resolve audio through Spotify's versioned storage-resolve/v2/files/audio/interactive/{format}/{file_id} route first.
  • Retain the legacy interactive route as an automatic fallback for older clusters and accounts.
  • Add a unit test that locks the route order and format component.

Why

The current signed Spotify desktop client uses the versioned storage route and includes the selected audio-format identifier. Librespot still called the older unversioned route without a format. That route remains available in some environments, so removing it would create avoidable compatibility risk; this change prefers the current contract while preserving the known fallback.

Impact

Successful legacy behavior is unchanged when the v2 route is unavailable. The requested format now stays attached to storage resolution instead of being known only by the decoder/player layer.

Validation

  • cargo fmt --all -- --check
  • cargo test -p librespot-core -p librespot-metadata -p librespot-audio -p librespot-playback
  • cargo clippy -p librespot-core -p librespot-metadata -p librespot-audio -p librespot-playback --all-targets -- -D warnings
  • Production fork PCM canary and attended jukebox soak: fresh Spotify PCM, six of six handoffs completed, and zero measured dead air.

@kingosticks

kingosticks commented Aug 14, 2026 via email

Copy link
Copy Markdown
Member

@dereksix

Copy link
Copy Markdown
Author

Yes, it was prompted by a real production problem, but I ran a controlled A/B before replying and the accurate answer is that I cannot attribute the fix to this change alone.

The original symptom was intermittent Spotify starts where Connect reported playback but librespot produced zero PCM, with HTTP 400 and audio-key errors in the logs. While comparing current desktop-client traffic, I found the versioned storage route and format component used here.

For the A/B I built two binaries from the same production commit with the same session/local-control reliability changes. The only source differences were the five files in this PR: one build used v2-first plus legacy fallback, and the other used only the legacy unversioned route.

The first v2 arm completed 20/20 cold non-local tracks with fresh, continuing PCM and zero retries. The following legacy arm completed 12/20, then Spotify's audio-key service began returning error audio key 0 2. Every subsequent v2 and legacy arm failed with the same audio-key error, including an ABBA rerun with identical 2.1-second key-request pacing. No route-specific storage-resolve, CDN, or HTTP 400 error appeared in either arm.

So the A/B was inconclusive for storage resolution and showed that the later failures were account/session/time-dependent audio-key failures, not a v2-vs-legacy difference. I have also observed v2 return 404 once and the legacy fallback succeed, which validates retaining the fallback.

In short: this change corrects protocol drift I observed while investigating a real failure, and the patched build has been stable in normal use, but I do not have evidence that the storage route itself fixed the production issue. I'm happy to reframe or close the PR if a protocol-alignment change without a deterministic regression is not useful, or add route-level instrumentation if you would like a more isolated test.

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.

2 participants