The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 17:15 UTC
fix(desktop): AppImage quit no longer leaves zygotes running on an unmounted image (#36057)
Julius Marminge committed
Nov 13, 2026 at 00:09 UTC
84efa01f124a5369d56abb344746e3212328c369
4 files changed
+49
-2
apps/desktop/src/app/DesktopExitChildren.test.ts
+21
-1
@@ -3,7 +3,7 @@ import * as NodeChildProcess from "node:child_process";
3
import * as NodeFS from "node:fs";
4
import { assert, describe, it } from "@effect/vitest";
5
6
-import { stopChildProcessesBeforeExit } from "./DesktopExitChildren.ts";
6
+import { stopChildProcessesBeforeExit, stopZygotesBeforeExit } from "./DesktopExitChildren.ts";
7
8
const isRunning = (pid: number) => {
9
try {
@@ -39,4 +39,24 @@ describe.runIf(NodeFS.existsSync("/proc/self/task"))("stopChildProcessesBeforeEx
39
parent.kill("SIGKILL");
40
}
41
});
42
+
43
+ it("kills zygote children before returning and leaves other helpers running", async () => {
44
+ const spawnTitled = async (title: string) => {
45
+ const child = NodeChildProcess.spawn("sleep", ["60"], { argv0: title, stdio: "ignore" });
46
+ await new Promise((resolve) => child.once("spawn", resolve));
47
+ return child;
48
+ };
49
+ // Chromium rewrites a zygote's argv into one space-separated title.
50
+ const zygote = await spawnTitled("/opt/T3 Code/t3code --type=zygote --no-sandbox");
51
+ const utility = await spawnTitled("/opt/T3 Code/t3code --type=utility");
52
+ try {
53
+ stopZygotesBeforeExit(process.pid);
54
+
55
+ assert.isFalse(isRunning(zygote.pid!));
56
+ assert.isTrue(isRunning(utility.pid!));
57
+ } finally {
58
+ zygote.kill("SIGKILL");
59
+ utility.kill("SIGKILL");
60
+ }
61
+ });
62
});
apps/desktop/src/app/DesktopExitChildren.ts
+17
@@ -29,6 +29,13 @@ const childPids = (pid: number): ReadonlyArray<number> => {
29
);
30
};
31
32
+// A zygote rewrites its argv into one space-separated title.
33
+const isZygote = (pid: number): boolean =>
34
+ (readProc(`/proc/${pid}/cmdline`) ?? "")
35
+ .replaceAll("\0", " ")
36
+ .split(" ")
37
+ .includes("--type=zygote");
38
+
39
// A zombie has already released its memory mappings.
40
const isRunning = (pid: number): boolean => {
41
const stat = readProc(`/proc/${pid}/stat`);
@@ -68,3 +75,13 @@ export const stopChildProcessesBeforeExit = (pid: number): ReadonlyArray<number>
75
waitUntilStopped(survivors, KILL_WAIT_MS);
76
return survivors;
77
};
78
+
79
+/**
80
+ * Chromium's zygotes exit only after main does, so on an AppImage they outlive the mount even on
81
+ * an orderly quit. Kills them while main still holds the image mounted. Linux only (/proc).
82
+ */
83
+export const stopZygotesBeforeExit = (pid: number): void => {
84
+ const zygotes = childPids(pid).filter(isZygote);
85
+ signal(zygotes, "SIGKILL");
86
+ waitUntilStopped(zygotes, KILL_WAIT_MS);
87
+};
apps/desktop/src/app/DesktopLifecycle.test.ts
+2
@@ -2,6 +2,7 @@ import { assert, describe, it } from "@effect/vitest";
2
import * as Deferred from "effect/Deferred";
3
import * as Effect from "effect/Effect";
4
import * as Layer from "effect/Layer";
5
+import * as Option from "effect/Option";
6
import * as Ref from "effect/Ref";
7
import * as TestClock from "effect/testing/TestClock";
8
@@ -117,6 +118,7 @@ describe("DesktopLifecycle", () => {
118
const layerEnvironment = Layer.succeed(DesktopEnvironment.DesktopEnvironment, {
119
platform,
120
isDevelopment: false,
121
+ appImagePath: Option.none(),
122
} as DesktopEnvironment.DesktopEnvironment["Service"]);
123
124
const layer = DesktopLifecycle.layer.pipe(
apps/desktop/src/app/DesktopLifecycle.ts
+9
-1
@@ -3,6 +3,7 @@ import * as Context from "effect/Context";
3
import * as Duration from "effect/Duration";
4
import * as Effect from "effect/Effect";
5
import * as Layer from "effect/Layer";
6
+import * as Option from "effect/Option";
7
import * as Ref from "effect/Ref";
8
import * as Schema from "effect/Schema";
9
import * as Scope from "effect/Scope";
@@ -12,7 +13,7 @@ import type * as Electron from "electron";
13
import * as HostProcess from "@t3tools/shared/HostProcess";
14
15
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
15
-import { stopChildProcessesBeforeExit } from "./DesktopExitChildren.ts";
16
+import { stopChildProcessesBeforeExit, stopZygotesBeforeExit } from "./DesktopExitChildren.ts";
17
import { makeComponentLogger } from "./DesktopObservability.ts";
18
import * as DesktopShutdown from "./DesktopShutdown.ts";
19
import * as ElectronApp from "../electron/ElectronApp.ts";
@@ -340,6 +341,13 @@ export const make = DesktopLifecycle.of({
341
quitFromSignal("SIGTERM", runEffect, quit);
342
});
343
}
344
+
345
+ // Unscoped: the app scope closes before Electron exits, and every exit path must run this.
346
+ if (environment.platform === "linux" && Option.isSome(environment.appImagePath)) {
347
+ yield* Effect.sync(() => {
348
+ process.once("exit", () => stopZygotesBeforeExit(process.pid));
349
+ });
350
+ }
351
}).pipe(Effect.withSpan("desktop.lifecycle.register")),
352
});
353