The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): report the relaunch waiter's exit code
emozilla00a5c1419edc
diff --git a/apps/desktop/electron/updater-process.ts b/apps/desktop/electron/updater-process.tsindex fa2347cfd47..f80a0406c54 100644--- a/apps/desktop/electron/updater-process.ts+++ b/apps/desktop/electron/updater-process.ts@@ -298,8 +298,10 @@ export function resolvePosixScriptHandoff(* (`start`'s powershell) are never members and Windows does not tie a* process's lifetime to its parent. By default `start` returns immediately, so the* spawned pid is the WRAPPER's — callers must not use it as a marker owner- * (the script claims the marker itself with its own $PID). Set waitForExit to- * keep the wrapper alive for callers that need to cancel its process tree.+ * (the script claims the marker itself with its own $PID). Set waitForExit for+ * callers that cancel the process tree or read the script's exit code: cmd then+ * runs the command directly in the same hidden console, stays alive until it+ * exits and returns its exit code (`start /wait` always returns 0).*/export function wrapHandoffForDetachedConsole(handoff: UpdateScriptHandoff,@@ -317,10 +319,7 @@ export function wrapHandoffForDetachedConsole('/d','/s','/c',- 'start',- '',- '/b',- ...(waitForExit ? ['/wait'] : []),+ ...(waitForExit ? [] : ['start', '', '/b']),handoff.command,...handoff.args,...extraArgsdiff --git a/apps/desktop/electron/updater/relaunch-waiter-lifecycle.test.ts b/apps/desktop/electron/updater/relaunch-waiter-lifecycle.test.tsindex bb9d484fda5..9fada2ebd24 100644--- a/apps/desktop/electron/updater/relaunch-waiter-lifecycle.test.ts+++ b/apps/desktop/electron/updater/relaunch-waiter-lifecycle.test.ts@@ -56,10 +56,6 @@ for (const mode of ['/d','/s','/c',- 'start',- '',- '/b',- '/wait',POWERSHELL_PATH,'-NoProfile','-NonInteractive',diff --git a/apps/desktop/electron/updater/relaunch-waiter-spawn.windows-live.test.ts b/apps/desktop/electron/updater/relaunch-waiter-spawn.windows-live.test.tsindex c0d66d11422..849bd2327ed 100644--- a/apps/desktop/electron/updater/relaunch-waiter-spawn.windows-live.test.ts+++ b/apps/desktop/electron/updater/relaunch-waiter-spawn.windows-live.test.ts@@ -6,6 +6,36 @@ import path from 'node:path'import { buildSync } from 'esbuild'import { expect, it } from 'vitest'+import { startRelaunchWaiter } from './relaunch-waiter'++it.runIf(process.platform === 'win32')(+ 'a waiter that exits before its handshake reports its own exit code',+ async () => {+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'waiter exit '))+ const script = path.join(root, 'waiter.ps1')+ const logs: string[] = []+ fs.writeFileSync(script, 'exit 2\n')++ try {+ const handle = await startRelaunchWaiter(+ {+ processId: process.pid,+ processStartTimeMs: Date.now() - process.uptime() * 1000,+ identityName: 'disposable-waiter-test',+ scriptPath: script+ },+ { log: message => logs.push(message) }+ )++ expect(handle).toBeUndefined()+ expect(logs.join('\n')).toMatch(/exited before its handshake after \d+ms \(exit code 2,/)+ } finally {+ fs.rmSync(root, { recursive: true, force: true })+ }+ },+ 30_000+)+it.runIf(process.platform === 'win32').each([false, true])('a real hidden PowerShell waiter survives parent exit unless cancelled (cancel=%s)',async cancel => {diff --git a/apps/desktop/electron/updater/relaunch-waiter.ts b/apps/desktop/electron/updater/relaunch-waiter.tsindex 5567be38e7c..92554d7655c 100644--- a/apps/desktop/electron/updater/relaunch-waiter.ts+++ b/apps/desktop/electron/updater/relaunch-waiter.ts@@ -193,7 +193,8 @@ export async function startRelaunchWaiter(try {// PowerShell 5.1 exits before executing -File under DETACHED_PROCESS.- // /b shares cmd's hidden console; /wait retains a live cancellation root.+ // cmd owns a hidden console that PowerShell shares, stays alive as the+ // cancellation root and returns the script's exit code.// The PowerShell grandchild survives Electron's libuv job being closed.const wrapped = wrapHandoffForDetachedConsole({