Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: bound local pregate Vitest workers so concurrent worktree gates stop starving each other (#9773)
[._.]/ Adam Eivy60dc8d18b2e7
diff --git a/docs/GITHUB_ACTIONS.md b/docs/GITHUB_ACTIONS.mdindex b46091dcfe..dc8a32d38b 100644--- a/docs/GITHUB_ACTIONS.md+++ b/docs/GITHUB_ACTIONS.md@@ -139,7 +139,11 @@ On GitHub Actions, `CI=true` caps the server Vitest runner at `maxWorkers: 4``client/vitest.config.js`). Standard Linux runners for public repositories are[4 vCPU / 16GB](https://docs.github.com/en/actions/reference/runners/github-hosted-runners);uncapped forks oversubscribe those cores during transform. Local `npm test`-is unbounded. The DOM-heavy client retains its proven two-worker override:+is unbounded. `npm run pregate` exports `PORTOS_PREGATE_MAX_WORKERS` (default 4,+overridable) so concurrent worktree gates on one host bound their Vitest+workers; it can only lower a workspace's cap (client stays at 2), and direct+test runs ignore it unless you set it. Divide the host between simultaneous+gates, e.g. `PORTOS_PREGATE_MAX_WORKERS=2 npm run pregate`. The DOM-heavy client retains its proven two-worker override:four workers made its async rendering assertions timing-dependent under CIcontention. File-level parallelism stays on; the DB suite already serializesfiles because those tests share one Postgres.diff --git a/scripts/pregate.js b/scripts/pregate.jsindex 45af1d2bc7..d24013c50b 100644--- a/scripts/pregate.js+++ b/scripts/pregate.js@@ -56,6 +56,17 @@ export const UNCOVERED_SUITES = Object.freeze({smoke: 'npm run smoke',});+/** Local pregate worker budget per Vitest workspace; see scripts/vitestCiPool.js. */+export const PREGATE_DEFAULT_MAX_WORKERS = '4';++/**+ * Env for a stage child: bound Vitest workers unless the operator chose a+ * budget. Direct `npm test` never passes through here, so it stays unbounded.+ */+export function pregateWorkerEnv(env) {+ return { ...env, PORTOS_PREGATE_MAX_WORKERS: env.PORTOS_PREGATE_MAX_WORKERS || PREGATE_DEFAULT_MAX_WORKERS };+}+/*** The ordered stages to run for a plan, each a spawnable command.*@@ -268,7 +279,7 @@ function main() {const result = spawnSync(process.execPath, [join(REPO_ROOT, 'scripts', stage.script), ...stage.args], {cwd: REPO_ROOT,stdio: 'inherit',- env: { ...process.env, ...stage.env },+ env: { ...pregateWorkerEnv(process.env), ...stage.env },});if (result.error) {console.error(`❌ ${stage.name} could not start: ${result.error.message}`);diff --git a/scripts/pregate.test.js b/scripts/pregate.test.jsindex c9bd5853c6..fb5f9f97da 100644--- a/scripts/pregate.test.js+++ b/scripts/pregate.test.js@@ -25,6 +25,7 @@ import {resolvePlanStages,downgradeFullPlan,parseArgs,+ pregateWorkerEnv,UNCOVERED_SUITES,unmergedIndexPaths,} from './pregate.js';@@ -243,6 +244,13 @@ describe('pregate hidden-content invocation', () => {});});+describe('pregateWorkerEnv', () => {+ it('bounds workers by default but honors an operator budget', () => {+ expect(pregateWorkerEnv({}).PORTOS_PREGATE_MAX_WORKERS).toBe('4');+ expect(pregateWorkerEnv({ PORTOS_PREGATE_MAX_WORKERS: '2' }).PORTOS_PREGATE_MAX_WORKERS).toBe('2');+ });+});+describe('downgradeFullPlan', () => {it('replaces the full suite with the tracked always-run guards', () => {const tracked = ALWAYS_RUN_TESTS.slice(0, 3);diff --git a/scripts/vitestCiPool.js b/scripts/vitestCiPool.jsindex 65c50e2397..f47a216710 100644--- a/scripts/vitestCiPool.js+++ b/scripts/vitestCiPool.js@@ -3,6 +3,9 @@* repositories are 4 vCPU / 16GB; uncapped forks oversubscribe those cores* during transform and swap.* Local `npm test` stays unbounded so a developer machine can use every core.+ * `npm run pregate` is the exception: it exports PORTOS_PREGATE_MAX_WORKERS so+ * several concurrent worktree gates share one host budget (#9773). The value+ * can only LOWER a workspace's cap, never raise it past the proven one.** fileParallelism stays at Vitest's default (true): four workers stay busy on* independent files. The DB suite already serializes files because those@@ -11,8 +14,10 @@* Vitest 5 exposes `maxWorkers` only — there is no `minWorkers` / `minThreads`.*/export function vitestCiPool({ maxWorkers = 4 } = {}) {- if (!process.env.CI) return {};- return { maxWorkers };+ if (process.env.CI) return { maxWorkers };+ const raw = process.env.PORTOS_PREGATE_MAX_WORKERS;+ const pregate = /^[1-9]\d*$/.test(raw ?? '') ? Number(raw) : null;+ return pregate === null ? {} : { maxWorkers: Math.min(maxWorkers, pregate) };}// Keep these public Chrome/ffmpeg contracts in the full/CI runner, but givediff --git a/scripts/vitestCiPool.test.js b/scripts/vitestCiPool.test.jsindex bc44ffc060..3210ff6801 100644--- a/scripts/vitestCiPool.test.js+++ b/scripts/vitestCiPool.test.js@@ -9,10 +9,35 @@ import { vitestCiPool } from './vitestCiPool.js';describe('vitestCiPool', () => {const original = process.env.CI;+ const originalPregate = process.env.PORTOS_PREGATE_MAX_WORKERS;+ const restore = (key, value) => {+ if (value === undefined) delete process.env[key];+ else process.env[key] = value;+ };afterEach(() => {- if (original === undefined) delete process.env.CI;- else process.env.CI = original;+ restore('CI', original);+ restore('PORTOS_PREGATE_MAX_WORKERS', originalPregate);+ });++ it('bounds local pregate workers, never above the workspace cap', () => {+ delete process.env.CI;+ process.env.PORTOS_PREGATE_MAX_WORKERS = '3';+ expect(vitestCiPool()).toEqual({ maxWorkers: 3 });+ expect(vitestCiPool({ maxWorkers: 2 })).toEqual({ maxWorkers: 2 });+ process.env.PORTOS_PREGATE_MAX_WORKERS = '16';+ expect(vitestCiPool()).toEqual({ maxWorkers: 4 });+ });++ it('ignores a malformed pregate budget and lets CI win', () => {+ delete process.env.CI;+ for (const bad of ['0', '-1', 'abc', '2.5', '']) {+ process.env.PORTOS_PREGATE_MAX_WORKERS = bad;+ expect(vitestCiPool()).toEqual({});+ }+ process.env.CI = 'true';+ process.env.PORTOS_PREGATE_MAX_WORKERS = '1';+ expect(vitestCiPool()).toEqual({ maxWorkers: 4 });});it('leaves local runs unbounded', () => {