fix(plugins): stop fallback server process trees

This commit is contained in:
OpenAI Codex
2026-10-13 23:33:15 +08:00
parent 45bae55787
commit 9d22eea7d2
5 changed files with 2360 additions and 3 deletions
+24 -2
View File
@@ -73,6 +73,10 @@ async function launch(packageSpecifier) {
}
const child = spawn(command, args, {
cwd: workingDirectory,
// A dedicated POSIX process group gives this launcher ownership of the
// package runner and any server it starts. Windows keeps direct-child
// signaling until a verified Job Object owner is available here.
detached: process.platform !== "win32",
stdio: "inherit",
shell: false,
});
@@ -80,8 +84,17 @@ async function launch(packageSpecifier) {
const signals = new Map();
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
const forward = () => {
if (child.exitCode === null && child.signalCode === null)
child.kill(signal);
if (child.exitCode !== null || child.signalCode !== null) return;
try {
if (process.platform !== "win32" && child.pid !== undefined)
process.kill(-child.pid, signal);
else child.kill(signal);
} catch (cause) {
if (!isMissingProcess(cause))
process.stderr.write(
`REA plugin could not forward ${signal}: ${cause.message}\n`,
);
}
};
signals.set(signal, forward);
process.on(signal, forward);
@@ -129,3 +142,12 @@ function isMissing(cause) {
cause.code === "ENOENT"
);
}
function isMissingProcess(cause) {
return (
typeof cause === "object" &&
cause !== null &&
"code" in cause &&
cause.code === "ESRCH"
);
}