refactor(restart): extract stale pid cleanup and supervisor markers

This commit is contained in:
Peter Steinberger
2026-02-26 16:39:14 +01:00
parent c81e9866ff
commit 4da6a7f212
6 changed files with 259 additions and 136 deletions

View File

@@ -1,4 +1,5 @@
import { spawn } from "node:child_process";
import { hasSupervisorHint } from "./supervisor-markers.js";
type RespawnMode = "spawned" | "supervised" | "disabled" | "failed";
@@ -8,24 +9,6 @@ export type GatewayRespawnResult = {
detail?: string;
};
const SUPERVISOR_HINT_ENV_VARS = [
// macOS launchd — native env vars (may be set by launchd itself)
"LAUNCH_JOB_LABEL",
"LAUNCH_JOB_NAME",
// macOS launchd — OpenClaw's own plist generator sets these via
// buildServiceEnvironment() in service-env.ts. launchd does NOT
// automatically inject LAUNCH_JOB_LABEL into the child environment,
// so OPENCLAW_LAUNCHD_LABEL is the reliable supervised-mode signal.
"OPENCLAW_LAUNCHD_LABEL",
// Linux systemd
"INVOCATION_ID",
"SYSTEMD_EXEC_PID",
"JOURNAL_STREAM",
"OPENCLAW_SYSTEMD_UNIT",
// Generic service marker (set by both launchd and systemd plist/unit generators)
"OPENCLAW_SERVICE_MARKER",
];
function isTruthy(value: string | undefined): boolean {
if (!value) {
return false;
@@ -35,10 +18,7 @@ function isTruthy(value: string | undefined): boolean {
}
function isLikelySupervisedProcess(env: NodeJS.ProcessEnv = process.env): boolean {
return SUPERVISOR_HINT_ENV_VARS.some((key) => {
const value = env[key];
return typeof value === "string" && value.trim().length > 0;
});
return hasSupervisorHint(env);
}
/**