fix(server): auto-reap stale sockets and add `jcode server stop` (#291)
After an `install.sh`/auto-update upgrade, the old daemon can survive and keep answering on the runtime socket (or leave a dead socket behind), so a fresh launch either talks to stale code or wedges in a connect-retry loop (issues #277/#291). Two complementary fixes: 1. `reap_stale_socket_if_dead`: on the client launch path, before spawning a server, unlink a provably-dead socket pair. Safety: only reaps when there is no live listener AND we can acquire the exclusive daemon `flock` (a live daemon holds that lock for its whole lifetime), with a post-lock re-check to close the startup race. This can never disturb a running server. 2. `jcode server stop`: graceful retirement for installers/users. Looks up the daemon owning the active socket in the registry, sends SIGTERM (the daemon has a graceful handler), waits for exit (escalating to SIGKILL only if it refuses), then reaps any leftover socket. Supports --json. Tested live: starts a real daemon in an isolated runtime dir, `server stop` signals it, the process exits, and the socket/lock/registry entry are cleared. Added 3 unit tests for the reaper (dead socket+lock removed; live listener spared; socket spared while lock held).
J
jeremy committed
823095b6ae6ab6dfa472e6e2334770dba688d4b7
Parent: 66e1c71