From b490a544606f9e395ebd1b3d7bbbf1f06357b749 Mon Sep 17 00:00:00 2001 From: shenghui kevin Date: Sat, 21 Feb 2026 04:52:57 -0800 Subject: [PATCH] fix: handle SIGHUP/SIGTERM/SIGPIPE to prevent orphaned processes When a controlling terminal is destroyed (SSH disconnect, tmux pane close), opencode processes become orphaned and continue running indefinitely because no signal handler triggers process.exit(). Add handlers for SIGHUP, SIGTERM, and SIGPIPE so the existing subprocess cleanup in the finally block runs promptly. Fixes #14504 Co-Authored-By: Claude Opus 4.6 --- packages/opencode/src/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/opencode/src/index.ts b/packages/opencode/src/index.ts index 65515658862b..575e3f3771dc 100644 --- a/packages/opencode/src/index.ts +++ b/packages/opencode/src/index.ts @@ -45,6 +45,10 @@ process.on("uncaughtException", (e) => { }) }) +for (const sig of ["SIGHUP", "SIGTERM", "SIGPIPE"] as const) { + process.on(sig, () => process.exit(1)) +} + const cli = yargs(hideBin(process.argv)) .parserConfiguration({ "populate--": true }) .scriptName("opencode")