Repository navigation
Description
Before submitting
- I searched existing issues and did not find an open duplicate. Closed issues that touch the same ground are under Related.
- I included enough detail to reproduce or investigate the problem.
Area
apps/server
Steps to reproduce
Run t3 serve with a large database and many agent sessions. Our load is about 46 agent processes under the server, 13 to 18 stored events per second in the windows I measured (9.5 per second averaged over the process lifetime), and one local client that makes most of the t3_thread_read calls (928 of 933 in one window). Nothing else is special.
- CPU per stored event. Read process CPU and the event sequence twice, 30 s apart, and divide:
pid=<t3 serve pid> db="file:$HOME/.t3/userdata/statev2.sqlite?mode=ro" a=$(awk '{print $14+$15}' /proc/$pid/stat); s1=$(sqlite3 "$db" "SELECT MAX(sequence) FROM orchestration_events") sleep 30 b=$(awk '{print $14+$15}' /proc/$pid/stat); s2=$(sqlite3 "$db" "SELECT MAX(sequence) FROM orchestration_events") awk -v t=$((b-a)) -v e=$((s2-s1)) 'BEGIN{printf "%.1f ms CPU per stored event\n", t*10/e}' ps -o etimes=,cputimes= -p $pid # lifetime CPU seconds, for the lifetime average
- SQLite cache. The setup code sets no
cache_sizeand nommap_size:grep -n "cache_size\|mmap_size" apps/server/src/persistence/Sqlite.ts packages/shared/src/nodeSqliteClient.ts # no output at 9a35ab0 sqlite3 "$db" "PRAGMA cache_size;" # -2000, the SQLite default (a new connection, so this shows the default, not a read of the server's connections)
- Runs per thread:
sqlite3 "$db" "SELECT thread_id, COUNT(*) c FROM orchestration_v2_projection_runs GROUP BY thread_id ORDER BY c DESC LIMIT 5"
Expected behavior
A stored event costs a few milliseconds of CPU, not tens. A thread read does not load every run of the thread when it returns a few items.
Actual behavior
t3 serve 0.1.10-nightly.20261113.4643 (commit 9a35ab0), up about 25 hours, on a 15.5 GB statev2.sqlite. The host is an 8-core Linux machine under heavy load (load average 15 to 47, CPU pressure 35 %, 12 GB of swap in use).
1. The CPU follows our event volume. The cost of each event is the issue, not a spin or a leak.
In quiet seconds the server uses about 3 % of one core. Per 1 s sample it ranges from 3 % (minimum) through 84 % (median) and 174 % (90th percentile) to 329 % (maximum). Process CPU divided by stored events:
| Window | CPU | Stored events | CPU per event |
|---|---|---|---|
| 209 s sample | 191.9 CPU-s | 2,903 | 66.1 ms |
| process lifetime | 56,451 CPU-s | 847,778 | 66.6 ms |
The CPU-per-event figure is the same over 4 minutes and over 25 hours. It is total process CPU, so it includes everything the server does for each event and for the clients' reads, not a single code path. Lifetime CPU is 63 % of one core (15 h 40 min in 89,150 s). Over the lifetime, by thread: main thread 47 %, SQLite worker threads 31 %, V8 helper threads (mostly garbage collection) 20 %. In the 209 s sample, 24 % of the process CPU was system time.
Database reads per event, from a fit over ten-second buckets in one 150 s window (R² 0.58, so a fit, not a measurement): about 1,300 pages (5.3 MB) per stored event, and about 1,355 pages (5.5 MB) per t3_thread_read by the local client. I did not check this read figure over the process lifetime, so I cannot say it is flat over 25 hours. Only the CPU figure is. The lifetime read totals are in section 2.
2. The SQLite cache is the 2 MB default on a 15.5 GB database.
cache_size is -2000 and no mmap_size is set (apps/server/src/persistence/Sqlite.ts lines 72 to 89 set the other PRAGMAs; cache_size and mmap_size appear in neither that file nor packages/shared/src/nodeSqliteClient.ts). The reader worker threads make 20,000 to 57,000 reads of about 4 KB a second, 82 to 233 MB/s. Over the process lifetime: 4.04 billion read calls and 11.4 TB read through system calls, 2.7 TB of it from disk. So most reads are served by the operating system cache, not by SQLite's own.
I have not tested whether a larger cache or mmap_size lowers the read calls or the CPU. #24895 argues a larger page cache would not help, because overflow content is read directly from the file and in WAL mode a reader's cache is reset when another connection commits. I cannot tell which of our reads are overflow pages.
3. t3_thread_read loads every run of the thread, with no limit.
loadReadableThread (apps/server/src/mcp/OrchestratorMcpService.ts lines 1376 to 1406) calls getProjectThreadRecords for runs, providerTurns and runtimeRequests with no filter. That reaches readCanonicalProjection (apps/server/src/orchestration-v2/ProjectionStore.ts line 3542, through getThreadRecords at lines 6278 to 6283, which passes no window), whose runs select has no limit and no status filter when no filter is passed (lines 3789 to 3796):
SELECT payload_json FROM orchestration_v2_projection_runs WHERE thread_id = ? ORDER BY ordinal ASCThe trace shows this select 2,303 times in 351 s, from all callers. This select reads rows in proportion to a thread's history. I did not time a thread read on a 5,000-run thread against a 10-run one, so I cannot say how much of a read's time it is. Our long-lived threads are long: 6 have over 1,000 runs, 43 have over 100, and the largest has 5,263 runs and 5.8 MB of run rows.
One client is the main caller. In 229 s of trace, t3_thread_read ran 244 times a minute. 928 of the 933 thread reads came from one user agent, a plain node client on the same host. It is the only plain node client on the server's port, so I take it to be our own tool; the trace does not record the caller, so that is an inference. One MCP session made 870 reads in 229 s, in bursts (median gap 0.03 s, up to 173 in 10 s). A fit of the 150 s window gives that client about 17 % of the process CPU (R² 0.36); the 209 s window gave about 0 (R² 0.29). So most of the CPU is not that client's reads.
Minor: 26 statements per read. A t3_thread_read runs a median 26 SQL statements (95th percentile 38, maximum 49) and takes a median 78 ms. It reads the same thread row 4 times and the thread's runs twice. The count is fixed and does not grow with thread size. In a quiet moment one read took 19 ms.
What I could not establish
- No CPU profile.
perf,strace,bpftraceandpidstatare not installed here,gdbattach is blocked and would pause the server, and the Node inspector would change the process. I cannot say where the main thread's 40 % of a core (209 s sample) goes. The split by thread above comes fromtop -H: it counts CPU per thread, not per function. The client's 17 % share is a fit, not a measurement. - The 11 MB/s of writes. The server wrote 1.05 TB to disk in 25 hours, about 1.2 MB per stored event. Traces are 0.3 to 0.5 MB/s of that. I did not trace the rest.
- The overloaded host. Load stretches the wall times I quote. It should not change CPU seconds much, but I did not check on a quiet host. I could not stop our load, so I do not know the idle cost with no agents.
- Which statements read the most pages. The trace records times, not bytes.
- Whether either fix helps. I did not change
cache_sizeormmap_size, and I did not time reads against thread size.
Impact
Minor bug or occasional failure. The server averages about 0.63 of a core over its lifetime and reached 329 % of a core in its busiest second. Nothing here fails on its own. I put it under Minor because I cannot show a failure caused by it.
Version or commit
0.1.10-nightly.20261113.4643, commit 9a35ab0. Source lines above are from that commit.
Environment
Linux 7.2 (Arch) on arm64, 8 cores, 32 GB RAM. t3 serve runs as a systemd user service with the Claude provider, with about 46 agent processes under it. The database is ~/.t3/userdata/statev2.sqlite, 15.5 GB.
Logs or stack traces
None beyond the counts above. I can share the trace analysis if it helps.
Workaround
None found. I did not change any setting or restart the server.
Related
- [Bug]: Desktop server writes ~100× its event data to disk (327 GB in 21 h, ≥2.2 TB in 15 h on Oct 8) #19105 (closed): reported
cache_size = -2000on a 46 GB database and suggested settingcache_sizeandtemp_store.temp_storeis set at 9a35ab0;cache_sizestill is not. - [Bug]: Event loop stalls of 10–60 s on HDD-backed hosts make T3 Connect reconnects time out (mint-credential / websocket-ticket) despite a healthy tunnel #37373 (closed): suggestion 3 asks to raise the page cache or
mmap_size, on a slow disk. - History-wide reads saturate the single SQLite reader on large databases (thread switches take 12-50 s) #24895 (closed): history-wide reads saturate the single reader. Item 5 covers
readCanonicalProjection. It argues a larger page cache would not help (see above). - t3_queue and the handoff-tool analytics lookup read a long thread's whole message history #36125 (closed):
t3_queueand the analytics lookup read a long thread's whole message history. - Deferred-steer check and queued-message cancel read a long thread's whole history under its dispatch lock #36095 (closed): the deferred-steer check and queued-message cancel read all runs of a long thread. Same kind of read, in other callers; not
t3_thread_read. - Server trace log volume makes it Defender's top scanned file on Windows and rotates history out in about two hours #28196 (open): trace volume. The server also writes every span to disk; I did not measure what that costs in CPU.
- [Bug]: Each event commit rewrites 25–33 SQLite pages, so the server writes 56–85× its event data #37600 (open): each event commit rewrites 25 to 33 SQLite pages.
- Opening a thread (thread.visit) waits behind the single SQLite writer and shows "Some requests are slow" (34 s) #30301 (open):
thread.visitwaits behind the single writer.
Activity
nitedani commentedon Nov 17, 2026
We see the same unbounded reads on a second server: headless
t3 serveon a 32 vCPU Linux VM, nightly 0.1.10-nightly.20261116.4761 plus #31488, with an 11 GiBstatev2.sqlite. We have nothing to add on points 1 and 2, because we didn't count stored events or changecache_size.The five longest
ProjectionStore.readCanonicalProjectionspans in our trace (23.5 s to 71.1 s) have not3_thread_readabove them. Four run underOrchestrator.startNextQueuedRunand one under thetask_canceltool'ssubagent.stop.startNextQueuedRunreads the thread throughreadCommandProjection, which on main still selects every run and attempt of the thread, whilet3_thread_readselects every run at OrchestratorMcpService.ts:1485.The runs select took under 1 s in all five, so it isn't the expensive part. In the 71.1 s one, attempts took 15.3 s and nodes 21.4 s. These are wall times on a busy reader pool, not CPU.
You couldn't say how much of a read's time thread size costs, so I timed it on a 12.5 GB backup copy of our database with Python's
sqlite3rather than the server. Your runs select on a 4,991-run thread (5.75 MB) took 8,447 ms on the first pass and 22 to 60 ms on repeats. WithLIMIT 20, run right after those, it took under 1 ms. On a 10-run thread it took 4.0 ms on the first pass and under 0.2 ms on repeats.I found no open PR that bounds these reads, and #36141 bounds history pages, a different path. I'd fix the shared command read, keeping only the records its callers use, rather than
t3_thread_readalone, because on our server the command path is where the long reads come from.jonathanli12 commentedon Nov 17, 2026
Note
🤖 Claude Opus 5.5 responding on behalf of jonathanli12
Seeing the same thing, and the cost per event grows with database size, not with event rate. Measured with the steps above (60 s windows) on four
t3 serveprocesses on one Linux host, at the same moment:To keep each database small, we now run nine extra servers on the same host. That fits your cache and run-loading diagnosis better than a concurrency limit, though we haven't profiled to confirm it.