From bb9af4d6b606e28c0cc969f660b7038e5807169e Mon Sep 17 00:00:00 2001 From: AndyS77 Date: Tue, 15 Sep 2026 22:01:40 +0200 Subject: [PATCH] fix(turbo): limit concurrency on Windows to prevent tsgo OOM tsgo crashes with fatal error: out of memory (errno=1455) when turbo runs 30 typecheck tasks in parallel on heavily loaded Windows machines. The Go runtime allocates ~84 MB committed memory per process during startup; with 30 parallel processes the combined spike can exceed the remaining commit budget (RAM + pagefile). Add script/turbo.ts that calculates safe concurrency at runtime: concurrency = max(1, min(cpuCount, floor(freeMB / 100))) Windows-only; other platforms pass through to turbo unchanged. Closes #49224 Co-Authored-By: opencode Agent: @bug-fix Model: msp-crow/zai-glm-52 Scope: #49224 --- package.json | 2 +- script/turbo.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 script/turbo.ts diff --git a/package.json b/package.json index a3f9544410da..058e5c0ecf19 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "dev:stats": "bun sst shell --stage=production -- bun run --cwd packages/stats/app dev", "dev:storybook": "bun --cwd packages/storybook storybook", "lint": "oxlint", - "typecheck": "bun turbo typecheck", + "typecheck": "bun run script/turbo.ts typecheck", "upgrade-opentui": "bun run script/upgrade-opentui.ts", "postinstall": "bun run --cwd packages/core fix-node-pty", "prepare": "husky", diff --git a/script/turbo.ts b/script/turbo.ts new file mode 100644 index 000000000000..46d8829b02e3 --- /dev/null +++ b/script/turbo.ts @@ -0,0 +1,33 @@ +#!/usr/bin/env bun + +import { $ } from "bun" +import os from "os" + +// tsgo (TypeScript-Go) peaks at ~84 MB committed memory per process during startup. +// On Windows, the commit limit (RAM + pagefile) can be nearly exhausted by other processes. +// Running 30 tsgo processes in parallel can exceed the remaining commit budget, causing +// fatal OOM crashes (errno=1455). This script limits turbo's concurrency based on available +// commit memory to prevent that. See https://github.com/anomalyco/opencode/issues/49224. +const MB_PER_PROCESS = 100 + +function computeConcurrency(cpuCount: number, freeMB: number) { + return Math.max(1, Math.min(cpuCount, Math.floor(freeMB / MB_PER_PROCESS))) +} + +const task = process.argv[2] +if (!task) { + console.error("Usage: bun run script/turbo.ts [extra turbo args...]") + process.exit(1) +} + +const extraArgs = process.argv.slice(3) + +if (process.platform === "win32") { + const freeMB = Math.floor(os.freemem() / (1024 * 1024)) + const cpuCount = os.availableParallelism() + const concurrency = computeConcurrency(cpuCount, freeMB) + console.log(`turbo ${task}: concurrency=${concurrency} (cpus=${cpuCount}, free=${freeMB}MB)`) + await $`bun turbo ${task} --concurrency=${concurrency} ${extraArgs}` +} else { + await $`bun turbo ${task} ${extraArgs}` +}