Files
openclaw/src/node-host/node-worker-process-identity.ts
T
Peter Steinberger 6b9bea84f0 feat(node-host): supervise durable worker launches (#122829)
* 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
2026-08-12 15:24:05 -07:00

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";
}