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
address review (codex): fall back to a plain spawn on win32 (no POSIX sh for the double-fork) (#1319)
[._.]/ Adam Eivyf1a10ab94bfc
diff --git a/server/lib/detachedSpawn.js b/server/lib/detachedSpawn.jsindex c3ef4be9b6..d8222f4c9a 100644--- a/server/lib/detachedSpawn.js+++ b/server/lib/detachedSpawn.js@@ -99,6 +99,17 @@ d="$1"; shift*/export async function spawnDetached(bin, args = [], { env, cwd, controlDir, pollMs = DEFAULT_POLL_MS, cleanup = false } = {}) {if (!controlDir) throw new Error('spawnDetached requires a controlDir');++ // Windows has no POSIX `sh` for the double-fork, and pm2's process management+ // there is taskkill-based rather than the PPID-walk this works around. Fall+ // back to a normal child process: a real ChildProcess already satisfies the+ // handle contract (pid / stdout / stderr / on('close',code,signal) / kill /+ // exitCode / signalCode), so callers are unaffected. Surviving a pm2 restart+ // is a POSIX-only guarantee; Windows keeps its prior spawn semantics.+ if (process.platform === 'win32') {+ return spawn(bin, args, { env, cwd, stdio: ['ignore', 'pipe', 'pipe'] });+ }+await ensureDir(controlDir);// Clear any stale control files from a prior run reusing this dir, so the// PID/exit pollers can't latch onto a previous job's results.diff --git a/server/lib/detachedSpawn.test.js b/server/lib/detachedSpawn.test.jsindex d30fa197a1..ee5417476b 100644--- a/server/lib/detachedSpawn.test.js+++ b/server/lib/detachedSpawn.test.js@@ -141,4 +141,24 @@ describe('spawnDetached', () => {it('requires a controlDir', async () => {await expect(spawnDetached('sh', ['-c', 'true'], {})).rejects.toThrow(/controlDir/);});++ it('falls back to a plain spawn on win32 (no POSIX sh double-fork)', async () => {+ const original = process.platform;+ Object.defineProperty(process, 'platform', { value: 'win32', configurable: true });+ try {+ const controlDir = await tmpControlDir();+ // Real `sh` exists on the test runner, so the plain-spawn fallback runs;+ // the point is that it returns a working ChildProcess, not the file-tailed+ // handle. (controlDir is unused on this path but still required.)+ const handle = await spawnDetached('sh', ['-c', 'printf "hi\\n"; exit 0'], { controlDir });+ expect(handle.pid).toBeGreaterThan(0);+ expect(typeof handle.kill).toBe('function');+ const getOut = collect(handle.stdout);+ const { code } = await onClose(handle);+ expect(code).toBe(0);+ expect(getOut()).toBe('hi\n');+ } finally {+ Object.defineProperty(process, 'platform', { value: original, configurable: true });+ }+ });});