fix(assistant): stop cross-tab message sync from looping regenerations - #1441
Open
francoisauclair911 wants to merge 1 commit into
Open
francoisauclair911 wants to merge 1 commit into
francoisauclair911 wants to merge 1 commit into
Conversation
`useAssistant` persists messages with `useLocalStorage`, which also syncs them from other tabs via `storage` events. `AssistantPanel` regenerates whenever synced messages end on a user turn, so with two tabs open each tab restarts the other's stream and answers pile up in the history. Keep persistence across reloads but stop listening to other tabs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@francoisauclair911 is attempting to deploy a commit to the NuxtLabs Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With the assistant open in two or more tabs of the same site, sending one question produces a pile of duplicated answers. The panel keeps restarting the tool calls and streaming, and the stored history fills with repeated
assistantmessages.Cause:
useAssistantpersists messages withuseLocalStorage('assistant-messages', []). By default this also listens tostorageevents, so every tab picks up the other tabs' writes.AssistantPanelwatches those messages and callsregenerate()whenever the last one is ausermessage and the panel isn't streaming.storageevent, sees a trailing user turn and sends its own request.onFinishwrites overwrite the other tab's messages, and the tabs keep triggering regenerations in each other.Reproduction
Tested on
main(dc05aff), usingplayground/withassistant.enabled: true. The route was replaced with a mockcreateUIMessageStreamthat streams text for about 5s, so no LLM or MCP is involved. Headless Chromium, one browser context, one question sent from tab 0, history read 25s later:POST /api/assistantassistant-messagesrolesuser, assistantuser+ 27 ×assistantuser, assistantAfter the fix, a reload still restores the conversation from localStorage.
Fix
Pass
listenToStorageChanges: falseto the messagesuseLocalStorage. Messages still persist across reloads, but each tab keeps its own conversation. Within a tab,useAssistantis a shared composable, soopen(initialMessage)still reaches the panel without storage events.Trade-off: a conversation no longer shows up live in other open tabs. It still loads on the next page load, as it did before. Live cross-tab mirroring would need the panel to tell a local user turn from one synced in from another tab. That seems out of scope for this bug fix, but I'm happy to explore it if you'd rather keep live sync.
eslintandnuxt typecheck layerpass.