Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 29, 2026

Problem

Dashboard chat accepted the first message but silently ignored follow-ups, breaking multi-turn conversations. Root cause: sendMessage checked 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:

// Before: Race condition when messages sent < 400ms after completion
const threadFromStorage = threads.find(t => t.id === targetThreadId);

// After: Always check source of truth
const threadFromStorage = await threadStore.getById(targetThreadId);

Removed threads dependency from useCallback since we no longer read from React state for the streaming check.

Technical Details

The flow that caused the bug:

  1. Message completes → executeChatResponse writes isStreaming: false to storage
  2. User sends follow-up before polling refreshes React state
  3. Check sees stale isStreaming: true → message silently dropped

Storage queries bypass the stale state issue entirely while maintaining the duplicate-send protection.

Original prompt

This section details on the original issue you should resolve

<issue_title>Bug: Dashboard chat only works for single turn (follow-ups don't trigger AI)</issue_title>
<issue_description>## Description
During livestream testing, discovered that the chat experience on the dashboard only works for the initial message. Follow-up messages don't trigger the AI to respond.

Steps to Reproduce

  1. Navigate to dashboard
  2. Send initial chat message
  3. AI responds successfully
  4. Send follow-up message
  5. AI does not respond

Expected Behavior

Chat should support multi-turn conversations where follow-up messages trigger AI responses.

Actual Behavior

Only the first message gets a response. Subsequent messages are ignored.

Impact

  • Users cannot have ongoing conversations
  • Limits chat usefulness to single Q&A exchanges</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

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
Copilot AI requested a review from chrisreddington January 29, 2026 13:35
@github-actions
Copy link

github-actions bot commented Jan 29, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copilot AI and others added 3 commits January 29, 2026 14:49
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.
@chrisreddington chrisreddington force-pushed the copilot/fix-dashboard-chat-multi-turn branch from ddfcc56 to 7963368 Compare January 29, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Dashboard chat only works for single turn (follow-ups don't trigger AI)

2 participants