[Bug]: Opening a thread freezes the desktop renderer for ~1 min when there are ~13k threads: `environment-quiet-thread-shell-list` rebuilds ~14k times over every thread #25823
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/web
Steps to reproduce#
- Have an environment with many threads. Here: 13,037 threads, 10,113 of them
thread:delegated-task:*subagent threads, ~11k under one long-running orchestration thread (15,884 turn items, 1,481 runs, 872 subagent items). - In the desktop app, switch from another thread to that orchestration thread.
Expected behavior#
The thread opens within a second or two; the rest of the UI stays responsive.
Actual behavior#
The whole window freezes for 53–58 s, then recovers. CPU sampling during the freeze:
- Server: about 2 s of work (00:46:06–07), then idle.
- Renderer: one core pinned at 100% for 53 s (00:46:08–00:47:01). Memory rises steadily from 650 to 707 MB.
A DevTools Performance recording shows one 58.4 s task: 58.7 s scripting, 0.6 s rendering. Aggregating the recording's samples by function:
WebSocket message handler invocations during the task | ~2,900 |
Rebuilds of environment-quiet-thread-shell-list | ~14,400 (≈5 per message) |
| Median cost per rebuild | 3.4 ms (iterates all 13,037 thread refs) |
| Total time inside that atom's read function | 54.0 s of 56.4 s |
The path is the same for ~80% of all samples:
WebSocket message → decode → Effect fiber runLoop → onSuccess → resume
→ stream atom setSelf → setValue → announce → invalidateChildren → invalidate → build
→ quietThreadShellsAtom read fn (packages/client-runtime/src/state/threadShell.ts)
Self time below it is all atom-registry overhead from the per-thread get(quietThreadShellAtomFamily(threadKey(ref))) calls:
| Self time | Where (0.1.3 bundle) |
|---|---|
| 26.7 s | MutableHashMap get (Atom.family lookup) |
| 9.1 s | Option helpers on the family's WeakRef deref |
| 7.1 s | readTracked |
| 4.7 s | ensureNode |
| 3.8 s | threadKey |
Why it's quadratic#
quietThreadShellsAtomwalks every thread ref, including archived and subagent threads, on each rebuild.- Each
threadShellAtomFamily(key)reads the wholeenvironmentThreadIndexAtom(environmentId). So any change to the index invalidates all ~13k shell atoms and their quiet wrappers, and the list rebuilds several times per message. - The ~2,900 messages are applied one at a time, synchronously, inside a single task, with no batching between them.
Cost ≈ messages × rebuilds per message × total thread count. Small installs never notice. Heavy orchestration users get thousands of subagent threads quickly.
I couldn't confirm which stream the ~2,900 messages belong to. They arrive on the WebSocket right after the switch, and each one ends in a setSelf on a stream-backed atom that feeds the thread index. Server traces in the same window show ~450 branch PR lookups (ThreadPullRequestServiceV2.synchronize) but only ~50 EventSink.writes, so PR discovery alone doesn't explain the message count.
Possible fixes#
- Batch inbound stream items: one registry batch per WebSocket frame or animation frame, instead of a synchronous rebuild per item.
- Make per-thread shell atoms depend on per-thread data, for example a per-thread family over the index, so one thread's update doesn't invalidate all 13k shells.
- Keep subagent and archived threads out of list atoms that don't display them, or index the list incrementally instead of rebuilding it from all refs.
Impact#
Major degradation or frequent failure
Every switch to the large thread costs about a minute of a fully frozen window. Thread count only grows, since each delegated task adds a thread.
Version or commit#
T3 Code desktop 0.1.3 (AppImage). The relevant source is unchanged on main as of 2026-10-27; threadShell.ts and threads.ts show no diff against v0.1.3.
Environment#
- Arch Linux (Omarchy), kernel 7.2.8, Hyprland/Wayland.
- AMD Ryzen 9 9950X; NVMe SSD.
- Providers: Claude + Codex, heavy use of delegated subagent tasks.
Logs or stack traces#
Aggregated profile numbers are above. I can share the raw trace on request; it includes screenshots of my workspace, so I'd rather not attach it publicly.
Screenshots, recordings, or supporting files#
No response
Workaround#
None besides avoiding the thread. Starting a fresh orchestration thread helps only until it accumulates its own subagents. Deleting old subagent threads should reduce the cost proportionally.
Follow-up: a second live macOS 0.1.3 freeze is now localized to this exact atom, rather than inferred only from the synthetic case.
DevTools paused the busy main renderer at
runtime-78TAXKYj.js:2:91914. Reading the matching asset from the installed signed release places that column atl(Z(n))in:_=T(e=>{let t=[];for(let n of e(p)){let r=e(l(Z(n)));r!==null&&t.push(r)}return Ns(g,t)?g:(g=t,t)}).pipe(j(`environment-quiet-thread-shell-list`))The installed asset SHA256 is
4adda3fdf68d109ca74762de1e87c20bc0e3ae93df91920a09168f32e4cc58b9. The selected frame's partially built output array already held 9,505 entries; that is not the total list count. The surrounding stack repeatedly alternatesbuild → value → propagate → invalidate → invalidateChildren → setValue; below it aresetSelf, notification delivery, EffectresumeandrunLoop. Private reference IDs were omitted.The renderer was at about 99–100% CPU while main/backend remained responsive. A frontend Force Reload completed but immediately returned to the same high-CPU condition. Terminating only the verified main renderer let the existing official recovery handler recreate it; main and backend PIDs were unchanged, the new UI loaded, and renderer CPU was 2.6% after 26 seconds. This was temporary recovery, not deployment of #25853. No production bundle or database was modified.
This live pause confirms that the quiet-shell aggregate is involved in the recurrent freeze. It does not yet quantify its exclusive share of CPU or exclude other contributing paths. The user confirmed that an earlier occurrence recovered by itself without reloading.
Another reproduction on v0.1.6 (stable), at larger scale
- Surface: macOS desktop app 0.1.6 (Electron 44) connected to a remote Linux x64 server 0.1.6 (boot service, Node 26.12.1),
statev2.sqliteabout 84 GB. - Thread: one long-running orchestration thread with 21,015 descendant subagent threads, 14,061 of them not archived (environment total: 38,049 threads, 16,790 active). It also has 13,106 messages, 40,646 turn items, 3,774 runs, 1,406 subagent rows and 155 linked PRs.
- Repro: switch to that thread from any other thread. The whole desktop window freezes for about a minute, then recovers. It happens every time, and other threads are unaffected.
- Server side is fast:
ws.orchestrationV2.subscribeThread≤1.4 s,ws.rpc.orchestration.getThreadFamily≤5.9 s,ShellStream.loadShellSnapshotParts≤6.5 s. The freeze is client-side, consistent with theenvironment-quiet-thread-shell-listanalysis above. - Contributing factor:
getThreadFamilyreturns every non-archived descendant with no limit (ProjectionStore.tsfamily query, v0.1.6). The client then merges them all into the environment thread list. Archive does not cascade from the parent, and settling doesn't remove children from the family read. - Code check: the quiet-list loop is unchanged on
mainas of 2026-11-02, so this still reproduces on current nightlies by code inspection. #25853 is still open.
Produced by Claude Code (Claude Opus 5.5) via
t3 triage.- Surface: macOS desktop app 0.1.6 (Electron 44) connected to a remote Linux x64 server 0.1.6 (boot service, Node 26.12.1),
tanstack-source added labelsbug
Note
🤖 Claude Opus 5.5 responding on behalf of @mfattakhov
Seeing the same shape at a much smaller scale on
0.1.11-nightly.20261117.4825(macOS desktop): 2,357 active threads, thread switches take 0.7–1.6 s while several agents stream, and about 10 ms when they don't. The installed bundle still has the per-thread loop inenvironment-quiet-thread-shell-list, and #25853 was closed without merging.From
server.trace.ndjson, which includes the client spans:EnvironmentCommands.visitThreadran 7–20 ms for ten minutes, then 150–570 ms once agent activity rose, peaking at 1,478, 1,613 and 703 ms on three consecutive thread switches.- The step lines up with agent traffic:
ClaudeAgentSdkQueryRunner.trackDescendantswent from 1.0 to 3.2/s,orchestrationV2.EventSink.providerBatchfrom 0.8 to 1.9/s, and total spans from 43 to 114/s. web.connectionStorage.readDatabaseValue, normally under 1 ms, took 400–850 ms, with batches of reads finishing at the same instant. That reads as a blocked renderer main thread rather than slow IndexedDB.- The main renderer working set swung between 300 and 920 MB every 30 s (
renderer-history.ndjson).
A fresh headless client on the same server, opened about ten minutes later, switched between threads in 77–138 ms. The window that degrades is the long-lived one (1 d 20 h uptime). I haven't profiled that window, so tying it to this atom is inference from the matching shape: renderer busy, cost rising with message rate.
Sign in to join this conversation.
Independent reproduction on v0.1.3 (
d2c440312e5f39d59827ed466838a623516454d6), plus before/after validation of #25853. A single snapshot update can reproduce a long synchronous stall; thousands of WebSocket frames are not required.Reproduction and measurements#
The attached script imports the real
createEnvironmentThreadShellAtoms, the existing synthetic fixtures,PrimaryConnectionTarget, and the real shell reducer. It mounts the quiet list as a subscriber, then updates synthetic thread titles. It does not use a server, provider, credentials, or private conversations. Timings coverregistry.setand synchronous subscriber delivery, excluding fixture construction and initial mount.macOS 26.7, Apple Silicon, Node 26.0.0, Effect 4.0.5, release lockfile. All rows change in the bulk cases; the five-row case changes only five existing objects in a single published snapshot. These are state-layer timings, not whole-app frame-rate measurements.
The patched ranges are three consecutive updates in a fresh process. The 12k baseline ran with Node CPU profiling enabled; the other timing rows did not. These are a few local measurements, not a statistical benchmark. As a control, the existing non-quiet
threadShellsAtomhandles the 26,138/all case in approximately 33 ms both before and after.The synthetic 12k CPU profile also matches this issue's reported hot path: about 37.9% self time in MutableHashMap lookup, 25.4% in readTracked, and 18.7% in Atom.family lookup. The quiet list at
threadShell.ts:394is above these calls. A 4k profiled run reproduced the same stall in 3,526 ms.Why this produces a freeze#
Each changed per-thread atom invalidates the aggregate quiet list while the shared snapshot is still propagating. Each rebuild walks all thread references. One snapshot changing K threads therefore does roughly K × N list work and publishes intermediate, partially updated lists. For a full replacement this becomes quadratic. Because
registry.setcompletes this synchronously, the renderer cannot process input during that work.#25853 fixes this by building the quiet list directly from each environment's thread array and keeping the previous quiet shell per thread, instead of subscribing the aggregate to every per-thread atom. It preserves the streaming hold behavior while publishing the completed list once. This is validation of the existing PR, not a competing implementation.
Regression validation#
Applied only #25853's test first:
delivers one quiet shell list per snapshot update that changes several threadsfails on v0.1.3, receiving three lists for one three-thread update, including two partially updated states. After applying its production change:At inspected
maincommit0894156d9a38eeff8abfd9c266f3f57b8e524217, the aggregate still loops overthreadRefsAtomand readsquietThreadShellAtomFamilyper thread. I did not run the full benchmark or typecheck on that newer main.Runnable synthetic case#
In a disposable checkout, with the script below saved outside it as
repro-quiet-shell.mjs:Apply #25853's two-file diff (tested PR head
da9db8b08b16130745600e1aa682bcdb24850884) to this disposable checkout and repeat. No running T3 install needs modification.Complete reproduction script
Relation to the original live incident#
The motivating incident was a signed macOS 0.1.3 desktop whose renderer stayed near one CPU core while the main process and local/remote backend descriptors remained responsive. The window eventually recovered without a reload. Its remote database has about 26k thread rows, but the active client shell cardinality was not measured and shell filtering can reduce it. The live native sample did not resolve JavaScript function names. Thus this confirms the source defect and the candidate patch, but does not prove this path was the sole cause of that particular live freeze. No private logs or conversation content are attached, and a patched production desktop was not deployed.
Prepared and verified with OpenAI Codex (GPT-6), through the Codex desktop harness.