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

fix: disable Node's compile cache for the server test run (#9051)

[._.]/ Adam Eivy1c3103ff1427
diff --git a/server/envExampleDrift.test.js b/server/envExampleDrift.test.js
index d530bc17bf..c4699167ea 100644
--- a/server/envExampleDrift.test.js
+++ b/server/envExampleDrift.test.js
@@ -106,6 +106,7 @@ const INHERITED_ENV = {
TMP: 'OS temp-dir convention, pointed at a run-scoped root by vitest.config.js (#9032)',
TEMP: 'OS temp-dir convention, pointed at a run-scoped root by vitest.config.js (#9032)',
PORTOS_TEST_TEMP_ROOT: 'in-process marker so a re-import of vitest.config.js (e.g. vitest.config.test.js) reuses the same run-scoped temp root instead of minting a second one (#9032)',
+ NODE_DISABLE_COMPILE_CACHE: 'Node-provided switch, set to "1" by vitest.config.js so no child process (isolated TMPDIR or not) writes Node\'s module compile cache into the run-scoped temp root (#9051)',
VITEST_FAST: 'opt-in fast-suite selector, CI/local test runs only',
CI_EXPECT_SLASHDO_SUBMODULE: 'CI flag that turns a skipped slashdo adapter contract into a failure',
TEST_DB_OK: 'test-harness flag for the DB-backed suites',
diff --git a/server/test/runTempRoot.js b/server/test/runTempRoot.js
index 86867b6620..98bdc24a4e 100644
--- a/server/test/runTempRoot.js
+++ b/server/test/runTempRoot.js
@@ -60,14 +60,22 @@ const VITEST_INTERNAL_SCRATCH_DIR = /^[A-Za-z0-9_-]{21}$/;
// `agentRunReconciler.test.js`'s own path-traversal fixture, deliberately
// written one level outside its RUNS_DIR and simply never swept in
// `afterAll`. Fixed by sweeping it there.
-// `node-compile-cache` — the confirmed cause (a real, unisolated `npm prefix
-// -g` in `npmGlobalBin.js`, npm being itself a large Node CLI that writes its
-// own module compile cache) is fixed the same way as `kilo`/`opencode` above.
-// It still reappears here VERY rarely (observed once in ~2,500 files) with no
-// real-CLI spawn in the trace that produced it — kept allowlisted rather than
-// pinned on an unconfirmed cause; narrow this further if a reproducible
-// trigger turns up.
-const KNOWN_THIRD_PARTY_CLI_SCRATCH = new Set(['node-compile-cache']);
+// - `node-compile-cache` — narrowed in #9051. `npmGlobalBin.js`'s own
+// `npm prefix -g` spawn was already TMPDIR-isolated by the time #9051
+// started (the fix above landed for it in #9039), yet the directory still
+// turned up rarely (~1 in 2,500 files) with no real-CLI spawn correlated
+// in the trace — Node's module compile cache (written whenever
+// `NODE_COMPILE_CACHE` is set or a CLI calls `module.enableCompileCache()`
+// for itself, which recent npm/npx builds do) is per-process, not tied to
+// one call site, so no single spawn helper's isolation can be proven to
+// cover every child that might inherit the run's TMPDIR. Disabled
+// tree-wide for the whole test run instead: `server/vitest.config.js` sets
+// `NODE_DISABLE_COMPILE_CACHE=1` in both the main process env and every
+// worker's `test.env`, honored since Node v22.1 (this repo requires
+// `^22.22.2 || ^24.15.0 || >=26.0.0`), so any child that inherits
+// `process.env` — isolated TMPDIR or not — never writes the cache in the
+// first place. No longer allowlisted below; a recurrence is a real,
+// unknown leak again.
// A leak this file is NOT the right place to fix: `server/services/
// mediaJobQueue/index.test.js` is a different work area, out of scope for
@@ -150,20 +158,18 @@ export function teardown() {
}
let hasUnknownLeak = false;
for (const [prefix, count] of byPrefix) {
- const knownThirdParty = KNOWN_THIRD_PARTY_CLI_SCRATCH.has(prefix);
const knownPending = KNOWN_PENDING_LEAKS.has(prefix);
- if (!knownThirdParty && !knownPending) hasUnknownLeak = true;
- const note = knownThirdParty ? ' (known third-party CLI scratch, see #9039)'
- : knownPending ? ' (known pending leak, see KNOWN_PENDING_LEAKS above)' : '';
+ if (!knownPending) hasUnknownLeak = true;
+ const note = knownPending ? ' (known pending leak, see KNOWN_PENDING_LEAKS above)' : '';
console.warn(`⚠️ test temp leak: ${prefix} ×${count}${note}`);
}
// Strict mode (#9032): a leftover entry means some suite wrote outside
// its own cleanup path. Fail the run so a new leaker is caught locally
// and in CI instead of quietly growing $TMPDIR — the run root itself is
// still removed below either way, so the failure never reaches the
- // host's real temp directory. A KNOWN_THIRD_PARTY_CLI_SCRATCH or
- // KNOWN_PENDING_LEAKS entry is still reported (so it does not silently
- // balloon) but does not fail the run — see those constants' comments.
+ // host's real temp directory. A KNOWN_PENDING_LEAKS entry is still
+ // reported (so it does not silently balloon) but does not fail the run —
+ // see that constant's comment.
if (hasUnknownLeak) process.exitCode = 1;
}
diff --git a/server/vitest.config.js b/server/vitest.config.js
index 7fc1fc776c..8f6f147cce 100644
--- a/server/vitest.config.js
+++ b/server/vitest.config.js
@@ -95,12 +95,26 @@ process.env.TEMP = RUN_TEMP_ROOT;
// VITEST_FAST is set here too).
process.env.NODE_ENV = 'test';
+// Node's module compile cache (`NODE_COMPILE_CACHE` env, or a CLI calling
+// `module.enableCompileCache()` on itself — recent npm/npx builds do) writes
+// to `TMPDIR/node-compile-cache` on every invocation of the process that
+// enables it. That directory used to turn up rarely in the run-scoped temp
+// root above (#9051) with no single spawn helper's isolation provably
+// covering every child that could inherit the run's TMPDIR — the cache is
+// process-wide, not tied to one call site, so isolating call sites one at a
+// time can't rule out the next one. Disabling it tree-wide removes the
+// possibility outright: honored since Node v22.1, and this repo requires
+// `^22.22.2 || ^24.15.0 || >=26.0.0` everywhere it runs (`package.json`
+// engines), so every supported Node build respects it.
+process.env.NODE_DISABLE_COMPILE_CACHE = '1';
+
export default defineConfig({
test: {
...vitestCiPool(),
// Workers get their own process.env — set it there as well as above.
env: {
NODE_ENV: 'test',
+ NODE_DISABLE_COMPILE_CACHE: '1',
TMPDIR: RUN_TEMP_ROOT,
TMP: RUN_TEMP_ROOT,
TEMP: RUN_TEMP_ROOT,