mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-20 09:31:54 -06:00
6b9bea84f0
* feat(node-host): add worker launch supervision * fix(node-host): harden worker lifecycle ownership * fix(node-host): harden worker execution boundary * fix(node-host): preserve worker trust settings * chore(plugin-sdk): refresh worker lifecycle baselines * docs(plan): track runner implementation slices * test(node-host): await runtime shutdown owner
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { readWindowsProcessStartTimeSync } from "../infra/windows-port-pids.js";
|
|
import { getFileLockProcessStartTime, isPidDefinitelyDead } from "../shared/pid-alive.js";
|
|
|
|
export type NodeWorkerProcessIdentity = {
|
|
pid: number;
|
|
startTime: number;
|
|
};
|
|
|
|
type NodeWorkerProcessIdentityState = "live" | "dead" | "reused" | "unknown";
|
|
|
|
function readNodeWorkerProcessStartTime(pid: number): number | null {
|
|
return process.platform === "win32"
|
|
? readWindowsProcessStartTimeSync(pid)
|
|
: getFileLockProcessStartTime(pid);
|
|
}
|
|
|
|
export function requireNodeWorkerProcessIdentity(pid: number): NodeWorkerProcessIdentity {
|
|
const startTime = readNodeWorkerProcessStartTime(pid);
|
|
if (startTime === null) {
|
|
throw new Error(`cannot establish PID-reuse-safe identity for process ${pid}`);
|
|
}
|
|
return { pid, startTime };
|
|
}
|
|
|
|
export function inspectNodeWorkerProcessIdentity(
|
|
identity: NodeWorkerProcessIdentity,
|
|
): NodeWorkerProcessIdentityState {
|
|
const observedStartTime = readNodeWorkerProcessStartTime(identity.pid);
|
|
if (observedStartTime !== null) {
|
|
if (observedStartTime !== identity.startTime) {
|
|
return "reused";
|
|
}
|
|
return isPidDefinitelyDead(identity.pid) ? "dead" : "live";
|
|
}
|
|
return isPidDefinitelyDead(identity.pid) ? "dead" : "unknown";
|
|
}
|