The open source coding agent.
TypeScript
electron: more robust sidecar kill handling (#18742)
Brendan Allan4c27e7fc6499
diff --git a/packages/desktop-electron/src/main/cli.ts b/packages/desktop-electron/src/main/cli.tsindex fba301f36c2..f2d918bd213 100644--- a/packages/desktop-electron/src/main/cli.ts+++ b/packages/desktop-electron/src/main/cli.ts@@ -35,6 +35,7 @@ export type CommandEvent =export type SqliteMigrationProgress = { type: "InProgress"; value: number } | { type: "Done" }export type CommandChild = {+ pid: number | undefinedkill: () => void}@@ -191,7 +192,7 @@ export function spawnCommand(args: string, extraEnv: Record<string, string>) {treeKill(child.pid)}- return { events, child: { kill }, exit }+ return { events, child: { pid: child.pid, kill }, exit }}function handleSqliteProgress(events: EventEmitter, line: string) {diff --git a/packages/desktop-electron/src/main/index.ts b/packages/desktop-electron/src/main/index.tsindex 484e4feb207..032343204cc 100644--- a/packages/desktop-electron/src/main/index.ts+++ b/packages/desktop-electron/src/main/index.ts@@ -81,6 +81,17 @@ function setupApp() {killSidecar()})+ app.on("will-quit", () => {+ killSidecar()+ })++ for (const signal of ["SIGINT", "SIGTERM"] as const) {+ process.on(signal, () => {+ killSidecar()+ app.exit(0)+ })+ }+void app.whenReady().then(async () => {// migrate()app.setAsDefaultProtocolClient("opencode")@@ -234,8 +245,15 @@ registerIpcHandlers({function killSidecar() {if (!sidecar) return+ const pid = sidecar.pidsidecar.kill()sidecar = null+ // tree-kill is async; also send process group signal as immediate fallback+ if (pid && process.platform !== "win32") {+ try {+ process.kill(-pid, "SIGTERM")+ } catch {}+ }}function ensureLoopbackNoProxy() {