Skip to content

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

ci: cap Vitest workers and cache transforms on GitHub Actions (#4395)

[._.]/ Adam Eivyf1ee30f31e41
diff --git a/.changelog/next/changed-issue-4395.md b/.changelog/next/changed-issue-4395.md
new file mode 100644
index 0000000000..525ea0cc0e
--- /dev/null
+++ b/.changelog/next/changed-issue-4395.md
@@ -0,0 +1 @@
+- CI caps Vitest at two workers on GitHub Actions and reuses the Vite transform cache between runs.
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 4ee5a6bdce..78c71a0d13 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -103,6 +103,20 @@ jobs:
- name: Install server dependencies
run: npm ci --prefix server
+ # After npm ci: it wipes node_modules, so a pre-install restore is lost.
+ # Vite/Vitest write transform artifacts under node_modules/.vite (and
+ # historically .vitest). Reusing them skips re-transforming unchanged files.
+ - name: Cache Vitest transform artifacts
+ uses: actions/cache@v4
+ with:
+ path: |
+ server/node_modules/.vite
+ server/node_modules/.vitest
+ key: vitest-server-${{ runner.os }}-${{ hashFiles('server/package-lock.json', 'server/vitest.config.js', 'scripts/vitestCiPool.js') }}
+ restore-keys: |
+ vitest-server-${{ runner.os }}-${{ hashFiles('server/package-lock.json') }}-
+ vitest-server-${{ runner.os }}-
+
# server/.npmrc pins ignore-scripts=true, so the native deps npm skipped
# need the explicit allowlist rebuild to be usable (node-pty et al).
# Always-run-only plans (prompt-upgrade + changelog fragment guards)
@@ -149,6 +163,17 @@ jobs:
- name: Install client dependencies
run: npm ci --prefix client
+ - name: Cache Vitest transform artifacts
+ uses: actions/cache@v4
+ with:
+ path: |
+ client/node_modules/.vite
+ client/node_modules/.vitest
+ key: vitest-client-${{ runner.os }}-${{ hashFiles('client/package-lock.json', 'client/vitest.config.js', 'scripts/vitestCiPool.js') }}
+ restore-keys: |
+ vitest-client-${{ runner.os }}-${{ hashFiles('client/package-lock.json') }}-
+ vitest-client-${{ runner.os }}-
+
- name: Lint client
if: needs.impact.outputs.lint_mode != 'skip'
env:
@@ -205,6 +230,17 @@ jobs:
- name: Install server dependencies
run: npm ci --prefix server
+ - name: Cache Vitest transform artifacts
+ uses: actions/cache@v4
+ with:
+ path: |
+ server/node_modules/.vite
+ server/node_modules/.vitest
+ key: vitest-server-${{ runner.os }}-${{ hashFiles('server/package-lock.json', 'server/vitest.config.js', 'server/vitest.config.db.js', 'scripts/vitestCiPool.js') }}
+ restore-keys: |
+ vitest-server-${{ runner.os }}-${{ hashFiles('server/package-lock.json') }}-
+ vitest-server-${{ runner.os }}-
+
# server/.npmrc pins ignore-scripts=true — DB suites that touch sharp /
# node-pty still need the explicit allowlist rebuild.
- name: Rebuild trusted native dependencies
@@ -214,7 +250,14 @@ jobs:
run: npm run setup:db:test --prefix server
- name: Run DB-backed tests (portos_test)
- run: npm run test:db:ci --prefix server
+ run: |
+ set +e
+ start=$(date +%s)
+ npm run test:db:ci --prefix server
+ status=$?
+ elapsed=$(( $(date +%s) - start ))
+ echo "⏱ server db suite: ${elapsed}s" | tee -a "$GITHUB_STEP_SUMMARY"
+ exit $status
env:
PGDATABASE: portos_test
@@ -261,6 +304,17 @@ jobs:
- name: Install server dependencies
run: npm ci --prefix server
+ - name: Cache Vitest transform artifacts
+ uses: actions/cache@v4
+ with:
+ path: |
+ server/node_modules/.vite
+ server/node_modules/.vitest
+ key: vitest-server-${{ runner.os }}-${{ hashFiles('server/package-lock.json', 'server/vitest.config.js', 'scripts/vitestCiPool.js') }}
+ restore-keys: |
+ vitest-server-${{ runner.os }}-${{ hashFiles('server/package-lock.json') }}-
+ vitest-server-${{ runner.os }}-
+
- name: Rebuild trusted native dependencies
run: node scripts/trusted-rebuilds.js server
diff --git a/client/vitest.config.js b/client/vitest.config.js
index 4dbca5c6ac..8da583cc3c 100644
--- a/client/vitest.config.js
+++ b/client/vitest.config.js
@@ -1,9 +1,12 @@
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
+import { vitestCiPool } from '../scripts/vitestCiPool.js';
+
export default defineConfig({
plugins: [react()],
test: {
+ ...vitestCiPool(),
environment: 'jsdom',
globals: true,
setupFiles: ['./src/test/setup.js'],
diff --git a/docs/GITHUB_ACTIONS.md b/docs/GITHUB_ACTIONS.md
index 9ca01c8664..10ad9cd977 100644
--- a/docs/GITHUB_ACTIONS.md
+++ b/docs/GITHUB_ACTIONS.md
@@ -26,6 +26,23 @@ plan, so no impact scope can drop it — currently
documentation-only PR therefore still runs the server job with those files
selected.
+### Vitest runner tuning
+
+On GitHub Actions, `CI=true` caps each Vitest runner at `maxWorkers: 2`
+(`scripts/vitestCiPool.js`, spread into `server/vitest.config.js` and
+`client/vitest.config.js`). Standard hosted runners are 2 vCPU / 7GB;
+uncapped forks oversubscribe those cores during transform. Local `npm test`
+is unbounded. File-level parallelism stays on for unit tests so the two
+workers stay busy; the DB suite already serializes files because those tests
+share one Postgres.
+
+Each test job restores Vite/Vitest transform artifacts
+(`node_modules/.vite`, `node_modules/.vitest`) **after** `npm ci` — install
+wipes `node_modules`, so a pre-install restore is lost. `scripts/run-ci-tests.js`
+writes Vitest wall time to the job summary so later runs can be compared
+against the pre-change full-suite job wall on `main` (2026-08-16, run
+`31951919659`): server ~300s, client+build ~467s, Windows ~463s.
+
The selected work is split across parallel jobs:
- **Server tests** — full, related, or explicit feature test files. Smoke-boots
diff --git a/scripts/ci-test-plan.js b/scripts/ci-test-plan.js
index 283a7e0e90..57628d87a6 100644
--- a/scripts/ci-test-plan.js
+++ b/scripts/ci-test-plan.js
@@ -15,6 +15,7 @@ const FULL_TRIGGER_RULES = [
{ re: /^\.github\/workflows\//, reason: 'workflow definition changed' },
{ re: /^(?:package|server\/package|client\/package)(?:-lock)?\.json$/, reason: 'dependency manifest changed' },
{ re: /^(?:server|client)\/vitest\.config(?:\.db)?\.js$/, reason: 'test runner configuration changed' },
+ { re: /^scripts\/vitestCiPool(?:\.test)?\.js$/, reason: 'test runner pool configuration changed' },
{ re: /^server\/vitest\.setup\.js$/, reason: 'server test setup changed' },
{ re: /^client\/src\/test\/setup\.js$/, reason: 'client test setup changed' },
// Biome config + its GritQL plugins (the former client/eslint.config.js). The
diff --git a/scripts/ci-test-plan.test.js b/scripts/ci-test-plan.test.js
index 37878539cd..b7c724b230 100644
--- a/scripts/ci-test-plan.test.js
+++ b/scripts/ci-test-plan.test.js
@@ -92,6 +92,7 @@ describe('CI test impact planner', () => {
'client/lint-no-random-uuid.grit',
'client/lint-react-legacy-apis.grit',
'scripts/run-ci-tests.test.js',
+ 'scripts/vitestCiPool.js',
]) {
const plan = buildCiTestPlan([path], { trackedFiles: TRACKED });
expect(plan.full, path).toBe(true);
diff --git a/scripts/run-ci-tests.js b/scripts/run-ci-tests.js
index f9159c8675..aa5ac07c50 100644
--- a/scripts/run-ci-tests.js
+++ b/scripts/run-ci-tests.js
@@ -1,6 +1,7 @@
#!/usr/bin/env node
import { spawnSync } from 'child_process';
+import { appendFileSync } from 'fs';
import { dirname, join, resolve } from 'path';
import { fileURLToPath } from 'url';
import { prepareCliSpawn } from '../server/lib/bufferedSpawn.js';
@@ -59,6 +60,15 @@ export function toRunnerPath(scope, path) {
return `../${path}`;
}
+export function recordVitestDuration(scope, label, startedAt) {
+ const seconds = ((Date.now() - startedAt) / 1000).toFixed(1);
+ const line = `⏱ ${scope} ${label}: ${seconds}s`;
+ console.log(line);
+ if (process.env.GITHUB_STEP_SUMMARY) {
+ appendFileSync(process.env.GITHUB_STEP_SUMMARY, `${line}\n`);
+ }
+}
+
function spawnNpm(scope, extraArgs, label) {
const args = ['run', 'test:ci', '--prefix', scope];
if (extraArgs.length > 0) args.push('--', ...extraArgs);
@@ -67,11 +77,13 @@ function spawnNpm(scope, extraArgs, label) {
// `shell:false` and throws EINVAL, so this script could never run on a
// Windows checkout. See server/lib/bufferedSpawn.js.
const { command, args: spawnArgs } = prepareCliSpawn('npm', args);
+ const startedAt = Date.now();
const result = spawnSync(command, spawnArgs, {
stdio: 'inherit',
env: process.env,
cwd: repoRoot,
});
+ recordVitestDuration(scope, label, startedAt);
if (result.error) {
console.error(result.error.message);
return 1;
diff --git a/scripts/run-ci-tests.test.js b/scripts/run-ci-tests.test.js
index 9c59709551..e53c7eb7b7 100644
--- a/scripts/run-ci-tests.test.js
+++ b/scripts/run-ci-tests.test.js
@@ -1,8 +1,12 @@
-import { describe, expect, it } from 'vitest';
+import { mkdtempSync, readFileSync, rmSync } from 'fs';
+import { tmpdir } from 'os';
+import { join } from 'path';
+import { afterEach, describe, expect, it } from 'vitest';
import {
listRelatedCwd,
parseVitestListOutput,
+ recordVitestDuration,
shouldSkipRelatedList,
toRunnerPath,
unionSelectors,
@@ -88,3 +92,25 @@ describe('toRunnerPath', () => {
expect(toRunnerPath('server', 'scripts/changelogFragments.test.js')).toBe('../scripts/changelogFragments.test.js');
});
});
+
+describe('recordVitestDuration', () => {
+ const originalSummary = process.env.GITHUB_STEP_SUMMARY;
+ let summaryDir;
+
+ afterEach(() => {
+ if (originalSummary === undefined) delete process.env.GITHUB_STEP_SUMMARY;
+ else process.env.GITHUB_STEP_SUMMARY = originalSummary;
+ if (summaryDir) {
+ rmSync(summaryDir, { recursive: true, force: true });
+ summaryDir = undefined;
+ }
+ });
+
+ it('writes wall time to the GitHub step summary when one is configured', () => {
+ summaryDir = mkdtempSync(join(tmpdir(), 'vitest-duration-'));
+ const summaryPath = join(summaryDir, 'summary.md');
+ process.env.GITHUB_STEP_SUMMARY = summaryPath;
+ recordVitestDuration('server', 'full suite', Date.now() - 1500);
+ expect(readFileSync(summaryPath, 'utf8')).toMatch(/^⏱ server full suite: 1\.\ds\n$/);
+ });
+});
diff --git a/scripts/vitestCiPool.js b/scripts/vitestCiPool.js
new file mode 100644
index 0000000000..04af4a8ec7
--- /dev/null
+++ b/scripts/vitestCiPool.js
@@ -0,0 +1,15 @@
+/**
+ * Vitest worker caps for GitHub Actions. Standard hosted runners are 2 vCPU /
+ * 7GB; uncapped forks oversubscribe those cores during transform and swap.
+ * Local `npm test` stays unbounded so a developer machine can use every core.
+ *
+ * fileParallelism stays at Vitest's default (true): two workers stay busy on
+ * independent files. The DB suite already serializes files because those
+ * tests share one Postgres.
+ *
+ * Vitest 4 exposes `maxWorkers` only — there is no `minWorkers` / `minThreads`.
+ */
+export function vitestCiPool() {
+ if (!process.env.CI) return {};
+ return { maxWorkers: 2 };
+}
diff --git a/scripts/vitestCiPool.test.js b/scripts/vitestCiPool.test.js
new file mode 100644
index 0000000000..08efdd488d
--- /dev/null
+++ b/scripts/vitestCiPool.test.js
@@ -0,0 +1,27 @@
+import { afterEach, describe, expect, it } from 'vitest';
+
+import { vitestCiPool } from './vitestCiPool.js';
+
+describe('vitestCiPool', () => {
+ const original = process.env.CI;
+
+ afterEach(() => {
+ if (original === undefined) delete process.env.CI;
+ else process.env.CI = original;
+ });
+
+ it('leaves local runs unbounded', () => {
+ delete process.env.CI;
+ expect(vitestCiPool()).toEqual({});
+ });
+
+ it('caps workers at 2 on CI', () => {
+ process.env.CI = 'true';
+ expect(vitestCiPool()).toEqual({ maxWorkers: 2 });
+ });
+
+ it('treats CI=1 as CI', () => {
+ process.env.CI = '1';
+ expect(vitestCiPool()).toEqual({ maxWorkers: 2 });
+ });
+});
diff --git a/server/vitest.config.js b/server/vitest.config.js
index 1fb8164e76..9cbab93bbc 100644
--- a/server/vitest.config.js
+++ b/server/vitest.config.js
@@ -1,7 +1,10 @@
import { defineConfig } from 'vitest/config';
+import { vitestCiPool } from '../scripts/vitestCiPool.js';
+
export default defineConfig({
test: {
+ ...vitestCiPool(),
testTimeout: process.platform === 'win32' ? 30000 : 10000,
// hookTimeout tracks testTimeout for the same reason: Windows fs + module
// resolution is markedly slower, and vitest's 10s DEFAULT applies to hooks