Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(endpoint): let user-mode and system-mode collectors coexist by deriving the health-check port (#626)

Justin D'Souza6c94f457406f
diff --cc cli/beacon/internal/endpoint/service/supervised.go
index 99c0d8a5,25134ce8..5b496a97
--- a/cli/beacon/internal/endpoint/service/supervised.go
+++ b/cli/beacon/internal/endpoint/service/supervised.go
@@@ -249,19 -226,15 +249,24 @@@ func supervisedCaveats(userMode bool) s
return noRestart
}
-// processAlive reports whether a pid is live.
-func processAlive(pid int) bool {
- if pid <= 0 {
+// running reports whether the recorded pid is live and is still the collector this state recorded.
+//
+// A pid is only a number, and the kernel hands it out again once the process holding it exits. The
+// pidfile outlives the collector -- an OOM kill, a container restart, a reboot of a host with no
+// service manager -- so the number can name an unrelated process by the time anything reads it.
+// Liveness alone then made status report a dead collector as running, load skip starting one, and
+// unload send that stranger SIGTERM, then SIGKILL if it had not exited ten seconds later.
+//
+// A pidfile written before StartedProgram existed cannot be checked, and is trusted on liveness
+// alone as before. Program is not a substitute: writeUnit may have changed it since the pid started.
+func (st supervisedState) running() bool {
+ if st.PID <= 0 || !pidAlive(st.PID) {
return false
}
- return pidAlive(pid)
+ return st.StartedProgram == "" || pidRunsProgram(st.PID, st.StartedProgram)
}
+
+ // supervisedLogPath is the file a supervised collector's stdout and stderr are appended to.
+ func supervisedLogPath(userMode bool) string {
+ return filepath.Join(stateDir(userMode), "collector.out")
+ }