Skip to content

Commit 0a8ecc6

Browse files
zknprclaude
andcommitted
fix(codex): exit reaper kills the whole app-server tree on Windows (PR #346 review P1)
The leak-fix exit reaper called this.proc.kill("SIGKILL") unconditionally, but on Windows the client is spawned with shell:true, so this.proc is cmd.exe and the real codex app-server is its child — a flat SIGKILL kills only the shell and leaks the app-server. Mirror close()'s platform branch: on Windows use terminateProcessTree (synchronous taskkill /T /F, safe in an exit handler) to kill the whole tree; non-Windows keeps the direct-child SIGKILL. (The P2 zombie note is addressed in-thread: the SIGKILL backstop is the right tradeoff — close() reaps in the normal path, the orphan is reaped by init on any normal host, and not killing reinstates the worse live-process leak.) Suite 119/119. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 4ebc407 commit 0a8ecc6

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

‎plugins/codex/scripts/lib/app-server.mjs‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,23 @@ class SpawnedCodexAppServerClient extends AppServerClientBase {
198198

199199
// Leak fix: a non-detached codex app-server child is NOT reaped by the OS when
200200
// this host process exits normally. Guarantee we kill OUR OWN child on host exit
201-
// (exit handlers must be synchronous, so SIGKILL). We never scan/kill processes we
202-
// did not spawn -- parallel sessions own their own app-servers.
201+
// (exit handlers must be synchronous). We never scan/kill processes we did not
202+
// spawn -- parallel sessions own their own app-servers.
203203
this._exitReaper = () => {
204204
try {
205205
if (this.proc && this.proc.exitCode === null && !this.proc.killed) {
206-
this.proc.kill("SIGKILL");
206+
if (process.platform === "win32") {
207+
// PR #346 review (P1): with shell:true, this.proc is cmd.exe and the
208+
// real codex app-server is its child; a flat SIGKILL would orphan it.
209+
// terminateProcessTree is synchronous (taskkill /T /F), so it is safe
210+
// in an exit handler and kills the whole tree.
211+
terminateProcessTree(this.proc.pid);
212+
} else {
213+
// Direct (non-shell) child: SIGKILL it; the orphan is reparented to
214+
// PID 1 and reaped by init (launchd/systemd) — see the reply on the
215+
// P2 zombie note for the no-reaper-container caveat.
216+
this.proc.kill("SIGKILL");
217+
}
207218
}
208219
} catch {
209220
// best-effort during host teardown

0 commit comments

Comments
 (0)