t3code icon indicating copy to clipboard operation
t3code copied to clipboard

Desktop window freezes up to 2 s while the connection cache saves, and the cache has no size limit (812 MB)

Open ahrsn opened this issue 3 days ago • 1 comments

What happened

The desktop app has become hard to use over the last week. Typing in the composer, clicking, and switching threads freeze for a fraction of a second up to about 2 seconds at a time. Other apps on the Mac stay responsive, and the Mac has spare CPU, memory and GPU while T3 freezes (about 47–79% idle CPU).

Diagnosis

The freezes are on the renderer main thread, not the server. The renderer's own spans (flushed into server.trace.ndjson) show requests that the server answered in 0.1–20 ms but that the renderer only handled 100–1,334 ms later (p90 205 ms, p99 809 ms over about 2,000 requests). During the worst freeze the server sat at 0.1% CPU.

One cause we could pin down is the renderer's IndexedDB connection cache (t3code:connection-runtime):

  1. Saves block the renderer. storage.saveShell runs every ~10 s while the shell changes. Over 75 minutes it reached 2,067 ms (p99 286 ms), with web.connectionStorage.writeDatabaseValue at up to 1,285 ms. In the 2,071 ms case, about 782 ms went to encoding before the write started. A native sample of the renderer during that window shows the main thread 88% busy in v8::ValueSerializer, v8::Object::Clone, v8::Object::Wrap and cppgc. storage.saveThread reached 568 ms in the same window, and 2,093 ms earlier in the evening.
  2. The cache has no size or age limit. On this machine the origin's IndexedDB is 812 MB in 2,378 files (t3code_app_0.indexeddb.blob + .leveldb), and its only database is t3code:connection-runtime. In apps/web/src/connection/storage.ts, thread store entries are removed only by removeThread or clear. Nothing caps how many threads stay cached or for how long. Single cached thread blobs reach 1.5–6.4 MB compressed (up to about 25 MB of JSON).

saveShell p50 is only 14 ms, so the long saves look like a compounding effect: synchronous encoding on the main thread plus GC plus LevelDB/blob work on a very large store.

Steps to reproduce

  1. Use the desktop app for a few weeks with many threads, including some with 1,000–2,000+ items, so the connection-runtime IndexedDB grows into the hundreds of MB.
  2. With several threads running, type in the composer and switch threads.
  3. Compare storage.saveShell, storage.saveThread and web.connectionStorage.writeDatabaseValue durations in server.trace.ndjson with the moments typing freezes.

Version

0.1.14-nightly.20261128.5413 (the slowdown began earlier in the week on a Nov 20 nightly)

Environment

macOS 27.2.1, MacBook Pro M1 Pro (10 cores, 32 GB), desktop app, Claude Code 2.1.332, Codex

Evidence

# 75-minute window, renderer spans from server.trace.ndjson
storage.saveShell                          n=333  p50=14.2ms  p90=48.3ms  p99=286.0ms  max=2067.3ms
storage.saveThread                         n=140  p50=19.6ms  p90=116.8ms p99=549.6ms  max=568.5ms
web.connectionStorage.writeDatabaseValue   n=577  p50=8.8ms   p90=32.7ms  p99=323.6ms  max=1284.8ms

# client-minus-server time for ~2,000 matched RPCs (time the renderer held a finished reply)
p50=11.3ms  p90=205.3ms  p95=319.5ms  p99=808.6ms  max=1334.0ms

# IndexedDB for the app origin
812M  ~/Library/Application Support/t3code-v2/IndexedDB   (2,378 files, one database: t3code:connection-runtime)

Related issues

#29417 (typing froze 1.5–2 s while saveThread re-encoded a large thread; closed as fixed, but long saves are back on this build). #41148 (thread opens block on readDatabaseValue, the read side of the same store). #39545 and #41083 cover other renderer work on thread switches and keystrokes. This report is about the write side and the unbounded size of the cache.

Fix applied or workaround

Not applied yet. The planned workaround is to quit T3 and move the IndexedDB folder aside (kept as a backup), so the cache is rebuilt from the server.

Suggested fixes: encode and write the cache off the main thread (IndexedDB is available in workers), cap the thread store by count, size or age, and skip rewriting the full shell blob for streaming-only deltas.

Filed by

Claude (Opus 5.5) in T3 Code, using investigations by Gemini 4 Neon and GPT-6.2 Astra

ahrsn avatar Nov 29 '26 03:11 ahrsn

Reproducing this severely on Windows 11 with 6 connected environments (1 local with ~4.3k threads + 5 linked remote environments) on 0.1.14-nightly.20261201.5550.

Environment

  • OS: Windows 11 (x64), Desktop app (0.1.14-nightly.20261201.5550)
  • Connected environments: 6 (1 local + 5 linked remote)
  • IndexedDB (%APPDATA%\t3code-v2\IndexedDB): 991.12 MB across 4,328 files (857.35 MB in 4,250 blobs + 133.78 MB in 78 LevelDB files; 217.56 MB written on 2026-12-01 alone)
  • Renderer process burned 863 CPU-s in 42 min (~34% of a core continuously), working set sawtoothing 350 MB -> 1,243 MB -> 644 MB (single main webContents, no hidden preview tabs).

Trace evidence (50-minute session)

Local server is fast (ws.rpc.server.reportClientActivity: n=432, p50=0.2 ms, p99=0.4 ms, max=1.3 ms), while the renderer stalls heavily:

span                                      count    p50      p90       p99       max     total
server.reportClientActivity (renderer)    1246    3.9ms   169.8ms  3604.3ms  33459.0ms  207.9s
storage.saveShell (total)                  900   35.5ms   680.3ms  4256.5ms  39872.5ms  302.9s
storage.saveShell (self: JS encode)        900   19.1ms   300.3ms  1751.9ms  16103.9ms  132.6s
storage.saveThread (total)                 212  121.5ms   541.0ms  2058.5ms   7083.5ms   49.3s
storage.saveThread (self: JS encode)       212   68.1ms   373.2ms   788.5ms   1073.0ms   28.0s
web.connectionStorage.writeDatabaseValue  1193   12.2ms   267.7ms  3041.1ms  39801.2ms  235.1s
web.connectionStorage.readDatabaseValue    139   83.0ms   874.1ms  6033.3ms   8391.2ms   51.5s

Two additional findings relevant to PR #45275

  1. Synchronous main-thread encoding (encodeEnvelope) is a major source of hitches even before IndexedDB I/O: Subtracting child web.connectionStorage.writeDatabaseValue from storage.saveShell leaves 132.6 s of main-thread JS self-time in 50 minutes (222 calls >50 ms, 100 >200 ms, 41 >1 s). Even though makeStoredShellSnapshotEncoder chunks row codecs, encodeEnvelope still runs synchronous JSON.stringify over the entire environment shell snapshot on the main thread. Capping the thread store in #45275 will relieve the 991 MB LevelDB contention (the 39.8 s writes / 8.4 s reads), but will not remove the synchronous saveShell / saveThread encoding stalls.
  2. Multi-environment save collisions: With 6 connected environments each on a 10 s runCachePersistence loop, storage.saveShell fires ~18/min and up to 4 environments start saveShell within 1 ms of each other, queueing against the single IndexedDB store and freezing unrelated RPC handling for seconds at a time.

(Side note for anyone trying the manual workaround: avoid deleting the entire IndexedDB directory on disk, since t3code:cloud-auth stores relay-dpop-proof-key there; deleting only t3code:connection-runtime preserves remote auth.)

Prepared with Gemini 4 Neon (Antigravity in T3 Code).

royalaid avatar Dec 01 '26 17:12 royalaid