Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(minikube): keep the wrapped status when the group reap is refused with EPERM

Alfredo Lopez569d74b3147b
diff --git a/scripts/minikube/run-with-deadline.mjs b/scripts/minikube/run-with-deadline.mjs
index f121e7024..96d57d272 100755
--- a/scripts/minikube/run-with-deadline.mjs
+++ b/scripts/minikube/run-with-deadline.mjs
@@ -116,14 +116,21 @@ function spawnErrorExitCode(error) {
return 1;
}
+// Returns the EPERM error when the kernel refused the signal, otherwise null.
+// macOS answers kill(-pgid) with EPERM when every process left in the group is
+// already exiting, so a refusal alone does not mean the group is alive; the
+// caller decides by checking the group afterwards (reapProcessGroup).
function killProcessGroup(signal) {
- if (!child.pid) return;
+ if (!child.pid) return null;
try {
if (process.platform === "win32") child.kill(signal);
else process.kill(-child.pid, signal);
} catch (error) {
- if (error?.code !== "ESRCH") throw error;
+ if (error?.code === "ESRCH") return null;
+ if (error?.code === "EPERM") return error;
+ throw error;
}
+ return null;
}
function processGroupExists() {
@@ -149,6 +156,20 @@ async function waitForProcessGroupExit(milliseconds) {
return !processGroupExists();
}
+// The last action on the group. A refused SIGKILL is accepted only when the
+// group is gone afterwards; a refused SIGKILL on a live group is rethrown.
+async function reapProcessGroup() {
+ const refusal = killProcessGroup("SIGKILL");
+ const groupGone = await waitForProcessGroupExit(1_000);
+ if (refusal === null) return;
+ if (groupGone) {
+ report("reap-permission-denied", "groupGone=true");
+ return;
+ }
+ report("reap-failed", "reason=EPERM groupGone=false");
+ throw refusal;
+}
+
const heartbeat = setInterval(() => {
report("heartbeat", `elapsedSeconds=${Math.floor(elapsedMilliseconds() / 1_000)}`);
}, heartbeatSeconds * 1_000);
@@ -180,6 +201,7 @@ for (const signal of HANDLED_SIGNALS) {
signalEscalated = true;
}
teardownStarted = true;
+ // A refusal here is settled by the reapProcessGroup that ends teardown.
killProcessGroup("SIGKILL");
};
signalHandlers.set(signal, handler);
@@ -208,8 +230,7 @@ if (first.kind === "exit") {
// A bounded operation may not daemonize work behind the runner. If the
// direct child exited while a helper remained in its process group, reap the
// helper before returning the child's exact status.
- killProcessGroup("SIGKILL");
- await waitForProcessGroupExit(1_000);
+ await reapProcessGroup();
} else if (first.kind === "spawn-error") {
finalExitCode = spawnErrorExitCode(first.error);
report("spawn-failed", `durationMs=${elapsedMilliseconds()} exitCode=${finalExitCode}`);
@@ -222,6 +243,7 @@ if (first.kind === "exit") {
`durationMs=${elapsedMilliseconds()} signal=${terminatingSignal} exitCode=${finalExitCode}`,
);
+ // A refused graceful signal is settled by the reap below.
if (!signalEscalated) killProcessGroup(terminatingSignal);
await waitForProcessGroupExit(killGraceSeconds * 1_000);
@@ -230,8 +252,7 @@ if (first.kind === "exit") {
// the first signal; killing by negative PGID closes that otherwise invisible
// orphan path. A repeated parent signal reaches this same action immediately
// through the handlers above.
- killProcessGroup("SIGKILL");
- await waitForProcessGroupExit(1_000);
+ await reapProcessGroup();
report("terminated", `durationMs=${elapsedMilliseconds()} exitCode=${finalExitCode}`);
}