[Bug]: With ~80 concurrent runs the server's one event-loop core saturates; opening a thread takes 2–3 min and the client re-subscribes every ~65 s #38646
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/server
Steps to reproduce#
- Run the service on a Linux box with many agents at once: delegate fan-out from a few orchestrator threads plus scheduled tasks, 50–120 runs in
preparing/starting/running/queuedat the same time. - Open the app from another machine and click through threads.
Expected behavior#
Opening a thread stays interactive while agents work. Extra load waits in a queue or uses more cores instead of making every client request wait.
Actual behavior#
The server's main thread sits at 100% of one core (top -H: node-MainThread 100%, worker threads 0–20%) while the other 23 cores are mostly idle (load average 3–13). Every request waits behind agent event handling:
| Time (CET) | Active runs (running/starting/queued) | subscribeThread avg | sqlite span avg |
|---|---|---|---|
| 14:00 | 54 | 66 s | 2.9 s |
| 14:05 | 54 | 52 s | 0.5 s |
| 15:32 | 74 / 8 / 33 | 133 s | 1.1 s |
| 16:13 | 84 / 3 / 36 | 163 s | 12.5 s |
| 16:14 | same | 144 s | 15.9 s |
The database itself is fast. The same statements on a separate read-only connection take about 1 ms, for example SELECT last_sequence FROM orchestration_v2_projection_metadata WHERE projection_name = ? or SELECT MAX(sequence) FROM orchestration_events. Inside the server they show 6–13 s, so the time is queueing on the event loop, not SQLite.
The client then makes it worse. Every ws.rpc.orchestration.subscribeThread span in a 20-minute window ended Interrupted after about 65–70 s (380 of 380), and the same 46 threads were re-subscribed about 9 times each. Each retry restarts the work, memory.heap_growth_bytes is about 47 MB per subscription, and the app shows " is reconnecting". A 22-event thread took 65 s the same way as a 6,420-event one.
Largest span totals over the last 30 minutes (18,944 spans): ws.rpc.orchestration.subscribeThread 24,320 s across 346 spans, sqlite 13,241 s across 4,473, ws.orchestrationV2.subscribeThread 8,104 s across 338, orchestrationV2.EventSink.write 3,980 s across 85. OrchestrationEventStore.rowToV2StoredEvent was the most frequent span name.
There is no setting to cap concurrent runs per server. A second t3 serve with its own --base-dir works as a stopgap, but it splits threads across two environments.
Asks, any one of which would help:
- Keep thread subscriptions and other client reads off the event loop that handles provider events, or at least ahead of it in priority.
- Don't let the client re-subscribe on a timer while the first subscription is still being served, or back off.
- A server setting for the maximum number of concurrently running provider turns, with extra runs waiting in
queued.
Impact#
Blocks work completely
Version or commit#
0.1.11-nightly.20261118.4877 (service install)
Environment#
Ubuntu 26.04.1 LTS, 24 cores, 60 GB RAM, Node 26.13.1 (bundled). statev2.sqlite 60 GB, about 16,800 live threads. Providers: Claude Code 2.1.327, Codex 0.170.0. Clients: macOS desktop over T3 Connect.
Logs or stack traces#
[16:03] WARN environment api request failed
endpoint: 'HttpApiEndpoint', errorTag: 'Interrupt'
cause: 'InterruptError: All fibers interrupted without error
at server.runServerCommand ...'
subscribeThread span: durationMs 65611, exit Interrupted,
memory.heap_growth_bytes 47289344
Screenshots, recordings, or supporting files#
No response
Workaround#
Pause scheduled tasks that fan out work and interrupt duplicate long-running monitors, or run a second t3 serve --base-dir <other dir> --port <other port> for interactive threads.
tanstack-source added labelsbug
same issue. with 3 machines (2* mac os, 1 windows) it's basically unusable when working on 10-15 projects. I'm going through 5-10B tokens/day
This is the same problem as #31422, so I'm closing it in favour of that one. If it is different, say how and it will be reopened.
juliusmarminge closed this
Sign in to join this conversation.
Profiled this on the affected Linux server (v0.1.11-nightly.20261118.4877, Node 26.13.1 SEA, ~30 active runs at measurement time). The main thread time is mostly going into
fork()for git/gh spawns, not into SQLite.Measurements
child_process.spawn= 4.9 s of 8.0 s busy (61%). SQLite ≈ 11%, tracing ≈ 3%.perf record -g -t <main tid>(30 s): 65% of main-thread samples are in the kernel. 45% are fork page-table copies (dup_mmap/copy_page_range/copy_present_ptes).straceon the main thread (15 s): 81clone()calls with plain fork flags (noCLONE_VM/CLONE_VFORK), 10.9 ms on average, 17.7 ms max. The process RSS is 0.85–1.6 GB, so every fork copies those page tables on the event loop.event-loop-stalls.ndjsonfrom earlier days shows the same split (~72% system).Where the spawns come from (from
server.trace.ndjson, 18.7 min, 7,595 spawns ≈ 6.8/s)checkpointCapture), ~24 git invocations per capture.ThreadPullRequestServiceV2.synchronize), ~17 git invocations per sync, mostlygit configreads (1,127 in the window).Root cause In
src/process/SpawnWorker.ts,layerServeronly routes spawns to the SpawnWorker pool onwin32. On Linux every Effect spawn calls libuvfork()on the main thread.Experiment I flipped that condition so Linux uses the existing SpawnWorker pool (the same pool already used on Linux for provider CLIs via
spawnPiped). In an isolated boot, 3 of 5 server spawns moved to worker threads; the other 2 are directexecFilecalls. It isn't load-tested yet. I'll add results here after running it under real load.Suggestions
posix_spawn/vfork semantics) for all spawns on Linux/macOS, not only Windows.git configreads per repo during PR sync. Most of the 17 calls per sync return the same values.