[GH-ISSUE #653] [Issue]: Spotify DJ agent disconnects after saving the agent following the paste-fallback OAuth flow #307

Closed
opened 2026-10-20 17:27:29 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @LightD31 on GitHub (May 10, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/653

Summary

Saving the Spotify DJ agent in the agent editor wipes its OAuth tokens off disk, so the agent appears disconnected on the next /api/spotify/status read. Most visibly affects users who connected via the paste-fallback flow and then click Save (or Save & close from the unsaved-changes banner).

Expected behavior

After connecting the Spotify DJ agent (popup or paste fallback), saving the editor — with or without other edits — should preserve the connection. The connection indicator should keep showing Connected to Spotify both immediately and after closing/reopening the editor.

Actual behavior

After connecting via the paste fallback and then saving the agent, the next status read returns disconnected and the editor shows the Connect Spotify Account button again. The user has to reconnect each time they save the agent. The popup path is technically vulnerable to the same wipe but is much less likely to trip in normal use because the popup auto-closes and users typically don't make further edits.

Root cause (for context): handleSave in 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 — so token fields the form doesn't know about (spotifyAccessToken, spotifyRefreshToken, spotifyExpiresAt, spotifyScope) are dropped. The connect-time save in the same component already spreads existing settings; the main handleSave did not.

Steps to reproduce

  1. Open Agents → Spotify DJ → enter a Spotify Client ID.
  2. Click Connect Spotify Account. On a non-loopback host the popup will fail to load; expand Browser couldn't reach the callback? and complete connection by pasting the redirected URL.
  3. Status panel shows Connected to Spotify.
  4. Make any unrelated edit in the agent editor (e.g. tweak the prompt) and click Save — or close the editor and pick Save & close in the unsaved-changes banner.
  5. Re-open the editor (or call /api/spotify/status) — agent reports disconnected.

Environment

  • Marinara Engine version: 1.5.9
  • Install type: source (pnpm workspace, local dev)
  • OS + version: Linux (Fedora 44, kernel 7.0.4)
  • Browser or app shell: any modern browser running the Vite client

Logs, screenshots, or video

No server-side error is logged — the wipe is silent because the editor's PATCH is a valid update with a settings object that simply omits the token fields. The disappearance is visible only by re-reading /api/spotify/status.

Additional context

Fix in flight: PR #652 (draft) — preserves the four token fields in handleSave and invalidates the agents React Query cache after the three out-of-band Spotify mutations the editor performs directly (exchange, popup-poll connected branch, disconnect). Server semantics (agents.storage.update wholesale-replace) intentionally left untouched to keep the patch focused.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @LightD31 on GitHub (May 10, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/653 ## Summary Saving the Spotify DJ agent in the agent editor wipes its OAuth tokens off disk, so the agent appears disconnected on the next `/api/spotify/status` read. Most visibly affects users who connected via the paste-fallback flow and then click *Save* (or *Save & close* from the unsaved-changes banner). ## Expected behavior After connecting the Spotify DJ agent (popup or paste fallback), saving the editor — with or without other edits — should preserve the connection. The connection indicator should keep showing *Connected to Spotify* both immediately and after closing/reopening the editor. ## Actual behavior After connecting via the paste fallback and then saving the agent, the next status read returns disconnected and the editor shows the *Connect Spotify Account* button again. The user has to reconnect each time they save the agent. The popup path is technically vulnerable to the same wipe but is much less likely to trip in normal use because the popup auto-closes and users typically don't make further edits. Root cause (for context): `handleSave` in `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 — so token fields the form doesn't know about (`spotifyAccessToken`, `spotifyRefreshToken`, `spotifyExpiresAt`, `spotifyScope`) are dropped. The connect-time save in the same component already spreads existing settings; the main `handleSave` did not. ## Steps to reproduce 1. Open Agents → Spotify DJ → enter a Spotify Client ID. 2. Click *Connect Spotify Account*. On a non-loopback host the popup will fail to load; expand *Browser couldn't reach the callback?* and complete connection by pasting the redirected URL. 3. Status panel shows *Connected to Spotify*. 4. Make any unrelated edit in the agent editor (e.g. tweak the prompt) and click *Save* — or close the editor and pick *Save & close* in the unsaved-changes banner. 5. Re-open the editor (or call `/api/spotify/status`) — agent reports disconnected. ## Environment - Marinara Engine version: 1.5.9 - Install type: source (pnpm workspace, local dev) - OS + version: Linux (Fedora 44, kernel 7.0.4) - Browser or app shell: any modern browser running the Vite client ## Logs, screenshots, or video No server-side error is logged — the wipe is silent because the editor's PATCH is a valid update with a settings object that simply omits the token fields. The disappearance is visible only by re-reading `/api/spotify/status`. ## Additional context Fix in flight: PR #652 (draft) — preserves the four token fields in `handleSave` and invalidates the `agents` React Query cache after the three out-of-band Spotify mutations the editor performs directly (`exchange`, popup-poll *connected* branch, `disconnect`). Server semantics (`agents.storage.update` wholesale-replace) intentionally left untouched to keep the patch focused. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
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#307
No description provided.