fix: move typingDiv guard to sendMessage() to prevent chatHistory desync (#6172)#6184
Open
piyushdotcomm wants to merge 1 commit intosugarlabs:masterfrom
Open
Conversation
…istory (sugarlabs#6172) When a user rapidly sends messages while the bot is processing, sendMessage() unconditionally pushed to chatHistory and the UI, but botReplyDiv() silently returned due to the typingDiv guard. This caused chatHistory to contain user messages that were never sent to the backend, permanently desyncing the conversation. Fix: Move the typingDiv guard into sendMessage() so the entire send is blocked before any state mutation. Remove the redundant guard from botReplyDiv(). Closes sugarlabs#6172
Contributor
|
❌ Some Jest tests failed. Please check the logs and fix the issues before merging. Failed Tests: |
Contributor
Author
|
Hey @walterbender, this fixes the concurrency bug in #6172 — just moved the guard check earlier in sendMessage() so rapid sends don't mess up chatHistory. Happy to make changes if needed! |
parthdagia05
reviewed
Mar 9, 2026
Contributor
parthdagia05
left a comment
There was a problem hiding this comment.
One small thought for the future might be disabling the input or queuing messages while the bot is replying, but that would be more of a UX improvement rather than part of this bug fix.
Contributor
Author
|
Good idea! Could be a nice follow-up. This PR just tackles the desync for now though |
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.
PR Category
Description
Fixes #6172
When a user sends multiple messages quickly (clicking Send or pressing Enter while the bot is still replying), the second message gets added to
chatHistoryand shows up in the UI, but botReplyDiv() silently drops it because of theif (this.typingDiv) returnguard. This meanschatHistorygoes out of sync with what the LLM actually received.Changes
if (this.typingDiv) returnguard at the top of sendMessage() so the whole function exits before pushing tochatHistoryor updating the UIThis is safe because sendMessage() is the only caller that uses the default
user_query = truepath. The other callers (startChatSession, updateProjectCode, getAnalysis) all passuser_query = false.