mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #2400] [MERGED] Serialize Spotify token refresh per agent to prevent overlapping grants #5582
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#5582
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2400
Author: @Romuromylus
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Romuromylus
Base:
refactor← Head:fix/spotify-token-refresh-lock📝 Commits (2)
9bb978cSerialize Spotify token refresh per agent to prevent overlapping grantsdb23028Serialize the explicit Spotify refresh route on the per-agent lock📊 Changes
1 file changed (+74 additions, -18 deletions)
View changed files
📝
src-tauri/src/commands/storage/integrations/spotify.rs(+74 -18)📄 Description
Linked issue
Closes #2318
Why this change
resolve_credentialsdid an unsynchronized proactive token refresh. Two concurrent same-agent requests (the Spotify mini-player's player + devices queries, both on a 5s refetch) could each POSTgrant_type=refresh_token. Spotify rotates the refresh token, so the second grant used an already-invalidated token, and last-writer-winssave_spotify_tokenspersisted the bad token — permanently breaking the connection until the user re-authorized.What changed
src-tauri/src/commands/storage/integrations/spotify.rs: refresh is now serialized per agent via a process-globalOnceLock<Mutex<HashMap<agent_id, Arc<tokio::sync::Mutex<()>>>>>(mirrors the existing per-agent track-index cache). After acquiring the per-agent async lock,resolve_credentialsre-reads the stored token (double-checked locking) and skips the network grant entirely if another task already refreshed while it waited; otherwise it runs the original refresh path unchanged.Refactor impact
Primary owner: Rust storage (integrations)
Impact areas reviewed:
src-tauri/src/commands/storage/integrations/spotify.rs(resolve_credentials, newspotify_refresh_lock)Boundary notes:
SpotifyCredentialsshape unchanged. Poisoned-mutex recovered viaPoisonError::into_inner(matches the track-index cache).tokiosync feature already enabled.Pressure points touched:
Validation
pnpm checkpasses before PR push/handoffManual verification notes
cargo test --manifest-path src-tauri/Cargo.toml -p marinara-engine spotify— 10 passed (existing + local-only guard tests: per-agent lock returns the same handle and serializes same-agent / stays parallel cross-agent).cargo clippy --manifest-path src-tauri/Cargo.toml --workspace --all-targets -- -D warnings— clean.Feature Discoverability
src/features/shell/discovery/Reason:
Docs and release impact
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.