MCPcopy Create free account
hub / github.com/bearlyai/OpenADE / createRuntimeNodeLivenessProbe

Function createRuntimeNodeLivenessProbe

projects/runtime-node/src/liveness.ts:64–126  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

62}
63
64export function createRuntimeNodeLivenessProbe(): RuntimeLivenessProbe {
65 return {
66 probe(runtime: RuntimeRecord): RuntimeLivenessProbeResult {
67 const pid = runtime.pid
68 if (!Number.isInteger(pid) || !pid || pid <= 0) {
69 return { state: "unknown", reason: "Runtime has no process id" }
70 }
71
72 const state = pidState(pid)
73 if (state.state !== "alive") return state
74
75 let verifiedByProcessGroup = false
76 const pgid = runtime.pgid
77 if (process.platform !== "win32" && Number.isInteger(pgid) && pgid && pgid > 0) {
78 const groupState = processGroupState(pgid)
79 if (groupState.state === "dead") return { state: "unknown", reason: `Process ${pid} is alive but expected process group ${pgid} is not` }
80 if (groupState.state === "alive") verifiedByProcessGroup = true
81 }
82
83 let verifiedByLabel = false
84 if (runtime.processLabel) {
85 const command = commandForPid(pid)
86 if (!command) {
87 return {
88 state: "unknown",
89 reason: `Process ${pid} is alive but command identity could not be verified`,
90 }
91 }
92 if (command && !commandMatchesLabel(command, runtime.processLabel)) {
93 return {
94 state: "unknown",
95 reason: `Process ${pid} is alive but does not match expected runtime label`,
96 }
97 }
98 verifiedByLabel = true
99 }
100
101 let verifiedByStartTime = false
102 if (runtime.processStartedAt) {
103 const actualStartedAt = startedAtForPid(pid)
104 if (!actualStartedAt) {
105 return {
106 state: "unknown",
107 reason: `Process ${pid} is alive but start time could not be verified`,
108 }
109 }
110 if (actualStartedAt && !processStartedAtMatches(runtime.processStartedAt, actualStartedAt)) {
111 return {
112 state: "unknown",
113 reason: `Process ${pid} is alive but started at ${actualStartedAt}, not ${runtime.processStartedAt}`,
114 }
115 }
116 verifiedByStartTime = true
117 }
118
119 return {
120 state: "alive",
121 verified: verifiedByProcessGroup || verifiedByLabel || verifiedByStartTime,

Callers 2

getRuntimeServerFunction · 0.90
createRuntimeNodeServerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected