tsgo crashes with OOM on Windows when turbo typecheck runs in parallel on heavily loaded machines
Description
tsgo (@typescript/native-preview) crashes with fatal error: out of memory when bun turbo typecheck runs 30 packages in parallel on Windows. The root cause is Windows commit limit exhaustion: the Go runtime allocates committed memory proportional to the number of parallel processes, and when the system commit limit (RAM + pagefile) is nearly exhausted by other processes, the parallel startup spike exceeds the remaining commit budget.
This only affects machines that are heavily loaded. On systems with plenty of free commit memory, unlimited parallelism works fine.
Root cause analysis:
The Go runtime GC grows the heap based on GOGC (default: 100, meaning heap doubles before GC triggers). Per the Go GC guide (https://tip.golang.org/doc/gc-guide), each Go process reserves ~700 MB of virtual address space on 64-bit, but this is not committed. The actual committed memory (private bytes) per tsgo process peaks at ~84 MB during startup (measured), then settles to ~19 MB steady-state working set.
tsgo --checkers (default: CPU count) further multiplies memory per process — microsoft/typescript-go#4201: "More threads does mean more memory consumption" and "each checker re-instantiates the shared library surface."
When turbo runs 30 tsgo processes in parallel with no concurrency limit, the combined startup spike (30 × ~84 MB = ~2.5 GB committed) can exceed the available commit budget.
Measured data (Windows 11, 16 GB RAM, 16 GB pagefile, 32 GB total commit, system at ~94% commit):
t=0s: 18 tsgo processes, 180 MB private, 468 MB free commit
t=2s: 20 tsgo processes, 561 MB private, 64 MB free commit → STACK OVERFLOW (errno=1455)
t=4s: 19 tsgo processes, 747 MB private, 24 MB free commit → crash
t=6s: tsgo exited, 1871 MB free commit → recovered
Per-process peak (top 5, during startup spike):
PID WorkingSet PrivateMem
52992 56.8 MB 64.3 MB
44236 51.3 MB 57.0 MB
60108 40.8 MB 47.0 MB
49660 35.7 MB 40.9 MB
34344 35.8 MB 40.5 MB
After reboot (6.7 GB free commit): bun turbo typecheck with no limit succeeds — 8/30 tasks pass, no OOM. The 22 failures are genuine TS errors (e.g. Cannot find module 'bun:test'), not memory crashes.
With only 215 MB free commit (heavy system load), even --concurrency=2 crashes.
Proposed fix:
A dynamic concurrency limit script (script/typecheck.ts) that calculates safe parallelism at runtime:
concurrency = max(1, min(cpuCount, floor(freeCommitMB / 100)))
Where:
cpuCount— upper bound (no point running more processes than CPUs; avoids context-switching overhead when memory is plentiful)freeCommitMB— available commit memory, measured via OS APIs (os.freemem()as proxy on Windows, or WMIWin32_OperatingSystem.FreeVirtualMemory)100 MB— conservative per-process startup spike estimate, derived from:- Measured peak private memory per tsgo process: ~84 MB
- Go GC guide: GOGC default = 100 → heap doubles before GC; base live heap ~40 MB × 2 = ~80 MB
- Rounded up to 100 MB for safety margin
This replaces bun turbo typecheck in the typecheck script in package.json:
"typecheck": "bun run script/typecheck.ts"
This only matters on heavily loaded machines. On systems with ample free commit (e.g. >2 GB), the formula yields min(cpuCount, floor(freeCommitMB/100)) which typically equals cpuCount — no change in behavior. The limit only kicks in when memory is scarce.
Related upstream issues:
- golang/go#75407 (closed, "not planned") — Go runtime
errno=1455on Windows - golang/go#75417 (open) — umbrella issue for Windows paging file exhaustion
- microsoft/typescript-go#4201 — tsgo peak RSS scales with
--checkers - microsoft/typescript-go#1622 — tsgo
--builduses extreme amounts of memory;--singleThreadedand--maxConcurrentProjectsas mitigations
Plugins
N/A (development tooling issue)
OpenCode version
dev branch (commit 228e909)
Steps to reproduce
- On Windows 11 with heavy memory usage (e.g. 6+ opencode instances, Outlook, Edge — system at ~94% commit, <500 MB free)
- Run
bun turbo typecheckfrom repo root - tsgo processes crash with
fatal error: out of memory/errno=1455/STATUS_STACK_BUFFER_OVERRUN - All 30 typecheck tasks fail (0 successful)
Verification:
- After reboot (6.7 GB free):
bun turbo typechecksucceeds (no OOM), only genuine TS errors remain - With
--concurrency=4and >400 MB free: no OOM crashes - With 215 MB free: even
--concurrency=2crashes
Screenshot and/or share link
N/A
Operating System
Windows 11 (16 GB RAM, 16 GB pagefile, 32 GB total commit limit, 8 CPUs)
Terminal
Windows Terminal / PowerShell 7
Thanks for the detailed measurements and the proposal, @AndyS77!
What you're asking for is a memory-aware concurrency limit for the repo's root typecheck script, so bun turbo typecheck doesn't start more type-check processes than the machine's free commit memory allows on heavily loaded Windows machines.
The local typecheck setup on dev has changed since commit 228e909:
- The root script is now
bun turbo typecheck --concurrency=3. - Since #58253, each package's local
typecheckrunsbun checkinstead of tsgo. tsgo/tsc is only used in CI now.
If you can, please re-run bun run typecheck on the latest dev under similar memory pressure and let us know whether it still runs out of memory. That will show whether a dynamic limit is still needed.
I've marked this as a feature request for maintainers to consider. I can't promise whether or when it will be picked up.
Follow-up to the request for measurements with --concurrency=3 and bun check: we observed a machine-wide stall with that setup. This is a WSL2 memory-reclaim case, not the original native Windows tsgo error.
Setup: OpenCode checkout based on v2.3.2, Bun 1.4.4, Turbo 2.10.2. WSL2 had a 12 GiB limit and no swap. A Roslyn server (~1.7 GiB) and five test database containers (~2.1 GiB combined) were already resident. An agent explicitly invoked bun run check in the source checkout. Lint handed off to bun turbo typecheck --concurrency=3; core, simulation and tui all logged cache misses and started bun check.
Observed: available guest memory fell to 317 MiB. A nominal 10-second sampler took 3 h 7 min to return. Across the samples bracketing the stall, the kernel's cumulative memory PSI full counter increased by 10,785 seconds (~96% of the interval), with 4.35 million major page faults and no increase in oom_kill. A development machine can become unusable long before there is an OOM error for the checker to report.
Workaround that completed on this machine: run bun turbo typecheck --concurrency=1 directly from the repo root. For the full check, run bun run lint && bun turbo typecheck --concurrency=1. The serial typecheck after recovery finished 35/35 tasks in 27.3 s (29 cache hits). This was a warm-cache retry with different memory headroom, not a controlled benchmark or a guarantee that one checker always fits.
Suggested fix: keep 3 as the normal default, but let developers set TURBO_CONCURRENCY=1 for the existing bun run check entry point. The hard-coded CLI flag currently takes precedence over the environment. Have the root typecheck script use the configured limit when supplied and fall back to 3 only when unset; document the serial command in the contributor guide. That would also cover checks invoked by agents and hooks without changing CI parallelism.