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 Codex ChatGPT sign-in on Windows: spawn the codex.cmd shim via cmd.exe
[._.]/ Adam Eivyeedcabc46071
diff --git a/server/services/codexAppServer.js b/server/services/codexAppServer.jsindex 548fd05e6c..cf2df905e4 100644--- a/server/services/codexAppServer.js+++ b/server/services/codexAppServer.js@@ -36,6 +36,7 @@ import { tmpdir } from 'os';import { join } from 'path';import { spawn } from '../lib/childProcess.js';+import { killProcessTree, prepareWindowsSafeSpawn } from '../lib/bufferedSpawn.js';import { ServerError } from '../lib/errorHandler.js';import { createLineReader } from '../lib/streamLines.js';import { findCommandOnPath } from '../lib/processEnv.js';@@ -180,7 +181,10 @@ const stopTarget = (target, error) => {teardown(target, error);if (target.child.killed) return;try {- target.child.kill('SIGTERM');+ // Not `child.kill()`: on Windows the child is the `cmd.exe /c` shim wrapper+ // (see `openConnection`), and signalling it leaves the real codex process+ // orphaned — still holding the JSON-RPC pipes PortOS just gave up on.+ killProcessTree(target.child, 'SIGTERM');} catch (err) {console.error(`❌ Failed to stop Codex app-server: ${err.message}`);}@@ -365,11 +369,18 @@ const openConnection = async () => {);}+ // `codex` installs as a `codex.cmd` npm shim on Windows, which `spawn()`+ // refuses under `shell: false` — "spawn EINVAL", so every account read and+ // ChatGPT sign-in failed there (#5838). The canonical wrap (see+ // `prepareWindowsSafeSpawn` for why, and #1865) is a no-op off Windows and+ // for a native `codex.exe`; this spawner was the last site bypassing it.+ const { command, args } = prepareWindowsSafeSpawn(binary, [...CODEX_APP_SERVER_ARGS]);+let child = null;try {// Fixed argv, inherited env, no shell — nothing from a request or a stored// provider record reaches this command line.- child = spawn(binary, [...CODEX_APP_SERVER_ARGS], { stdio: ['pipe', 'pipe', 'pipe'] });+ child = spawn(command, args, { stdio: ['pipe', 'pipe', 'pipe'] });} catch (err) {throw codexError(CODEX_ERROR_CODES.startFailed, `Codex app-server failed to start: ${err.message}`);}diff --git a/server/services/codexAppServer.test.js b/server/services/codexAppServer.test.jsindex 75f615d088..137be0f08b 100644--- a/server/services/codexAppServer.test.js+++ b/server/services/codexAppServer.test.js@@ -12,9 +12,21 @@ vi.mock('../lib/processEnv.js', async (importOriginal) => ({...(await importOriginal()),findCommandOnPath: vi.fn(() => '/usr/local/bin/codex'),}));+// Spied, not replaced: the real pure functions still run (so the POSIX no-op+// path is exercised as shipped), while a test can force the Windows branch's+// result without pretending to be on win32.+vi.mock('../lib/bufferedSpawn.js', async (importOriginal) => {+ const actual = await importOriginal();+ return {+ ...actual,+ prepareWindowsSafeSpawn: vi.fn(actual.prepareWindowsSafeSpawn),+ killProcessTree: vi.fn(actual.killProcessTree),+ };+});const { spawn } = await import('../lib/childProcess.js');const { findCommandOnPath } = await import('../lib/processEnv.js');+const { killProcessTree, prepareWindowsSafeSpawn } = await import('../lib/bufferedSpawn.js');const { CODEX_ACCOUNT_STATUS, CODEX_ERROR_CODES } = await import('../lib/codexAccount.js');const {__resetCodexAppServer,@@ -113,6 +125,38 @@ describe('spawning the app-server', () => {expect(readiness.runtimeInstalled).toBe(false);});+ it('routes the resolved binary through prepareWindowsSafeSpawn, so a Windows codex.cmd shim starts (#5838)', async () => {+ // The reported bug: `codex` installs as a `.cmd` npm shim on Windows, and+ // Node's CVE-2024-27980 patch refuses that target under `shell: false`+ // ("spawn EINVAL"), so every account read and ChatGPT sign-in failed there.+ // The fix is the canonical wrap — asserted here with a sentinel, because+ // the wrap itself is platform-gated and owned by bufferedSpawn.+ findCommandOnPath.mockReturnValue('C:\\npm\\codex.cmd');+ vi.mocked(prepareWindowsSafeSpawn).mockReturnValueOnce({+ command: 'cmd.exe',+ args: ['/c', 'C:\\npm\\codex.cmd', 'app-server'],+ });++ const promise = getCodexAccountReadiness();+ await scripted(child, promise, [['initialize', {}], ['account/read', { account: null }]]);+ await promise;++ expect(prepareWindowsSafeSpawn).toHaveBeenCalledWith('C:\\npm\\codex.cmd', ['app-server']);+ // spawn() received the wrapped pair, NOT the raw shim path.+ expect(spawn.mock.calls[0][0]).toBe('cmd.exe');+ expect(spawn.mock.calls[0][1]).toEqual(['/c', 'C:\\npm\\codex.cmd', 'app-server']);+ });++ it('tears the child down through killProcessTree, so a cmd.exe shim cannot orphan codex', async () => {+ const promise = getCodexAccountReadiness();+ await scripted(child, promise, [['initialize', {}], ['account/read', { account: null }]]);+ await promise;++ await stopCodexAppServer();++ expect(killProcessTree).toHaveBeenCalledWith(child, 'SIGTERM');+ });+it('reuses one child across calls, so a page poll cannot fan out processes', async () => {const first = getCodexAccountReadiness();await scripted(child, first, [['initialize', {}], ['account/read', { account: null }]]);