Fix concurrent Cursor/Droid send race before SDK dispatch#426
Draft
cursor[bot] wants to merge 1 commit into
Draft
Fix concurrent Cursor/Droid send race before SDK dispatch#426cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
Reserve the chat session as active at the end of prepareSendMessage for Cursor and Droid providers so overlapping sendMessage calls cannot both pass the idle check and reach sendPrompt on the same worker. Co-authored-by: Arul Sharma <arul28@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
This was referenced May 30, 2026
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.
Bug and impact
Two overlapping
chat.sendcalls on the same Cursor or Droid session could both passprepareSendMessagewhilesession.statuswas stillidle, then both reachsendPrompton the same SDK worker. That interleaves streams, duplicates optimistic UI turns, and risks corrupting turn IDs (the failure path deliberately avoids clearing state on "already active" errors because the first turn is still live).Trigger: Double-submit from the composer, rapid IPC/automation sends, or steer + send racing before the first turn sets
runtime.busy.Root cause
prepareSendMessagerejected active sessions but only setsession.status = "active"later insendMessage, afterprepareSendMessagereturned. There was a TOCTOU window between the idle check andrunCursorTurnsettingruntime.busy.Fix
Mark Cursor/Droid sessions active at the end of
prepareSendMessage(whenallowActiveSessionis false) so the second overlapping send fails fast with "Turn is already active" before any optimistic UI or SDK dispatch.Validation
npx vitest run src/main/services/chat/agentChatService.test.ts -t "rejects overlapping Cursor sends"(passes)Other findings (not fixed here — existing draft PRs)
ALTERleak withoutcrsql_commit_alteron failure → Fix CRR alter leak and restore binding on failed remote switch #363