[PR #652] [MERGED] Fix Spotify disconnect when saving the agent after the paste-fallback OAuth flow #4712

Closed
opened 2026-10-22 04:10:02 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/652
Author: @LightD31
Created: 5/10/2026
Status: ✅ Merged
Merged: 5/10/2026
Merged by: @Romuromylus

Base: main ← Head: fix/spotify-token-preservation


📝 Commits (3)

  • 326dd01 Ajout de la préservation des champs OAuth pour Spotify et invalidation des requêtes après les mises à jour
  • 5ad6124 Close save-vs-refetch race in Spotify connect/disconnect flows
  • 08b87c2 Merge branch 'main' into fix/spotify-token-preservation

📊 Changes

1 file changed (+44 additions, -1 deletions)

View changed files

📝 packages/client/src/components/agents/AgentEditor.tsx (+44 -1)

📄 Description

Linked issue

Closes #653

Why this change

  • Saving the Spotify DJ agent in the editor wipes its OAuth tokens off disk, so the user appears disconnected the next time /api/spotify/status is read. Most visibly affects the paste-fallback path: users have just typed a URL into a textbox and reflexively hit Save afterward, which drops spotifyAccessToken / spotifyRefreshToken / spotifyExpiresAt / spotifyScope from agent.settings. The popup path is technically vulnerable too — the auto-closing popup just makes it less likely to be triggered.
  • Root cause: handleSave in AgentEditor.tsx builds the new settings payload from form fields only, and the server's agents.storage.update replaces the settings JSON wholesale rather than merging — anything the form omits is lost.

What changed

  • handleSave now reads the latest dbConfig.settings and re-includes spotifyAccessToken, spotifyRefreshToken, spotifyExpiresAt, spotifyScope in the saved payload, so wholesale replacement on the server no longer drops them.
  • The three out-of-band Spotify mutations the editor performs directly (paste exchange, popup-poll connected branch, and disconnect) now qc.invalidateQueries({ queryKey: agentKeys.all }) so React Query's dbConfig reflects the new server state. Without that, handleSave would preserve from a stale cache and either re-resurrect tokens after disconnect or fail to preserve fresh ones after exchange.
  • No server-side changes — agents.storage.update's wholesale-replace semantics are left untouched to keep the patch focused (per CLAUDE.md).

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

To exercise:

  • Configure a Spotify DJ agent, connect via the paste-fallback flow on a non-loopback host, then make an unrelated edit (e.g. tweak the prompt) and click Save — agent should remain connected on next status read.

  • Repeat with the popup flow (loopback / 127.0.0.1) and confirm Save also preserves the connection afterwards.

  • Click Disconnect in the editor, then click Save — agent should remain disconnected (tokens must not be resurrected from a stale React Query cache).

  • After paste-fallback success, close and re-open the editor — status should still show Connected to Spotify.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Preserve existing Spotify authentication tokens and related settings when saving agent configurations.
    • Ensure the UI immediately reflects Spotify connect/disconnect actions and prevents stale token data from reappearing after disconnect.

Review Change Stack


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/652 **Author:** [@LightD31](https://github.com/LightD31) **Created:** 5/10/2026 **Status:** ✅ Merged **Merged:** 5/10/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `main` ← **Head:** `fix/spotify-token-preservation` --- ### 📝 Commits (3) - [`326dd01`](https://github.com/Pasta-Devs/Marinara-Engine/commit/326dd01564177f834888432fd932b3a4bd7f34ba) Ajout de la préservation des champs OAuth pour Spotify et invalidation des requêtes après les mises à jour - [`5ad6124`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5ad6124604928f8c93985a18126cbc92cf2116df) Close save-vs-refetch race in Spotify connect/disconnect flows - [`08b87c2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/08b87c295105d63bcce1632bb1d48cae9d108174) Merge branch 'main' into fix/spotify-token-preservation ### 📊 Changes **1 file changed** (+44 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/agents/AgentEditor.tsx` (+44 -1) </details> ### 📄 Description ## Linked issue <!-- Tracker issue filed; this PR resolves it. --> Closes #653 ## Why this change - Saving the Spotify DJ agent in the editor wipes its OAuth tokens off disk, so the user appears disconnected the next time `/api/spotify/status` is read. Most visibly affects the paste-fallback path: users have just typed a URL into a textbox and reflexively hit *Save* afterward, which drops `spotifyAccessToken` / `spotifyRefreshToken` / `spotifyExpiresAt` / `spotifyScope` from `agent.settings`. The popup path is technically vulnerable too — the auto-closing popup just makes it less likely to be triggered. - Root cause: `handleSave` in [`AgentEditor.tsx`](packages/client/src/components/agents/AgentEditor.tsx) builds the new `settings` payload from form fields only, and the server's `agents.storage.update` replaces the `settings` JSON wholesale rather than merging — anything the form omits is lost. ## What changed - `handleSave` now reads the latest `dbConfig.settings` and re-includes `spotifyAccessToken`, `spotifyRefreshToken`, `spotifyExpiresAt`, `spotifyScope` in the saved payload, so wholesale replacement on the server no longer drops them. - The three out-of-band Spotify mutations the editor performs directly (paste `exchange`, popup-poll *connected* branch, and `disconnect`) now `qc.invalidateQueries({ queryKey: agentKeys.all })` so React Query's `dbConfig` reflects the new server state. Without that, `handleSave` would preserve from a stale cache and either re-resurrect tokens after disconnect or fail to preserve fresh ones after exchange. - No server-side changes — `agents.storage.update`'s wholesale-replace semantics are left untouched to keep the patch focused (per CLAUDE.md). ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes <!-- ⚠️ AI-generated PR — the boxes above are a to-do list, not proof. Verify each item in a real browser before merging out of draft. --> To exercise: - Configure a Spotify DJ agent, connect via the paste-fallback flow on a non-loopback host, then make an unrelated edit (e.g. tweak the prompt) and click *Save* — agent should remain connected on next status read. - Repeat with the popup flow (loopback / 127.0.0.1) and confirm *Save* also preserves the connection afterwards. - Click *Disconnect* in the editor, then click *Save* — agent should remain disconnected (tokens must not be resurrected from a stale React Query cache). - After paste-fallback success, close and re-open the editor — status should still show *Connected to Spotify*. - ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) <!-- No UI surface changes — this is a state-management/persistence fix. Connection status indicator and editor layout are unchanged. --> 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Preserve existing Spotify authentication tokens and related settings when saving agent configurations. * Ensure the UI immediately reflects Spotify connect/disconnect actions and prevents stale token data from reappearing after disconnect. [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/652) <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:10:02 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4712
No description provided.