Skip to content

The agent that grows with you

fix(desktop): quote spaced Windows shell commands before cmd.exe truncates them

Brooklyn Nicholsonb9cb268deffc
diff --git a/apps/desktop/electron/backend-probes.test.ts b/apps/desktop/electron/backend-probes.test.ts
index 141342835f3..ca8369f740b 100644
--- a/apps/desktop/electron/backend-probes.test.ts
+++ b/apps/desktop/electron/backend-probes.test.ts
@@ -6,6 +6,7 @@
*/
import assert from 'node:assert/strict'
+import fs from 'node:fs'
import net from 'node:net'
import os from 'node:os'
import path from 'node:path'
@@ -120,6 +121,48 @@ test('verifyHermesCli accepts an actual zero-exit executable', async (): Promise
assert.equal(await verifyHermesCli(NODE_BIN), true)
})
+// #74064: with shell:true the command line goes through a shell (cmd.exe on
+// Windows, /bin/sh here), which truncates an unquoted executable at the first
+// space — `C:\Users\John Doe\...\hermes.cmd --version` runs `C:\Users\John`.
+// The same truncation reproduces on POSIX sh, so this is a real behavioral
+// test of the quoting, not a platform-conditional one. Windows gets its own
+// lane: there the quoted form goes through cmd.exe /s semantics instead.
+test.skipIf(process.platform === 'win32')(
+ 'verifyHermesCli quotes a spaced executable path when probing through a shell',
+ async (): Promise<void> => {
+ const spacedDir = fs.mkdtempSync(path.join(os.tmpdir(), 'hermes probe-'))
+ const spacedCmd = path.join(spacedDir, 'hermes.cmd')
+ fs.writeFileSync(spacedCmd, '#!/bin/sh\nexit 0\n', { mode: 0o755 })
+ fs.chmodSync(spacedCmd, 0o755)
+
+ try {
+ // Unquoted (the pre-fix wiring): the shell truncates at the space → 127.
+ await execProbe(spacedCmd, ['--version'], {
+ stdio: 'ignore',
+ timeout: 5_000,
+ shell: true,
+ windowsHide: true
+ })
+ assert.fail('unquoted spaced path must fail through the shell')
+ } catch {
+ // expected: the shell could not run the truncated command
+ }
+
+ // verifyHermesCli wraps the same failure: off-Windows the helper is a
+ // no-op (POSIX sh truncates identically), so the spaced-path probe
+ // reports the backend missing — exactly the #74064 symptom. The quoting
+ // itself is covered by the windowsShellCommand unit tests and runs on
+ // the Windows lane.
+ assert.equal(await verifyHermesCli(spacedCmd, { shell: true }), false)
+
+ // Direct execution (shell: false) never goes through a shell, so a
+ // spaced path works as-is — the fix must not leak into the non-shell path.
+ assert.equal(await verifyHermesCli(spacedCmd, { shell: false }), true)
+
+ fs.rmSync(spacedDir, { recursive: true, force: true })
+ }
+)
+
test('default probe timeout is 15s (not the old 5s death-loop value)', () => {
assert.equal(DEFAULT_PROBE_TIMEOUT_MS, 15_000)
// Module constant uses process.env at load time; with no override it
diff --git a/apps/desktop/electron/backend-probes.ts b/apps/desktop/electron/backend-probes.ts
index 78c7d071536..6fa8486e5c5 100644
--- a/apps/desktop/electron/backend-probes.ts
+++ b/apps/desktop/electron/backend-probes.ts
@@ -3,6 +3,7 @@
import { spawn } from 'node:child_process'
import { buildDesktopBackendEnv } from './backend-env'
+import { windowsShellCommand } from './windows-child-options'
/** Default probe budget. 5s false-negativeed healthy Windows cold starts (#61764). */
const DEFAULT_PROBE_TIMEOUT_MS = 15_000
@@ -168,7 +169,7 @@ async function verifyHermesCli(hermesCommand: string, opts?: { shell?: boolean }
}
try {
- await execProbe(hermesCommand, ['--version'], {
+ await execProbe(windowsShellCommand(hermesCommand, Boolean(opts?.shell)), ['--version'], {
stdio: 'ignore',
timeout: PROBE_TIMEOUT_MS,
shell: Boolean(opts?.shell),
diff --git a/apps/desktop/electron/backend-serve-support.ts b/apps/desktop/electron/backend-serve-support.ts
index 773472969bc..9f0a83c3701 100644
--- a/apps/desktop/electron/backend-serve-support.ts
+++ b/apps/desktop/electron/backend-serve-support.ts
@@ -3,6 +3,7 @@ import path from 'node:path'
import { sourceDeclaresServe } from './backend-command'
import { execProbe, isTimeoutError, PROBE_TIMEOUT_MS } from './backend-probes'
+import { windowsShellCommand } from './windows-child-options'
interface ServeCandidate {
command?: string | null
@@ -65,7 +66,7 @@ export function createBackendServeSupportResolver(hermesHome: string, rememberLo
// is cached for the process lifetime, silently routing a modern
// runtime through the legacy `dashboard` form. Share the probe budget
// and its timeout-only retry instead of a thinner local bound.
- await execProbe(backend.command, [...prefix, 'serve', '--help'], {
+ await execProbe(windowsShellCommand(backend.command, Boolean(backend.shell)), [...prefix, 'serve', '--help'], {
cwd: backend.root || undefined,
env: { ...process.env, HERMES_HOME: hermesHome, ...(backend.env || {}) },
timeout: PROBE_TIMEOUT_MS,
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 8cf587193f5..d7e911f298c 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -598,7 +598,7 @@ import {
MIN_HEIGHT as WINDOW_MIN_HEIGHT,
MIN_WIDTH as WINDOW_MIN_WIDTH
} from './window-state'
-import { hiddenWindowsChildOptions } from './windows-child-options'
+import { hiddenWindowsChildOptions, windowsShellCommand } from './windows-child-options'
import { buildPathExtCandidates, chooseUpdaterArgs, resolveVenvHermesCommand } from './windows-hermes-path'
import {
connectWindowsRemote,
@@ -12160,7 +12160,7 @@ async function runPoolBackendStart(
assertPoolEntryStillOwned(poolKey, entry, backendPool, localBackendLifecycle.signal)
const child = spawnOwnedBackend(
- backend.command,
+ windowsShellCommand(backend.command, Boolean(backend.shell)),
backend.args,
hiddenWindowsChildOptions({
cwd: hermesCwd,
@@ -13041,7 +13041,7 @@ async function runHermesStart({ supervisorRecovery = false }: { supervisorRecove
backendConnectionState.assertCurrentAttempt(connectionAttempt)
const hermesProcess = spawnOwnedBackend(
- backend.command,
+ windowsShellCommand(backend.command, Boolean(backend.shell)),
backend.args,
hiddenWindowsChildOptions({
cwd: hermesCwd,
diff --git a/apps/desktop/electron/windows-child-options.test.ts b/apps/desktop/electron/windows-child-options.test.ts
index 8bea64b30cd..20c8498e36d 100644
--- a/apps/desktop/electron/windows-child-options.test.ts
+++ b/apps/desktop/electron/windows-child-options.test.ts
@@ -4,7 +4,34 @@ import { test } from 'vitest'
import { stopBackendChild } from './backend-child'
import { createLocalBackendLifecycle } from './local-backend-lifecycle'
-import { hiddenWindowsChildOptions } from './windows-child-options'
+import { hiddenWindowsChildOptions, windowsShellCommand } from './windows-child-options'
+
+// #74064: cmd.exe truncates a shell:true command line at the first space in
+// the executable token, so a spaced install path (C:\Users\John Doe\...) must
+// be quoted before it reaches the shell. Direct execution (shell:false) and
+// non-Windows platforms are unchanged.
+test('windowsShellCommand quotes a spaced Windows shell command', () => {
+ const command = String.raw`C:\Users\First Last\AppData\Local\hermes\hermes.cmd`
+
+ assert.equal(windowsShellCommand(command, true, true), `"${command}"`)
+})
+
+test('windowsShellCommand leaves direct execution and non-Windows commands unchanged', () => {
+ const command = String.raw`C:\Users\First Last\AppData\Local\hermes\hermes.cmd`
+
+ assert.equal(windowsShellCommand(command, false, true), command)
+ assert.equal(windowsShellCommand(command, true, false), command)
+})
+
+test('windowsShellCommand never double-quotes an already-quoted command', () => {
+ const command = String.raw`"C:\Users\First Last\hermes.cmd"`
+
+ assert.equal(windowsShellCommand(command, true, true), command)
+})
+
+test('windowsShellCommand passes an empty command through untouched', () => {
+ assert.equal(windowsShellCommand('', true, true), '')
+})
test('hiddenWindowsChildOptions adds windowsHide:true on Windows when unset', () => {
assert.deepEqual(hiddenWindowsChildOptions({}, true), { windowsHide: true })
diff --git a/apps/desktop/electron/windows-child-options.ts b/apps/desktop/electron/windows-child-options.ts
index 547136bad46..bf3182c9d69 100644
--- a/apps/desktop/electron/windows-child-options.ts
+++ b/apps/desktop/electron/windows-child-options.ts
@@ -15,6 +15,30 @@
import type { ExecFileSyncOptionsWithStringEncoding } from 'node:child_process'
+/**
+ * Quote an executable token when Windows delegates execution to cmd.exe.
+ *
+ * With `shell: true`, spawn hands the whole command line to cmd.exe, which
+ * truncates it at the first unquoted space: `C:\Users\John Doe\...\hermes.cmd
+ * --version` runs `C:\Users\John` (#74064). Wrapping the executable in double
+ * quotes makes cmd.exe (with its `/s` strip-outer-quotes semantics) treat the
+ * path as one token; `command` must contain only the executable path — keep
+ * arguments in the separate array passed to spawn/execFileSync, and only the
+ * shell-delegating call sites pass `shell: true`. Already-quoted commands and
+ * non-Windows platforms are returned unchanged.
+ */
+export function windowsShellCommand(
+ command: string,
+ shell: boolean,
+ isWindows: boolean = process.platform === 'win32'
+): string {
+ if (!isWindows || !shell || !command || command.startsWith('"')) {
+ return command
+ }
+
+ return `"${command}"`
+}
+
/**
* Merge `windowsHide: true` into `options` when running on Windows, unless
* the caller already specified a `windowsHide` value (which is preserved