fix(update): the legacy start_watchdog matches the monitor exactly too; a restart is reported only when the monitor runs (Issue #72, review round 4)
With MAM_DELEGATION_PY=0 the legacy helper still found the monitor with an unanchored pgrep -f, so a process that only named the monitor path was reported as the restarted monitor and none was started. lib.sh _monitor_pids is the shell twin of daemon.find_running; update.sh and post_update.sh check the PID start_watchdog printed with mam_monitor_started before saying "monitor: restarted". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cf1b693e85
commit
1d63e882bc
5 files changed
+103
-12
No files matched your search
+36
-1
@@ -2235,6 +2235,41 @@ _delegate_publish_event_legacy() {
|
||||
"$py_bin" "$pub" --job "$job_id" --event "$event" --detail "$detail" ${extra[@]+"${extra[@]}"} || true
|
||||
}
|
||||
|
||||
# _monitor_pids <monitor_script>
|
||||
# Issue #72: PIDs whose command line is exactly `<bash> <monitor_script>
|
||||
# --subscribe[ ...]` - the shell twin of lib_py.delegation.daemon.find_running,
|
||||
# so both start_watchdog branches recognise the same daemons. Not a `pgrep -f`
|
||||
# regex: that also matched another workspace's daemon (an unescaped `.`) and a
|
||||
# process that only names the path in an argument.
|
||||
_monitor_pids() {
|
||||
ps -A -ww -o pid= -o args= | MAM_MONITOR_WANT="$1 --subscribe" awk '
|
||||
{ line = $0; sub(/^ +/, "", line)
|
||||
i = index(line, " "); if (!i) next
|
||||
pid = substr(line, 1, i - 1); args = substr(line, i + 1)
|
||||
j = index(args, " "); if (!j) next
|
||||
n = split(substr(args, 1, j - 1), a0, "/"); rest = substr(args, j + 1)
|
||||
want = ENVIRON["MAM_MONITOR_WANT"]
|
||||
if (a0[n] == "bash" && (rest == want || index(rest, want " ") == 1)) print pid }'
|
||||
}
|
||||
|
||||
# mam_monitor_started <workspace> <pid...>
|
||||
# Issue #72: 0 once one of the PIDs start_watchdog printed is WORKSPACE's
|
||||
# monitor (_monitor_pids), so a restart is only reported when it happened.
|
||||
# Polled for up to 5 s: a daemon just started from the shell carries its
|
||||
# parent's command line until it execs bash.
|
||||
mam_monitor_started() {
|
||||
local script="$1/.agents/skills/multi-agent-mux-monitor/scripts/reconcile.sh" n=0 p
|
||||
shift
|
||||
while [ "$n" -lt 50 ]; do
|
||||
for p in $(_monitor_pids "$script"); do
|
||||
case " $* " in *" $p "*) return 0 ;; esac
|
||||
done
|
||||
sleep 0.1
|
||||
n=$((n + 1))
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# start_watchdog <job_id> [workdir]
|
||||
# Spawns a watchdog process to monitor a delegate-job JOB in the background.
|
||||
# The watchdog re-spawns the subscriber every 2 minutes (or whatever hard
|
||||
@@ -2253,7 +2288,7 @@ _start_watchdog_legacy() {
|
||||
|
||||
# Check if reconcile.sh --subscribe is already running on this workspace
|
||||
local pid
|
||||
pid=$(pgrep -f "bash $monitor_script --subscribe" || true)
|
||||
pid=$(_monitor_pids "$monitor_script" || true)
|
||||
|
||||
# Issue #19: MAM_NO_SUBSCRIBER_DAEMON=1 reports a running daemon but never
|
||||
# starts one (test sandboxes; externally supervised monitors).
|
||||
|
||||
Reference in new issue
Block a user