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."