From c0d0e012ccaaa272c269e3a18649a0dec10fda9f Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 26 May 2026 13:19:11 -0700 Subject: [PATCH] [eric] outputs/quit: reap app builder child processes before killing the backend on windows so nsis upgrades stop hitting "cannot be closed"; bump 1.1.67 - root cause: window-all-closed called killBackend() (windows: taskkill /F) BEFORE before-quit could POST /shutdown-all, so the backend was dead before it could run stop_all(), orphaning the bundled vite node.exe; a running node.exe locks its own image at resources\node\x64\node.exe, so the next nsis upgrade cannot overwrite it and surfaces appCannotBeClosed via the file-lock retry path (extractAppPackage.nsh / installUtil.nsh), not the name-based app-running check - windows-only because mac's killBackend sends SIGTERM, which lets uvicorn run its lifespan shutdown -> stop_all(); only since 1.1.64 because app builder first started spawning these children on windows in bf6d7a9 (before that they died with WinError 2) - fix: drop the premature killBackend() in window-all-closed (will-quit still kills the backend, now AFTER the reap) and raise the pre-quit reap budget from 2s to 10s to cover stop_all's parallel taskkill (up to 5s) + 3s SIGTERM grace - mac unaffected: will-quit already kills the backend; the app reap simply runs explicitly via /shutdown-all now instead of riding on SIGTERM timing Co-Authored-By: Claude Opus 4.7 (1M context) --- electron/main.js | 17 +++++++++++++++-- electron/package.json | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/electron/main.js b/electron/main.js index 6f30242c..10064499 100644 --- a/electron/main.js +++ b/electron/main.js @@ -1485,7 +1485,15 @@ app.on('web-contents-created', (_event, contents) => { }); app.on('window-all-closed', () => { - if (!isDev) killBackend(); + // Intentionally NOT killBackend() here. before-quit POSTs /shutdown-all + // so the backend reaps App Builder child processes (bundled node/vite, + // uvicorn) while it is still alive; will-quit kills the backend after. + // Killing it here first (on Windows that is taskkill /F, which skips + // uvicorn's graceful stop_all) orphans those children, and an orphaned + // vite node.exe keeps a lock on its own image at + // resources\node\x64\node.exe, blocking the next NSIS upgrade with + // "OpenSwarm cannot be closed". Mac's SIGTERM happened to run stop_all, + // which is why this never reproduced there. app.quit(); }); @@ -1522,8 +1530,13 @@ app.on('before-quit', async (event) => { if (drainingForQuit) return; event.preventDefault(); drainingForQuit = true; + // 10s, not 2s: stop_all() reaps runtimes in parallel but each can take up + // to ~8s on Windows (taskkill /T /F up to 5s + a 3s SIGTERM grace). At 2s + // the backend got hard-killed mid-reap, orphaning the vite node.exe. The + // ceiling is only reached when an App Builder app is actually running and + // slow to die; with none active stop_all returns instantly. try { - await postShutdownAllApps(2000); + await postShutdownAllApps(10000); } catch (_) {} app.quit(); }); diff --git a/electron/package.json b/electron/package.json index bf7b6d92..fcbc89ea 100644 --- a/electron/package.json +++ b/electron/package.json @@ -1,6 +1,6 @@ { "name": "openswarm", - "version": "1.1.66", + "version": "1.1.67", "description": "OpenSwarm — AI Agent Orchestrator", "author": "openswarm-ai", "main": "main.js",