Fix race condition blocking multi-turn chat conversations#13
Draft
Fix race condition blocking multi-turn chat conversations#13
Conversation
Copilot
AI
changed the title
[WIP] Fix dashboard chat to support multi-turn conversations
Fix race condition blocking multi-turn chat conversations
Jan 29, 2026
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
The bug was in `sendMessage` function which checked React state to see if a thread was streaming, but React state could be stale after a message completed. This caused rapid follow-up messages to be blocked. Fixed by: - Query threadStore.getById() directly instead of using threads from React state - Remove threads from useCallback dependency array (no longer needed) Co-authored-by: chrisreddington <791642+chrisreddington@users.noreply.github.com>
…ponses The previous fix to check storage directly still had a race condition for multi-turn conversations. The cleanup effect that removes threads from the pending list was incorrectly triggered when a thread already had assistant messages from previous turns. Root cause: The old logic checked for ANY completed assistant message, but for multi-turn chat, the thread already has completed responses from earlier turns. When sending a follow-up, the cleanup effect would immediately remove the thread from pending (since hasCompletedResponse was true), stopping the polling before the new response arrived. Fix: Track the expected message count when starting a job: - Store Map<threadId, expectedMessageCount> instead of Set<threadId> - Only remove from pending once thread.messages.length >= expected count - This correctly handles multi-turn: after each message, we expect current count + 2 (user + assistant) Verified with Playwright: Can now send multiple follow-up messages and each receives a proper AI response.
ddfcc56 to
7963368
Compare
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
Dashboard chat accepted the first message but silently ignored follow-ups, breaking multi-turn conversations. Root cause:
sendMessagechecked React state to guard against duplicate sends, but state lagged storage updates by up to 400ms (the polling interval).Changes
Query storage directly instead of stale React state:
Removed
threadsdependency fromuseCallbacksince we no longer read from React state for the streaming check.Technical Details
The flow that caused the bug:
executeChatResponsewritesisStreaming: falseto storageisStreaming: true→ message silently droppedStorage queries bypass the stale state issue entirely while maintaining the duplicate-send protection.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.