Skip to content
Source
Sign inSign up
pingdotgg/t3code

[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

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

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

  1. 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/queued at the same time.
  2. 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 avgsqlite span avg
14:005466 s2.9 s
14:055452 s0.5 s
15:3274 / 8 / 33133 s1.1 s
16:1384 / 3 / 36163 s12.5 s
16:14same144 s15.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:

  1. Keep thread subscriptions and other client reads off the event loop that handles provider events, or at least ahead of it in priority.
  2. Don't let the client re-subscribe on a timer while the first subscription is still being served, or back off.
  3. 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.

  1. tanstack-source added labelsbug

  2. 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

    • V8 CPU profile (45 s, via SIGUSR1 inspector): main thread 17.6% busy; 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).
    • strace on the main thread (15 s): 81 clone() calls with plain fork flags (no CLONE_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.
    • Since the last restart, the main thread has used 157 s user and 278 s system time. event-loop-stalls.ndjson from 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)

    • 46% checkpoint capture (checkpointCapture), ~24 git invocations per capture.
    • 34% PR sync (ThreadPullRequestServiceV2.synchronize), ~17 git invocations per sync, mostly git config reads (1,127 in the window).
    • These scale with active runs × (checkpoints + PR syncs + VCS polls). At ~80–117 runs the loop saturates, which matches the 2–3 min thread opens in the original report.

    Root cause In src/process/SpawnWorker.ts, layerServer only routes spawns to the SpawnWorker pool on win32. On Linux every Effect spawn calls libuv fork() 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 direct execFile calls. It isn't load-tested yet. I'll add results here after running it under real load.

    Suggestions

    1. Use the SpawnWorker pool (or posix_spawn/vfork semantics) for all spawns on Linux/macOS, not only Windows.
    2. Cache git config reads per repo during PR sync. Most of the 17 calls per sync return the same values.
    3. Batch the git calls in checkpoint capture (~24 per capture).
    4. Skip PR sync for threads whose PR is merged or closed.
  3. 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

  4. 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.

  5. juliusmarminge closed this

Sign in to join this conversation.