Expand description
Reclaim the data dir from an srv that an earlier launcher left behind.
srv takes an exclusive flock on <data_dir>/srv.lock and writes its PID
into it (crates/srv-core/src/backend/base.rs, acquire_data_dir_lock). If an
srv outlives its launcher, every later launch’s srv fails on that lock and
the app cannot be opened (2026-10-11: macOS “Quit & Reopen” left one
behind). An srv still holding the lock whose launcher is gone (it was
reparented to launchd/init) is stale: stop it, and start fresh.
Only a process that is an agentmux-srv binary is stopped, and never one
started headless (--headless / AGENTMUX_HEADLESS=1), which runs on its
own by design (the caller is told, Reclaim::HeadlessRunning, so it can say so
and not try to start a second srv on the same folder), and never one whose parent is still an AgentMux launcher:
winning the single-instance socket isn’t proof enough on its own, since two
local builds of one checkout can share a data dir with different sockets.
Enums§
- Reclaim
- What
reclaim_stale_srv_lockfound.
Constants§
- SRV_
LOCK_ 🔒FILE - Name of srv’s data-dir lock file. Mirrors
SRV_DATA_LOCK_FILEincrates/srv-core/src/backend/base.rs. - TERM_
GRACE 🔒 - How long a stale srv gets to exit after SIGTERM (it closes its agents first) before its whole process group is killed.
Functions§
- headless_
running_ words - The title and the words for a person who opens AgentMux while an srv started headless holds its folder: it is running, without a window; here is how to use it, and how to get the app window instead. Not the splash’s bare “interrupted”.
- kill_
orphaned_ 🔒agents - The stale srv is gone; its agent CLIs lead their own process groups and
are still running unless it closed them. End them (
agent_roots). - lock_
holder_ 🔒via_ lsof - The process that has
lock_pathopen, for a lock file without a recorded PID: an agentmux-srv among the holders if there is one, else the first. The checks inreclaim_stale_srv_lockstill apply to it. - lock_
is_ 🔒free - True when nobody holds the lock (or the file doesn’t exist). Takes and immediately releases the lock; the srv spawned next takes it for real.
- processes_
with_ 🔒file_ open - PIDs with
pathopen. Linux: read/proc/<pid>/fddirectly, sincelsofisn’t installed everywhere (the AppImage doesn’t bundle it and the packages declare no dependencies). Only this user’s processes are readable, which is all an srv we could stop can be. - ps_
field 🔒 - One
psfield forpid(ww: untruncated;with_env: append the process’ environment,ps e), orNoneif it isn’t running. Never log the result: it can hold another process’ secrets. - reclaim_
or_ say_ headless_ running reclaim_stale_srv_lock, and when a server started headless runs this folder: say what is running and how to use it or replace it, and stop. A second srv would fail on the folder’s lock, and the splash would end on a bare “interrupted”.- reclaim_
stale_ srv_ lock - If
<data_dir>/srv.lockis held, stop the stale srv holding it. Returns once the lock is free, or the holder can’t be stopped (the srv spawn that follows then fails and reports it as before), or says that a headless srv holds it. - started_
headless 🔒 - Whether an
agentmux-srvwas started headless, from its arguments and its arguments with its environment (pswithout and withe); either one that could not be read counts as not. - tell_
the_ 🔒person - Print the words, and on macOS show them in a native alert too: a launcher started from the Finder has no terminal to print
to. The text goes to
osascriptas arguments, never into the script, so nothing in it is parsed. Notshow_fatal_dialog, whose other callers (out of memory, an expired upgrade) do not wait on a button. - wait_
for_ 🔒free