Python SDK: Client.launch_bridge fails on Windows (WinError 10038), and a failed launch leaves node.exe running

Where does the bug appear (feature/product)?

Cursor SDK

Describe the Bug

Bug 1: the sync bridge launcher can’t start on Windows

Cause

_bridge._read_discovery (lines 236–284) registers the bridge’s stderr pipe with selectors.DefaultSelector() and calls selector.select(). On Windows, DefaultSelector is SelectSelector, and select.select() only accepts sockets, so any pipe file descriptor raises WinError 10038.

The bridge itself is fine. Launched directly, cursor-sdk-bridge.cmd --workspace <dir> prints its cursor-sdk-bridge ready {...} line to stderr in about a second. The async launcher (AsyncClient.launch_bridge, which uses asyncio.create_subprocess_exec) works on the same machine.

Suggested fix

Don’t use select() on pipes on Windows. For example, read stderr lines on a background thread into a queue.Queue and wait on the queue with the deadline. That thread can also keep draining stderr after discovery. Currently nothing reads the pipe after discovery, so a bridge that logs a lot to stderr could eventually block on a full pipe buffer, on any OS.

Workaround we’re using

We replace cursor_sdk._bridge._read_discovery at runtime with a thread-based reader, as described above. Since Bridge.launch looks the function up by name when it runs, the replacement takes effect. The real fix belongs in the SDK, because we’re replacing a private function.

Bug 2: on Windows, a failed launch leaves the bridge’s node.exe running

Cause

On Windows, the launcher is cursor-sdk-bridge.cmd, so Popen starts cmd.exe, which starts node.exe. When a launch fails, _bridge._terminate_process (line 310) calls process.terminate(), which calls TerminateProcess on cmd.exe only. Windows doesn’t kill child processes when their parent dies, so node.exe keeps running.

A normal close() doesn’t have this problem, because it sends a shutdown RPC to the bridge before terminating. The async _terminate_process (_async_bridge.py line 216) has the same shape. I expect it orphans node.exe the same way, but I haven’t confirmed that.

The orphaned process’s command line also contains the tool-callback auth token, which any local process can read.

Suggested fix

Any of these would work:

  • On Windows, launch the bundled node.exe with dist/bin/cursor-sdk-bridge.js directly instead of going through the .cmd wrapper, so process.pid is the bridge itself.
  • Kill the whole process tree on failure, for example with taskkill /T /F /PID <pid>, or by putting the child in a Job Object with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE.
  • Pass the callback token through something other than argv. That’s a separate issue, but it’s worth considering since the code already avoids passing the store-callback token through env for a similar reason.

Steps to Reproduce

Bug 1:

from cursor_sdk import Client

with Client.launch_bridge(workspace=r"D:\some\folder") as client:
    pass

Bug 2:

Trigger any failure inside Bridge.launch after Popen. Bug 1 does this on every launch. Afterward:

Get-CimInstance Win32_Process -Filter "Name='node.exe'" |
  Where-Object { $_.CommandLine -match 'cursor-sdk-bridge' }

That lists a node.exe ...\dist\bin\cursor-sdk-bridge.js --workspace ... --tool-callback-url ... --tool-callback-auth-token ... process. Its parent is gone, and it keeps running until it’s killed by hand.

Operating System

Windows 10/11

Version Information

cursor-sdk 1.0.37, the latest on PyPI at the time of writing
Bundled bridge: cursor-sdk-bridge serverVersion 1.0.0, bundled Node v24.5.0
Python 3.13.15 (CPython, x64)
Windows 11 Enterprise 22631, PowerShell 7.6
Local runtime, with the default bundled bridge (resolve_bridge_path(), which resolves to _vendor/bridge/bin/cursor-sdk-bridge.cmd)

Does this stop you from using Cursor

No - Cursor works, but with this issue

Hey @rp-wbg, thanks for the detailed report.

The first one (sync launch failing with WinError 10038) is a known issue we’re already tracking, and I’ve added your report to it. Your reading is right: the sync launcher waits on the bridge’s stderr pipe in a way Windows doesn’t support, so every sync launch fails there. Your thread-based reader is a sound stopgap. The async client takes a different startup path and works on native Windows if you’d rather not patch a private function.

The second one (a failed launch leaving the bridge’s node.exe running, with the callback token on its command line) is new to us.

You mentioned you hadn’t confirmed whether the async launcher leaves node.exe behind too. If you have a minute, this should show it without needing the first issue:

  1. In PowerShell, run your Get-CimInstance command and stop any cursor-sdk-bridge node.exe processes it lists.
  2. Save and run this script (it forces a discovery timeout):
   import asyncio
   from cursor_sdk.asyncio import AsyncClient
   async def main():
       try:
           async with await AsyncClient.launch_bridge(workspace=r"D:\some\folder", timeout=0.2):
               pass
       except Exception as e:
           print("launch failed:", e)
   asyncio.run(main())
  1. Confirm it prints “launch failed: Timed out waiting for bridge discovery”.
  2. Wait about 5 seconds, then run the Get-CimInstance command again.

Does a node.exe running cursor-sdk-bridge.js show up in step 4? Let us know either way.

Thanks for the quick follow-up, and for adding the report to the existing issue.

I ran your script. The async launcher leaks node.exe too, so Bug 2 isn’t specific to the sync path.

Setup: cursor-sdk 1.0.37, Python 3.13.15, Windows 11 22631.

1. No cursor-sdk-bridge node.exe was running before the test.

2. I ran your script as written, with the workspace set to an existing folder.

3. It printed “launch failed: Timed out waiting for bridge discovery”.

4. About 6 seconds later, Get-CimInstance listed a node.exe running cursor-sdk-bridge.js:

  • Its parent process no longer existed.

  • It was still running 30 seconds after the failure. I didn’t wait longer than that.

  • It was listening on a 127.0.0.1 port, so it was a live bridge server and not a process that was exiting.

  • Its command line contained --tool-callback-auth-token with the token in plain text.

(Your message says “step 4” for the check, but I believe you meant the check after the 5-second wait. That’s the one I ran.)

So the async _terminate_process orphans node.exe the same way I expected, and fixing the sync launcher on its own wouldn’t fix it. I stopped the leftover process by hand afterward.

One more thing I noticed in the same run: the script exits with code 0 but prints an “Exception ignored in _ProactorBasePipeTransport._del_ … ValueError: I/O operation on closed pipe” traceback. I haven’t traced it, but it suggests the async failure path doesn’t close the subprocess’s pipe transports before the loop shuts down.

Thanks for running that, @rp-wbg, and yes, I meant the check after the 5-second wait.

Your result matches what we see. We reproduced it on our side, and it isn’t specific to Windows or to the sync launcher. Any failed launch that goes through the bundled launcher script leaves the bridge’s node process running, because only the wrapper gets terminated. I’ve passed this to the team as its own issue, together with the callback token on the command line and the stderr draining point.

The “_ProactorBasePipeTransport … I/O operation on closed pipe” traceback comes from the same leftover process. It still holds the bridge’s stderr pipe open, so the pipe never closes before the event loop shuts down, and the cleanup runs too late.

Until that’s fixed, you can avoid both by launching the bundled node.exe and bridge script directly instead of going through the .cmd wrapper. Then the SDK’s terminate() reaches the real bridge process:

import os
from cursor_sdk._vendor import resolve_bridge_path
from cursor_sdk.asyncio import AsyncClient

bin_dir = os.path.dirname(resolve_bridge_path())
bridge_cmd = [
    os.path.join(bin_dir, "node.exe"),
    os.path.join(bin_dir, "..", "dist", "bin", "cursor-sdk-bridge.js"),
]

async with await AsyncClient.launch_bridge(command=bridge_cmd, workspace=r"D:\some\folder") as client:
    ...

Client.launch_bridge takes the same command argument if you’re using it together with your thread-based reader. This relies on the current layout of the bundled bridge, so treat it as a stopgap. In our test, launching node directly left no process behind after a failed launch and the pipe traceback went away. We ran that check on Linux, so if you still see a leftover node.exe or the traceback on Windows with this change, let us know.