From a849a30e11908a0d76e6a2b8733b56f3b95bb882 Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Thu, 28 May 2026 22:21:31 -0700 Subject: [PATCH] feat(agent-queue): refuse a second run when a daemon is already active cmd_run now checks daemon.pid liveness up front: if a run loop is alive it exits with an error (protecting the single-launcher invariant locking depends on); a stale daemon.pid (dead pid) is cleared and the run proceeds. --- agent-queue/agent-queue.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/agent-queue/agent-queue.sh b/agent-queue/agent-queue.sh index cb3d8f8..e1dcd18 100755 --- a/agent-queue/agent-queue.sh +++ b/agent-queue/agent-queue.sh @@ -340,6 +340,14 @@ cmd_run() { *) die "run: unknown arg '$1'";; esac done + # Refuse to start a second run loop against the same queue — two daemons would + # break the single-launcher invariant that per-cwd locking relies on. + local dpid="" + [[ -f "$STATE/daemon.pid" ]] && dpid=$(cat "$STATE/daemon.pid" 2>/dev/null) + if [[ -n "$dpid" ]] && kill -0 "$dpid" 2>/dev/null; then + die "a run loop is already active (pid $dpid). Use 'stop' first, or a different AGENT_QUEUE_ROOT." + fi + [[ -n "$dpid" ]] && log "clearing stale daemon.pid ($dpid)" echo "$$" > "$STATE/daemon.pid" trap 'rm -f "$STATE/daemon.pid"; log "run loop stopped"; exit 0' INT TERM log "run loop started (max=$MAX_CONCURRENCY, default engine=$DEFAULT_ENGINE). Ctrl-C to stop."