Skip to content

Commit d681ceb

Browse files
committed
🤖 fix: convert signal-terminated processes to non-zero exit codes
When a process is killed by signal (SIGTERM, SIGKILL, etc.), Node's close event provides code=null and signal name. Previously we defaulted null to 0, making killed processes appear as successful exits. Now converts signals to Unix-conventional exit codes (128 + signal_number): - SIGKILL (9) → 137 - SIGTERM (15) → 143 - SIGINT (2) → 130 This allows bash_background_read/list to distinguish clean exits from forced terminations (via terminate() or external kill/OOM).
1 parent e252065 commit d681ceb

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/node/services/bashExecutionService.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,33 @@ export class BashExecutionService {
171171
errBuf = flushLines(errBuf, true);
172172
});
173173

174-
child.on("close", (code: number | null) => {
175-
log.debug(`BashExecutionService: Process exited with code ${code ?? "unknown"}`);
174+
child.on("close", (code: number | null, signal: NodeJS.Signals | null) => {
175+
log.debug(
176+
`BashExecutionService: Process exited with code ${code ?? "null"}, signal ${signal ?? "none"}`
177+
);
176178
// Flush any remaining partial lines
177179
if (outBuf.trim().length > 0) {
178180
callbacks.onStdout(outBuf);
179181
}
180182
if (errBuf.trim().length > 0) {
181183
callbacks.onStderr(errBuf);
182184
}
183-
callbacks.onExit(code ?? 0);
185+
186+
// Convert signal to exit code using Unix convention (128 + signal number)
187+
// Common signals: SIGTERM=15 → 143, SIGKILL=9 → 137
188+
let exitCode = code ?? 0;
189+
if (code === null && signal) {
190+
const signalNumbers: Record<string, number> = {
191+
SIGHUP: 1,
192+
SIGINT: 2,
193+
SIGQUIT: 3,
194+
SIGABRT: 6,
195+
SIGKILL: 9,
196+
SIGTERM: 15,
197+
};
198+
exitCode = 128 + (signalNumbers[signal] ?? 1);
199+
}
200+
callbacks.onExit(exitCode);
184201
});
185202

186203
child.on("error", (error: Error) => {

0 commit comments

Comments
 (0)