[GH-ISSUE #3001] [Issue]: Agent store reset() leaks Custom Music DJ playback state across chat switches (localMusicPlay/localMusicVolume never cleared) #1575

Closed
opened 2026-10-21 05:39:31 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3001

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
The agent store's reset() action (the chat-switch teardown) clears the YouTube DJ playback intent but omits the analogous Custom (local file) Music DJ fields. So the Custom Music DJ "play" intent from the previous chat survives a chat switch. When the local music player remounts (e.g. on a viewport toggle or the 767px breakpoint crossing), its nonce-based effect sees the stale intent and auto-starts playback of the PREVIOUS chat's track inside the new chat. YouTube is protected because reset() nulls its play intent; local music is not.

How to reproduce (try it yourself)

  1. Configure Music DJ with the Custom (local file) provider and enable the player (musicPlayerSource='custom').
  2. In chat A, let the Custom Music DJ pick a track (localMusicPlay.nonce becomes >=1, track from chat A plays).
  3. Switch to chat B (different chat id) — reset() is called; youtube fields are cleared but localMusicPlay/Volume are NOT.
  4. Cause the LocalMusicPlayer/LocalMusicMobileWidget to remount (e.g. on mobile/narrow viewport toggle the Custom player off and on, or cross the 767px breakpoint).

You'll see: on remount the effect auto-plays chat A's track inside chat B.
Expected: a chat switch wipes the previous chat's Custom DJ track, exactly as it does for YouTube.

Where it is
packages/client/src/stores/agent.store.ts:281-300 (reset — missing localMusicPlay/localMusicVolume; fields declared at 127-129). Chat-switch teardown: packages/client/src/stores/chat.store.ts:295-296. Stale-state auto-play: packages/client/src/components/chat/LocalMusicPlayer.tsx:141-164; remount path at :471-478. YouTube guard contrast: YouTubePlayer.tsx:219.

What's happening
reset() was written by enumerating fields to clear and the local-music pair was simply omitted, unlike its YouTube twin. The dedicated clearLocalMusic() action exists but is only invoked from the player's manual close handler, never on chat switch, so nothing compensates.

Suggested fix
Add the two fields to the reset() set() object, immediately after the youtube lines (around 296-297):

  youtubePlay: null,
  youtubeVolume: null,
  localMusicPlay: null,
  localMusicVolume: null,

No regression: both reset() callers are teardown contexts where clearing is intended; nulling localMusicPlay is the protective change (the play effect early-returns on !localMusicPlay, matching YouTube's guard); nulling localMusicVolume is a no-op for the volume effect and does NOT touch the persisted playerVolume, so the user's chosen volume is unaffected. The existing clearLocalMusic() already nulls exactly these two fields, confirming null is the canonical cleared state.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3001 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** The agent store's `reset()` action (the chat-switch teardown) clears the YouTube DJ playback intent but omits the analogous Custom (local file) Music DJ fields. So the Custom Music DJ "play" intent from the previous chat survives a chat switch. When the local music player remounts (e.g. on a viewport toggle or the 767px breakpoint crossing), its nonce-based effect sees the stale intent and auto-starts playback of the PREVIOUS chat's track inside the new chat. YouTube is protected because reset() nulls its play intent; local music is not. **How to reproduce (try it yourself)** 1. Configure Music DJ with the Custom (local file) provider and enable the player (musicPlayerSource='custom'). 2. In chat A, let the Custom Music DJ pick a track (localMusicPlay.nonce becomes >=1, track from chat A plays). 3. Switch to chat B (different chat id) — reset() is called; youtube fields are cleared but localMusicPlay/Volume are NOT. 4. Cause the LocalMusicPlayer/LocalMusicMobileWidget to remount (e.g. on mobile/narrow viewport toggle the Custom player off and on, or cross the 767px breakpoint). You'll see: on remount the effect auto-plays chat A's track inside chat B. Expected: a chat switch wipes the previous chat's Custom DJ track, exactly as it does for YouTube. **Where it is** `packages/client/src/stores/agent.store.ts:281-300` (`reset` — missing localMusicPlay/localMusicVolume; fields declared at 127-129). Chat-switch teardown: `packages/client/src/stores/chat.store.ts:295-296`. Stale-state auto-play: `packages/client/src/components/chat/LocalMusicPlayer.tsx:141-164`; remount path at `:471-478`. YouTube guard contrast: `YouTubePlayer.tsx:219`. **What's happening** `reset()` was written by enumerating fields to clear and the local-music pair was simply omitted, unlike its YouTube twin. The dedicated `clearLocalMusic()` action exists but is only invoked from the player's manual close handler, never on chat switch, so nothing compensates. **Suggested fix** Add the two fields to the `reset()` set() object, immediately after the youtube lines (around 296-297): ```ts youtubePlay: null, youtubeVolume: null, localMusicPlay: null, localMusicVolume: null, ``` No regression: both reset() callers are teardown contexts where clearing is intended; nulling localMusicPlay is the protective change (the play effect early-returns on `!localMusicPlay`, matching YouTube's guard); nulling localMusicVolume is a no-op for the volume effect and does NOT touch the persisted playerVolume, so the user's chosen volume is unaffected. The existing `clearLocalMusic()` already nulls exactly these two fields, confirming null is the canonical cleared state. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in merged staging PR #3004.

<!-- gh-comment-id:4832284030 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in merged staging PR #3004.
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#1575
No description provided.