Skip to content

Fix concurrent Cursor/Droid send race before SDK dispatch#426

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-correctness-bugs-b2c4
Draft

Fix concurrent Cursor/Droid send race before SDK dispatch#426
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-correctness-bugs-b2c4

Conversation

@cursor
Copy link
Copy Markdown
Contributor

@cursor cursor Bot commented May 30, 2026

Bug and impact

Two overlapping chat.send calls on the same Cursor or Droid session could both pass prepareSendMessage while session.status was still idle, then both reach sendPrompt on 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

prepareSendMessage rejected active sessions but only set session.status = "active" later in sendMessage, after prepareSendMessage returned. There was a TOCTOU window between the idle check and runCursorTurn setting runtime.busy.

Fix

Mark Cursor/Droid sessions active at the end of prepareSendMessage (when allowActiveSession is 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)

Open in Web View Automation 

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>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
ade Ignored Ignored May 30, 2026 4:08am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant