Fix order of message events #4037
Closed
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.
Related GitHub Issue
Closes: #4034
Description
Both
Task.addToClineMessagesandTask.updateClineMessageare async functions.However, when
addToClineMessagesis called, it is awaited,and when
updateClineMessageis called, it is not awaited.This can result in reordering the execution of these functions,
and thus reordering the
this.emit("message", ...)calls (and also messages sent to webview probably).The solution is to await on
updateClineMessage. It should not introduce much performance penalty, as it only sends message to webview and emits an event (addToClineMessagesdoes much more and it is awaited).Test Procedure
Subscribe to
messageevent, run a task and watch the order of message events.The procedure must be run multiple times — not always the events are emitted in wrong order.
However, probably as the change is very small and obvious, it does not need additional testing.
Type of Change
srcor test files.Pre-Submission Checklist
npm run lint)¹.console.log) has been removed.npm test).mainbranch.npm run changesetif this PR includes user-facing changes or dependency updates.²¹ Getting
Invalid option '--ext' - perhaps you meant '-c'?from eslint.² Getting
Missing script: changesetScreenshots / Videos
Documentation Updates
Does this PR necessitate updates to user-facing documentation?
Additional Notes
Get in Touch
Discord handle: wkordalski
Important
Fixes message event order by awaiting
updateClineMessage()inTask.tsto ensure correct event emission sequence.updateClineMessage()inTask.tsto ensure correct order ofmessageevents.ask(),say(), and other methods whereupdateClineMessage()is called.updateClineMessage()now awaited inask(),say(), and 2 other places inTask.ts.messageevents are emitted in wrong order #4034 related to message event order.This description was created by
for ede7cc7. You can customize this summary. It will automatically update as commits are pushed.