-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: resolve message queue race condition during LLM processing #8694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add defensive routing in webviewMessageHandler to check for pending ask - Implement active queue monitoring in Task.ask() with event listener - Add queue draining loop in recursivelyMakeClineRequests() - Add UI hardening in ChatView to prefer queuing during transitions - Add comprehensive test coverage for race condition scenarios Fixes #8536
Review SummaryI've reviewed the changes in this PR that addresses the race condition where user messages could vanish during LLM processing. The implementation is solid with a multi-layered approach:
Issues Found
Overall AssessmentThe PR effectively addresses the race condition issue with a well-thought-out multi-layered approach. All identified issues have been resolved and the implementation is ready to merge. |
Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>
@roomote This PR fixes the issue but also creates a new isue where the chat message box gets cleared when a message comes off the stack so if I am typing while the queue is going then my message gets cleared! |
Thanks for flagging this, Hannes. Acknowledged — this regression happens because the input state is being reset when a queued message is consumed and the chat view re-renders. I will push a follow-up fix on this branch to preserve the user’s draft while the queue drains. Plan:
Working on the patch now on fix/message-queue-race-condition. |
Follow up fix pushed to preserve the chat input while the queue drains. What changed:
Implementation:
Verification:
Please try typing while messages are draining from the queue and confirm the input no longer clears. |
Summary
This PR addresses issue #8536 by fixing a race condition where user messages could vanish when sent during the tiny window between Task.ask() queue check and UI state transition.
Problem
Messages sent in the brief gap between:
Would be routed as askResponse to a non-existent ask, causing them to disappear silently.
Solution
Implemented a multi-layered fix as suggested by @hannesrudolph:
1. Defensive Routing (webviewMessageHandler.ts)
taskAsk
exists before processingmessageResponse
2. Active Queue Monitoring (Task.ts)
ask()
to monitor queue during blocking3. Queue Draining (Task.ts)
drainQueuedMessages()
after each API turn inrecursivelyMakeClineRequests()
4. UI Hardening (ChatView.tsx)
shouldQueue
logic to prefer queuing during transitionsclineAskRef.current
for stable referenceTesting
webviewMessageHandler.race-condition.spec.ts
Impact
Fixes #8536
Important
Fixes message queue race condition by implementing defensive routing, active queue monitoring, and UI hardening, ensuring messages are not lost during state transitions.
Task.ask()
and UI state transition are not lost.webviewMessageHandler.ts
to queue messages if notaskAsk
is pending.Task.ts
to consume messages immediately during blocking.shouldQueue
logic inChatView.tsx
to prefer queuing during transitions.webviewMessageHandler.race-condition.spec.ts
for comprehensive testing of race condition scenarios.ChatView.tsx
to maintain stable references for input and images during message queuing.This description was created by
for 595beaa. You can customize this summary. It will automatically update as commits are pushed.