Fixes#5188
This commit resolves a race condition where user messages would sometimes
or always disappear after AI file edits, depending on whether the edit
succeeded or failed.
Root Cause:
The webview message handler was not properly awaiting the handleWebviewAskResponse
call, creating a race condition where subsequent user messages could be lost
if the AI was still processing or in an unstable state.
Solution:
1. Fixed webviewMessageHandler.ts to properly await handleWebviewAskResponse
and added error handling to prevent message loss even during failures
2. Enhanced Task.ts to immediately save user feedback messages to chat history
for messageResponse types, ensuring persistence regardless of timing
Changes:
- src/core/webview/webviewMessageHandler.ts: Added await and try-catch for askResponse handling
- src/core/task/Task.ts: Enhanced handleWebviewAskResponse to immediately save user feedback
- src/core/webview/__tests__/message-race-condition.test.ts: Added comprehensive test coverage
The fix ensures:
- Proper async handling prevents race conditions
- User messages are immediately persisted to chat history
- Graceful error handling prevents message loss during failures
- Both success and failure scenarios are properly handled