Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

fix(cli): give the Windows user-PATH write 15 s and one retry (#36224)

Neil1ae73d09741c
diff --git a/src/main/cli/cli-install-constants.ts b/src/main/cli/cli-install-constants.ts
index 7769be0bcc1..ecf43889122 100644
--- a/src/main/cli/cli-install-constants.ts
+++ b/src/main/cli/cli-install-constants.ts
@@ -2,4 +2,5 @@ export const DEFAULT_MAC_COMMAND_PATH = '/usr/local/bin/orca'
export const DEV_COMMAND_NAME = 'orca-dev'
export const LEGACY_LINUX_COMMAND_NAME = 'orca'
export const DEV_LAUNCHER_DIR = ['cli', 'bin'] as const
-export const WINDOWS_PATH_WRITE_TIMEOUT_MS = 5_000
+// Cold PowerShell start plus the WM_SETTINGCHANGE broadcast exceeded 5 s on low-spec machines.
+export const WINDOWS_PATH_WRITE_TIMEOUT_MS = 15_000
diff --git a/src/main/cli/cli-privileged-processes.test.ts b/src/main/cli/cli-privileged-processes.test.ts
new file mode 100644
index 00000000000..7459955d800
--- /dev/null
+++ b/src/main/cli/cli-privileged-processes.test.ts
@@ -0,0 +1,62 @@
+// A low-spec Windows machine timed out the first user-PATH write at 5 s; a retry then succeeded.
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+import type { ProcessResult } from '@orca/process-host/process-spec'
+
+const { runProcessMock } = vi.hoisted(() => ({ runProcessMock: vi.fn() }))
+
+vi.mock('@orca/process-host', () => ({ runProcess: runProcessMock }))
+
+import { writeWindowsUserPath } from './cli-privileged-processes'
+import { WINDOWS_PATH_WRITE_TIMEOUT_MS } from './cli-install-constants'
+
+function result(overrides: Partial<ProcessResult> = {}): ProcessResult {
+ return { code: 0, signal: null, stdout: '', stderr: '', timedOut: false, ...overrides }
+}
+
+const TIMED_OUT = result({ code: null, timedOut: true })
+
+beforeEach(() => {
+ runProcessMock.mockReset()
+})
+
+describe('writeWindowsUserPath', () => {
+ it('allows a slow PowerShell well past the old 5 s deadline', async () => {
+ runProcessMock.mockResolvedValue(result())
+
+ await writeWindowsUserPath('C:\\Users\\me\\bin')
+
+ expect(WINDOWS_PATH_WRITE_TIMEOUT_MS).toBeGreaterThanOrEqual(15_000)
+ expect(runProcessMock).toHaveBeenCalledWith(
+ expect.objectContaining({ program: 'powershell', timeoutMs: WINDOWS_PATH_WRITE_TIMEOUT_MS })
+ )
+ })
+
+ it('retries once after a timeout and succeeds', async () => {
+ runProcessMock.mockResolvedValueOnce(TIMED_OUT).mockResolvedValueOnce(result())
+
+ await expect(writeWindowsUserPath('C:\\Users\\me\\bin')).resolves.toBeUndefined()
+
+ expect(runProcessMock).toHaveBeenCalledTimes(2)
+ expect(runProcessMock.mock.calls[1]).toEqual(runProcessMock.mock.calls[0])
+ })
+
+ it('gives up after a second timeout', async () => {
+ runProcessMock.mockResolvedValue(TIMED_OUT)
+
+ await expect(writeWindowsUserPath('C:\\Users\\me\\bin')).rejects.toThrow(
+ `Windows PATH command timed out after ${WINDOWS_PATH_WRITE_TIMEOUT_MS}ms.`
+ )
+ expect(runProcessMock).toHaveBeenCalledTimes(2)
+ })
+
+ it('does not retry a PowerShell failure', async () => {
+ runProcessMock.mockResolvedValue(
+ result({ code: 1, stderr: 'Access to the registry is denied.' })
+ )
+
+ await expect(writeWindowsUserPath('C:\\Users\\me\\bin')).rejects.toThrow(
+ 'Access to the registry is denied.'
+ )
+ expect(runProcessMock).toHaveBeenCalledOnce()
+ })
+})
diff --git a/src/main/cli/cli-privileged-processes.ts b/src/main/cli/cli-privileged-processes.ts
index b6ffbaae715..7c0823f847b 100644
--- a/src/main/cli/cli-privileged-processes.ts
+++ b/src/main/cli/cli-privileged-processes.ts
@@ -27,11 +27,13 @@ export async function writeWindowsUserPath(value: string): Promise<void> {
}
export async function runWindowsPathCommand(args: string[]): Promise<string> {
- const result = await runProcess({
- program: 'powershell',
- args,
- timeoutMs: WINDOWS_PATH_WRITE_TIMEOUT_MS
- })
+ const run = () =>
+ runProcess({ program: 'powershell', args, timeoutMs: WINDOWS_PATH_WRITE_TIMEOUT_MS })
+ let result = await run()
+ // Setting PATH to a fixed value is idempotent, so one retry is safe even if the first landed.
+ if (result.timedOut) {
+ result = await run()
+ }
if (result.timedOut) {
throw new Error(`Windows PATH command timed out after ${WINDOWS_PATH_WRITE_TIMEOUT_MS}ms.`)
}