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: skip empty leftover temp entries instead of racing on a shared path
[._.]/ Adam Eivy74291c205f36
diff --git a/server/lib/spawnCwd.test.js b/server/lib/spawnCwd.test.jsindex 8e6eba3a90..31554f684b 100644--- a/server/lib/spawnCwd.test.js+++ b/server/lib/spawnCwd.test.js@@ -1,4 +1,4 @@-import { describe, it, expect, vi, beforeEach, afterEach, afterAll } from 'vitest';+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';import { posixPath } from './testHelper.js';import { mkdtempSync, mkdirSync, rmSync, writeFileSync, existsSync } from 'fs';@@ -202,15 +202,14 @@ describe('Creative Director scratch cwd (#4650)', () => {await removeCreativeDirectorScratchCwd('agent-cd-rm');expect(existsSync(dir)).toBe(false);await expect(removeCreativeDirectorScratchCwd('agent-cd-rm')).resolves.toBeUndefined();- });-- // removeCreativeDirectorScratchCwd only ever removes the per-agent leaf —- // in production the shared `portos-cd-cwd` container is meant to persist- // and be reused across runs. In this test file it is a throwaway created- // by `mkdirSync(dir, { recursive: true })` above, so clean the container- // itself once here (#9032).- afterAll(() => {- rmSync(join(tmpdir(), 'portos-cd-cwd'), { recursive: true, force: true });+ // removeCreativeDirectorScratchCwd only ever removes the per-agent leaf —+ // in production the shared `portos-cd-cwd` container is meant to persist+ // and be reused across runs, so this test leaves it in place rather than+ // removing it itself (which would race agentFinalization.providerBench+ // .test.js's own use of the same literal path if Vitest runs them+ // concurrently). The run-scoped temp root's teardown (#9032,+ // server/test/runTempRoot.js) treats an empty leftover container as a+ // non-leak, so the now-empty `portos-cd-cwd` needs no cleanup at all.});});diff --git a/server/services/agentFinalization.providerBench.test.js b/server/services/agentFinalization.providerBench.test.jsindex 4cffe576cb..09069680ca 100644--- a/server/services/agentFinalization.providerBench.test.js+++ b/server/services/agentFinalization.providerBench.test.js@@ -27,7 +27,7 @@ vi.mock('./codeReview.js', async (importOriginal) => ({getGoalFidelityConfig: vi.fn(async () => null),}));-import { describe, it, expect, vi, beforeEach, afterAll } from 'vitest';+import { describe, it, expect, vi, beforeEach } from 'vitest';vi.mock('../lib/execGit.js', () => ({execGit: vi.fn(async () => ({ stdout: 'main\n', stderr: '', exitCode: 0 })),@@ -328,17 +328,13 @@ describe('finalizeAgent — Creative Director scratch cleanup (#4650)', () => {prExpected: false,});expect(existsSync(dir)).toBe(false);- });-- // finalizeAgent's real cleanup only removes the per-agent leaf — in- // production the shared `portos-cd-cwd` container is meant to persist and- // be reused across runs. `mkdirSync(dir, { recursive: true })` above also- // created that container, so remove it once here (#9032), mirroring- // spawnCwd.test.js.- afterAll(async () => {- const { rmSync } = await import('fs');- const { tmpdir } = await import('os');- const { join } = await import('path');- rmSync(join(tmpdir(), 'portos-cd-cwd'), { recursive: true, force: true });+ // finalizeAgent's real cleanup only removes the per-agent leaf — in+ // production the shared `portos-cd-cwd` container is meant to persist and+ // be reused across runs, so this test leaves it in place rather than+ // removing it itself (which would race spawnCwd.test.js's own use of the+ // same literal path if Vitest runs them concurrently). The run-scoped+ // temp root's teardown (#9032, server/test/runTempRoot.js) treats an+ // empty leftover container as a non-leak, so the now-empty+ // `portos-cd-cwd` needs no cleanup at all.});});diff --git a/server/test/runTempRoot.js b/server/test/runTempRoot.jsindex 63c3817fa7..7c20ce3e2d 100644--- a/server/test/runTempRoot.js+++ b/server/test/runTempRoot.js@@ -19,7 +19,8 @@* the issue asks for — once every per-file leaker in the tree is fixed, any* new leak fails the run instead of silently reappearing in $TMPDIR.*/-import { readdirSync, rmSync } from 'node:fs';+import { readdirSync, rmSync, statSync } from 'node:fs';+import { join } from 'node:path';export function setup() {// No-op: server/vitest.config.js already created the root and pointed@@ -65,6 +66,41 @@ export function groupLeakPrefix(name) {return name.replace(/[0-9a-zA-Z]{6,}$/, '') || name;}+/**+ * True when `path` holds no real content: a zero-byte file, or a directory+ * whose entries (recursively) are all themselves empty. A shared,+ * production-managed scratch container — `creativeDirectorScratchCwd`'s+ * `portos-cd-cwd`, or a fixed-name log a service truncates with `writeFile+ * (path, '')` before every start — is meant to persist across runs and be+ * reused; once its own per-run content is cleaned up (as production code+ * already does), what remains costs nothing and is not a leak worth+ * reporting or failing over. This also sidesteps a real hazard two files+ * sharing that literal path would otherwise create: each file removing the+ * whole shared container in its own `afterAll` races the other if Vitest+ * runs them concurrently, and one can delete a sibling's still-in-use+ * fixture. Skipping empty entries here means neither file needs to touch+ * the shared path at all — production's own per-item cleanup is trusted,+ * and this function only asks "is anything really left". Exported for the+ * regression test.+ */+export function isEffectivelyEmpty(path) {+ let stat;+ try {+ stat = statSync(path);+ } catch {+ return true; // already gone+ }+ if (stat.isFile()) return stat.size === 0;+ if (!stat.isDirectory()) return false; // a socket, symlink, etc. — never silently drop it+ let children;+ try {+ children = readdirSync(path);+ } catch {+ return true;+ }+ return children.every((child) => isEffectivelyEmpty(join(path, child)));+}+export function teardown() {const root = process.env.TMPDIR;if (!root) return;@@ -78,7 +114,9 @@ export function teardown() {return;}- entries = entries.filter((name) => !VITEST_INTERNAL_SCRATCH_DIR.test(name));+ entries = entries+ .filter((name) => !VITEST_INTERNAL_SCRATCH_DIR.test(name))+ .filter((name) => !isEffectivelyEmpty(join(root, name)));if (entries.length > 0) {const byPrefix = new Map();@@ -104,8 +142,12 @@ export function teardown() {try {rmSync(root, { recursive: true, force: true });- } catch {+ } catch (err) {// Best-effort — a lingering open handle on a worker that hasn't fully- // exited yet must not crash teardown and mask the leak report above.+ // exited yet (most often on Windows) must not crash teardown and mask+ // the leak report above. Not silent, though: warn so a stubborn root is+ // visible rather than just reappearing next run — the stale-root sweep+ // in vitest.config.js cleans it up once it's 6h old either way.+ console.warn(`⚠️ could not remove run temp root ${root}: ${err.message}`);}}