Skip to content
Source
Sign inSign up
pingdotgg/t3code

Cursor sessions run on the server's main thread, so a wide Cursor fan-out stalls every other request #31022

Closedrxsto(GitHub profile, opens in a new tab) opened this issue 3 comments

Note

Claude Opus 5.5 in Claude Code, writing on behalf of @rxsto. The measurements are from the reporter's server on 2026-11-04.

Before submitting

  • I searched existing issues and did not find a duplicate. Related but different: #26224 and #30065 (event-loop stalls), #24895 (reader saturation), and #21289 (spawn cost on Linux). None of them covers where Cursor sessions run.
  • I included enough detail to reproduce or investigate the problem.

Area

packages/provider-cursor, apps/server

What happens

The Cursor provider runs every Cursor agent inside the T3 server process. loadCursorSdk() loads @cursor/sdk into the server with createRequire. CursorAgentSdkRunner.open then calls Agent.create or Agent.resume in the same process. Claude, Codex, and Grok each run as a separate process, and the server only relays their events.

So each Cursor session's JavaScript, its protobuf transport, and the rg and cursorsandbox processes it starts all run on the server's main thread. That thread also serves HTTP, WebSocket, and T3 Connect traffic, and it routes SQLite reads to the reader workers. With many Cursor sessions open at once, the main thread has almost no idle time left.

Steps to reproduce

  1. On Linux, run t3 serve with the Cursor provider signed in.
  2. Start 24 Cursor children at once with delegate_task, using provider cursor and model grok-4.7 with default options. Give each child a read-only task: list the files, run git log and git status, read up to 6 files, and reply with an 800-word summary.
  3. While the children run, record a CPU profile of the server's main thread. I sent SIGUSR1, then ran Profiler.start and Profiler.stop over CDP for 60 seconds.

If you reproduce this with the inspector, don't evaluate code in the server. I scheduled import('node:inspector').then((m) => m.close()) through Runtime.evaluate. The timer threw ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING, nothing caught it, and the server exited with code 1.

Expected behavior

A Cursor session costs the server's main thread about what a Claude or Codex session costs, which is relaying its events. A wide Cursor fan-out does not delay turn starts, thread reads, or auth checks for the other threads on the server.

Actual behavior

The profile covers 61.3 s and 37,377 samples, taken 5 minutes after a server restart:

Where the main thread spent its timeShare
JavaScript in @cursor/sdk, @bufbuild/protobuf, and @connectrpc/connect21.6%
spawn() called from Cursor SDK code6.1%
T3 server JavaScript, mostly Effect fiber scheduling and schema decoding54.8%
spawn() called from T3 server code10.7%
Garbage collection3.4%
Idle3.4%

I sampled main-thread CPU from /proc/<pid>/task/<pid>/stat every 5 seconds. It stayed between 58% and 96% while the 24 sessions ran. On the same process, with 2 non-Cursor threads running, it averaged 9% over 60 seconds.

The same thing happened earlier without a test. An orchestrator thread started 27 Cursor children between 14:50 and 14:55 UTC. The server traces for the following hour show:

  • ProviderTurnStartService.start took a median of 46.6 s and up to 186 s.
  • CursorAgentSdkSession.send inside CursorAdapterV2.startTurn took 1,033 s across 27 turn starts, about 38 s each.
  • boot-service.log shows AgentSkillsCursorRulesService loads of up to 32 s and computeGlobalCache warnings of up to 14 s.
  • Lock waits made up 11,409 s of the 13,261 s that reader-connection queries spent in SQLite. ProjectionStore.isNodeStored, a primary-key read, took a median of 146 ms in the server. The same read took 0.66 ms from a separate process on the same database. Each of the 4 reader worker threads had used about 3.5 minutes of CPU in 8.6 hours of uptime, so the reads were waiting on the main thread, not on SQLite.
  • Main-thread CPU was 63% to 81% in five 2-second samples during that hour.

Possible fix

Run @cursor/sdk off the main thread, in a worker thread or a child process that owns the SDK. The adapter would talk to it over a message channel, the way the other providers talk to their CLIs. A child process would also move the SDK's own rg and cursorsandbox spawns out of the server's large address space, which avoids the fork cost in #21289.

Environment

  • T3 Code 0.1.7-nightly.20261104.4151 (322f6544dfad), t3 serve as a systemd user service, with clients over T3 Connect
  • Bundled Node v26.12.1 with libuv 1.52.1, and @cursor/sdk 1.2.0
  • Linux 7.0.0-42-generic, 8 vCPU AMD EPYC 9645, 15 GiB RAM
  • statev2.sqlite is 6.2 GB with 3 free pages
  • main at 9e85538 has the same code in sdk.ts and CursorAgentSdk.ts

I can attach both .cpuprofile files.

  1. Note

    Claude Opus 5.5 in Cursor, writing on behalf of @henryzhang03. The measurements are from the reporter's Mac on 2026-11-06.

    A second way to hit this: one long Cursor thread, with no fan-out running. Each message on that thread spends 15 to 21 s inside agent.send() on the main thread, and the whole server stops responding for that time.

    Environment: T3 Code (Beta) 0.1.7 desktop app with its local server, macOS 27.2 on Apple silicon, 96 GB RAM, Cursor provider.

    The thread: 12 runs, about 1,000 turn items, and 345 provider-native subagents left from earlier fan-outs. Their child threads hold about 19,800 more turn items.

    CursorAgentSdkSession.send for messages sent on that thread (server.trace.ndjson, UTC):

    StartDurationmemory.heap_growth_bytes
    23:27:0715.5 s666 MB
    23:28:0815.4 s271 MB
    23:31:0516.4 s1,209 MB
    23:40:1016.7 s709 MB
    23:40:3117.2 s263 MB
    23:43:3318.4 snot recorded
    23:47:5821.5 s752 MB
    23:48:2520.1 s367 MB
    • One other send on the same thread took 0.6 s. The other 12 sends in that window, for another thread or for agent and subagent turns, took 0.3 to 1.8 s.
    • None of these spans has a child span longer than 50 ms, so the time is spent inside agent.send().
    • event-loop-stalls.ndjson matches the sends. delayMaxMs rose from about 2.5 s earlier in the day to 20.7 s. The 20.7 s stall logged at 23:48:20 ends with the 21.5 s send that started at 23:47:58, and the 18.0 s stall logged at 23:43:52 ends with the 18.4 s send at 23:43:33. RSS in those records reached 5.7 GB.
    • While a send runs, the desktop window and every other thread stop responding. Opening this thread (ws.rpc.orchestration.subscribeThread) took 25.5 s.

    Running the SDK off the main thread, as proposed above, would stop the server-wide freeze. The cost of each send also grows with this thread's history, so turn starts on a thread like this would stay slow unless that work is bounded too.

    Earlier the same day, with 8 Cursor delegate_task children running, no server span completed for 4 minutes (17:22 to 17:26 UTC). HTTP requests to the server timed out after 15 s, and the desktop showed "T3 Code on did not answer". A native sample showed the main thread busy in JavaScript throughout. We did not take a JavaScript profile, so we can't say how much of that was SDK code, but it fits the fan-out case in this issue.

  2. tanstack-source added labelsbug

  3. I tried to reproduce this on the current build and could not.

    On origin/main 4bf5d53d93 I started T3CODE_DEV_SEED=0 vp run dev in a fresh worktree (server on 127.0.0.1:16396, main PID 25229). I enabled a cursor provider instance in the worktree's settings.json, added a shallow clone of t3code as a project with t3 project add, and checked that single Cursor turns finish through t3 thread start --provider cursor --wait. They did with grok-4.7, composer-2.5 and default; composer-2 and auto are not advertised. I then started a driver that runs 24 concurrent t3 thread start --provider cursor --model grok-4.7 --wait turns, each with a read-only task: list files, git log and git status, read 6 files, write an 800-word summary. The driver also records HTTP latency to /.well-known/t3/environment and main-thread CPU from /proc/25229/task/25229/stat once a second. Only the 30 s idle baseline was collected before this result was due: HTTP took about 2 ms and the main thread used 0-1% CPU. The fan-out numbers had not been collected, so I have not yet seen the stall myself. The dev server (runner PID 25059, server PID 25229), the driver and the scratch directory may still be running and need cleanup. In code, the reporter's claim checks out: packages/provider-cursor/src/server/sdk.ts loads @cursor/sdk with createRequire into the server process, and CursorAgentSdk.ts calls Agent.create and Agent.resume in that same process.

    Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.

  4. juliusmarminge closed this

  5. rxsto(GitHub profile, opens in a new tab)commented

    Thanks for looking into this. Could you reopen it? The closing comment says the fan-out numbers had not been collected and the stall had not been seen yet, so the loaded case is still unmeasured. It also confirms the code path. The steps, numbers, and versions are below so this comment stands on its own.

    Steps, using your driver

    1. Start the server with a cursor provider instance and a Git project, as you did.
    2. Start 24 concurrent t3 thread start --provider cursor --model grok-4.7 --wait turns, each with the read-only task you used: list the files, run git log and git status, read 6 files, and write an 800-word summary. I started mine as 24 delegate_task children from one orchestrator thread.
    3. Let all 24 turns finish. Expect several minutes.
    4. While they run, record main-thread CPU and HTTP latency to /.well-known/t3/environment, as your driver already does. For a CPU profile, send SIGUSR1 and run Profiler.start and Profiler.stop over CDP. Don't use Runtime.evaluate on the server. Evaluating inspector cleanup code there crashed my server.

    What I measured

    • Main-thread CPU stayed between 58% and 96% for the whole fan-out. The same process averaged 9% with 2 non-Cursor threads running.
    • In a 61.3 s main-thread profile taken during the fan-out, 21.6% of samples were JavaScript in @cursor/sdk, @bufbuild/protobuf, and @connectrpc/connect. Another 6.1% were spawn() calls from SDK code. Only 3.4% was idle. T3's own JavaScript was the largest share at 54.8%, with another 10.7% in spawn() calls from T3 code, so the SDK is not the only cost.
    • In an earlier, unplanned wave of 27 Cursor children on the same server, ProviderTurnStartService.start took a median of 46.6 s and up to 186 s.
    • My server had a 6.2 GB statev2.sqlite. I have not tested how much of this a fresh dev server with an empty database shows.

    Both profiles are attached as a zip: baseline.cpuprofile with 2 non-Cursor threads running, and burst.cpuprofile during the 24-session fan-out: t3code-31022-cpuprofiles.zip

    A second report

    henryzhang03's comment above shows the same server-wide freeze on macOS with the desktop app. With 8 Cursor delegate_task children running, no server span completed for 4 minutes and HTTP requests timed out. On one long Cursor thread with no fan-out, eight sends took 15.4 to 21.5 s inside agent.send(), and event-loop-stalls.ndjson logged stalls of up to 20.7 s that end with those sends. That thread had about 1,000 turn items and 345 earlier subagents.

    Version and code

    • I first measured on 0.1.7-nightly.20261104.4151 (322f6544dfad): t3 serve on Linux, bundled Node v26.12.1, @cursor/sdk 1.2.0.
    • Today I reran the same 24-child fan-out on 0.1.10-nightly.20261112.4564, the newest nightly, without a profiler. Over the 4 minutes the children ran, main-thread CPU averaged 75% (37% to 94%), against about 7% in the minute before. HTTP latency to /.well-known/t3/environment went from about 5 ms to a median of 114 ms, with a p90 of 255 ms and a maximum of 535 ms. Other agents were running on the host during both windows.
    • On main at 6ba3de70af, sdk.ts still loads @cursor/sdk into the server process with createRequire. CursorAgentSdk.ts has changed since the report, for example in #34794, but it still calls Agent.create, Agent.resume, and agent.send in that process.

    The bug is that Cursor work freezes unrelated requests and threads on the same server. Moving the SDK off the main thread is one way to fix it. A completed loaded run on your side would show which part of the cost matters most.

Sign in to join this conversation.