t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Server writes ~2 TB (≈1 TB net) and reads ~0.9 TB per month; statev2.sqlite is 40 GB. Measured per thread over 30 days, same on latest stable

Open tatarmb4s opened this issue 4 days ago • 3 comments

2026-11-27

Before submitting

  • [x] I searched existing issues and did not find a duplicate. (Related, not duplicate: #24789, #28903, #37961, #38159, #26591, #23365, #30065, #37877. All treat one cause each. This report measures the total effect over 30 days and it is still happening.)
  • [x] I included enough detail to reproduce or investigate the problem.

Area

apps/server

Summary

The T3 server (t3 serve, systemd t3code.service) is the biggest disk writer on my machine by a wide margin. Over 30 days its main thread read 876 GB and wrote 2,042 GB (1,077 GB of that was later cancelled, so about 965 GB net reached storage). The next biggest writer on the host wrote 157 GB. statev2.sqlite is 40 GB and its WAL never rests.

I think this is urgent. It wears out SSDs on every machine that runs T3 for a few weeks, with or without a GPU, and the user sees nothing: no warning, no setting, no size or write-rate display. I rate it more serious than the recent NVIDIA and AMD issues, because those cost time and this one costs hardware life and cannot be avoided by the user.

Measurements (30 days, 2026-10-28 → 2026-11-27)

Method (full setup in the gist below): a collector samples Linux per-thread I/O counters (/proc/<pid>/task/<tid>/io) every 500 ms and sums them per hour per systemd unit. Drive totals come from SMART counters. Grafana shows both.

What Reads Writes (dirtied) Cancelled writes
t3code.service, thread node-MainThread 875.6 GB 2,042.4 GB 1,076.9 GB
t3code.service, all threads 927.6 GB 2,073.4 GB 1,083.2 GB
all t3code-*.scope agent sessions (child CLIs, git, builds) 362.7 GB 1,100.3 GB –
systemd-journald (next biggest writer on the host) 0.7 GB 156.8 GB –
  • The server alone wrote 13 times more than the next writer. With agent sessions included, T3 caused 66% of all attributed writes on this host (3,174 GB of 4,832 GB).
  • Worst day: 349.9 GB written (2026-11-20, 24 hours above 5 GB each). Worst hour: 28.8 GB written (2026-11-27). Several days over 150 GB.
  • The writes come in long bursts while agents run, then stop. Idle days are near zero. So the cost follows agent activity, not the clock.
  • Physical effect: lifetime host writes of the WD SSD (the drive that grows; the other drive stays flat) went from about 31.4 TB to 40.08 TB across the same window (screenshot 1). Everything on the machine contributes to that number, not only T3. The per-thread numbers above are the part I can attribute to T3. They are lower bounds: the collector can miss short-lived threads. It lost no events (events_lost 0, 0 errors). Hours without any I/O have no rows, so the 395 hours with activity out of 720 in the window carry all of it.
  • write_bytes counts data dirtied for write-back. cancelled_write_bytes is the part removed before it reached the disk. I show both so nobody has to guess. Even the net number is far too high for a local orchestration app.

Database state (measured read-only today)

  • ~/.t3/userdata/statev2.sqlite: 40,079,163,392 bytes (9,785,199 pages × 4 KiB), freelist_count 0, WAL mode. A plain VACUUM reclaims nothing.
  • orchestration_events 22.3 GB (56%), orchestration_v2_projection_turn_items 8.0 GB, orchestration_v2_projection_nodes 2.8 GB. Event indexes add about 3.6 GB.
  • T3's own event-loop-stalls.ndjson: 670 stall records since 2026-10-19. Median worst delay per record 3.1 s, 95th percentile 8.5 s, maximum 1,033 s. Server CPU time in the kernel is about equal to user time (median ratio 0.92). That fits a server that spends its time on storage work.

Steps to reproduce

  1. Run T3 on Linux (here WSL2) with several agent threads for a few weeks. I use Claude, Codex and Cursor agents, including delegated sub-tasks.
  2. Watch the server's I/O: pidstat -d -p "$(pgrep -f 't3 serve')" 60, or sample /proc/<pid>/task/*/io and sum write_bytes and cancelled_write_bytes.
  3. Compare with the size of ~/.t3/userdata/statev2.sqlite.

Expected behavior

  • A running server writes a small fraction of this. Streaming output should not be persisted as thousands of full snapshots.
  • The event log has retention or compaction, so the file and the write rate stay bounded (#28903 asked for it).
  • The user can see the file size and the write rate, and gets a warning before the SSD or the disk pays for it.

Actual behavior

About 1 TB net (2 TB dirtied) of writes and 0.9 TB of reads per month from the server main thread alone, on a database that keeps growing (40 GB now).

Impact

Major degradation or frequent failure. It consumes SSD endurance continuously and stalls the event loop for seconds at a time.

Version or commit

  • Measured on: t3 v0.1.1-nightly.20261018.3315 (service-managed; the numbers above are from this build for the whole window).
  • I see the same behavior on a second machine running the latest stable release (v0.1.13 was marked "Latest" when I wrote this). I did not collect per-thread measurements there, only the same symptoms (constant heavy disk activity, a very large statev2.sqlite).

Environment

WSL2, Ubuntu 24.04.4, kernel 6.6.87.2-microsoft-standard-WSL2, 32 logical CPUs, 47 GB RAM, ext4 on a virtual disk, NVMe SSDs.

Logs or supporting files

Sanitized data, Grafana setup and screenshots (unlisted gist): https://gist.github.com/tatarmb4s/55c9effc78f3a92e7900d66eecbe332e

  • Hourly CSVs: t3code-service-hourly-by-thread.csv, t3code-agent-scopes-hourly-sum.csv, host-ssd-hourly-smart.csv, collector-coverage-hourly.csv
  • dbstat-summary.txt, event-loop-stalls-summary.txt
  • grafana-setup__*: Docker Compose (Grafana 13.2.3, Prometheus v3.15.0, node-exporter v1.12.1, cAdvisor v0.60.6, SQLite datasource plugin), Prometheus configs, rollup and import scripts, provisioned dashboards (JSON), systemd units. The per-thread collector itself is a small custom .NET service and its source is not included.
  • Masked: hostname, IPs, drive serials, URLs, credentials, user name and paths, other projects' container names, session ids. No conversation content or file paths were collected.

Screenshots (screenshot 3 has unrelated project and container names masked):

Lifetime, calendar-day and hourly host writes

Physical SSD hourly growth

Top 10 apps, hourly disk reads and writes (T3 is the blue series)

Workaround

None that I trust. Deleting history by hand from a live SQLite file is unsafe (#24789). I stopped nothing; I only measured.

Requested action

  1. Triage as high priority and confirm whether current builds still write at this rate. I can share more aggregate numbers on request.
  2. Find the top write sources by event type and reduce them at the source (stream coalescing, no per-chunk snapshots, checkpoint policy, see #38159).
  3. Ship bounded retention and real compaction by default (#28903), and a t3 db maintenance command.
  4. Show database size and write rate in settings, and warn when they grow fast.

tatarmb4s avatar Nov 27 '26 16:11 tatarmb4s

Follow-up with two things I should have included, plus a workaround.

1. The file regrows fast after a cleanup (same machine, same build 0.1.1-nightly.20261018.3315).

Date Event statev2.sqlite
2026-10-20 Offline cleanup (first/latest turn-item.updated retention), all 1,035 threads kept 21.12 GB → 3.80 GB
2026-11-07 Second cleanup, 3,123 conversation records kept, 1,112,454 intermediate snapshots removed 32.01 GB → 19.51 GB
2026-11-27 No cleanup since 40.08 GB

By file-size arithmetic that is about 1.6 GB/day, then about 1.0 GB/day (assuming the replaced file stayed in place). A cleanup removes snapshots. It does not change the writers, so the file fills again.

2. A retention fix already exists, and it does not address the write side.

  • #20990 ("compact superseded turn-item snapshots") merged on 2026-10-25 and is contained in v0.1.13. The build I measured predates it.
  • Its description says it "does not promise lower incoming device writes or immediate file shrinkage". It bounds what is kept. It does not reduce what is written.
  • I see the same heavy disk activity on a second machine on the latest stable release. I did not measure that one per thread, so I can't say how much of it is the old snapshots and how much is new writes. A per-thread measurement on a current build is the useful next step. The method is in the guide below.

3. Workaround that worked twice. A supervised offline rebuild: stop the service, build one bounded replacement, validate it, swap it in, restart. Conversations stay readable, including subagents. Full steps, the measuring method and the regrowth table are in one guide:

  • Guide: https://gist.github.com/tatarmb4s/55c9effc78f3a92e7900d66eecbe332e#file-t3-storage-guide-md
  • Helper (scripts, fixture tests, procedure): t3-storage-compaction-skill.tar.gz in the same gist. It is my own tested helper, not an official tool. Read it before running it, and never run it on a database you can't afford to lose.

This is a stopgap. It does not fix the cause. The requested actions in the issue still stand: find the top write sources by event type and reduce them at the source, ship retention and compaction as a supported feature, and show size and write rate to the user.

tatarmb4s avatar Nov 27 '26 16:11 tatarmb4s

Read-only sample, Nov 29 Mac A Mac B
statev2.sqlite (GB, decimal) 24.11 9.49
WAL (MiB) 128.00 45.56
Pages (4 KiB each) 5,886,834 2,316,992
Free pages 0 0
T3 version 0.1.14-nightly.20261128.5399 0.1.14-nightly.20261128.5399
Age of oldest retained event 267.3 days 52.5 days

Two Apple Silicon Macs; many agent threads over roughly three months, plus older imported history. WAL mode, incremental auto-vacuum enabled on both.

Database state (measured read-only today)

pie showData
    title Mac B — physical database bytes by table group
    "Turn items" : 4860997632
    "Nodes" : 1812942848
    "Events" : 348217344
    "Messages" : 196116480
    "Other tables and indexes" : 2272124928

Turn items + nodes occupy 70.3% of Mac B's file; events occupy 3.7%. Mac A's payload-only fallback finds 9.65 GB of turn-item JSON versus 0.47 GB of event JSON; its physical breakdown was not obtained.

Measurements

Retained event JSON dated Nov 28 Mac A Mac B
Payload (MB, decimal) 267 99

This is retained payload by event timestamp, not net daily growth or SSD writes. Neither daily file growth nor device I/O was measured. Oldest-row age includes imports; dividing size by age would not establish growth. Both databases have recent event-pruning markers, consistent with the retention fix noted above.

Expected behavior

  • Supported, configurable retention/compaction for settled-thread projections, preserving fork/checkpoint dependencies and replay anchors.
  • Incremental vacuum after supported pruning; it is already enabled here, and zero free pages leaves nothing to reclaim now.
  • Visible database size, retained bytes by source, and write-rate warnings.

Method: read-only SQLite PRAGMAs, dbstat on Mac B, aggregate payload byte lengths on both. No database writes, copies, cleanup, checkpoint, vacuum or app restart.

EtanHey avatar Nov 29 '26 01:11 EtanHey

Same growth here, with a user-facing effect: the desktop app freezes for 10 to 45 seconds and shows "MacBook Pro is reconnecting. T3 Code on MacBook Pro did not answer", although the server runs on the same Mac.

Environment: desktop 0.1.13 (bc0f04da94f6) with its local backend, macOS (Darwin 27.2), Apple Silicon.

Database (read-only): statev2.sqlite is 11.0 GB. t3 doctor --dry-run reports only 419.9 MiB reclaimable. Turn items (4,891 MB) and nodes (1,837 MB) use most of the file, like Mac B above.

Stalls: event-loop-stalls.ndjson has 12 stalls of 10 seconds or longer, 11 of them since 2026-11-24. The longest is 43.9 s. In mid-November most stalls were 2 to 5 s.

Trace: during the 18.9 s stall that ended at 2026-11-29T14:45:37Z, ShellStream.loadShellSnapshotParts (ws.rpc.orchestration.getArchivedShellSnapshot) spent 41.8 s in sqlite. OrchestrationEventStore.readAgentEvents took 26.1 s. Unrelated RPCs such as vcs.refreshBranch and workspace.listFolders waited behind them for 26 to 42 s.

Related: #21539 (same symptom, 12.5 GB database, closed) and #42372 (retention, closed as not planned).

Collected with t3 triage by Claude Code (Claude Opus 5.5).

giovanecesar avatar Nov 29 '26 14:11 giovanecesar