Skip to main content

Module stale_srv

Module stale_srv 

Source
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_lock found.

Constants§

SRV_LOCK_FILE 🔒
Name of srv’s data-dir lock file. Mirrors SRV_DATA_LOCK_FILE in crates/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_path open, for a lock file without a recorded PID: an agentmux-srv among the holders if there is one, else the first. The checks in reclaim_stale_srv_lock still 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 path open. Linux: read /proc/<pid>/fd directly, since lsof isn’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 ps field for pid (ww: untruncated; with_env: append the process’ environment, ps e), or None if 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.lock is 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-srv was started headless, from its arguments and its arguments with its environment (ps without and with e); 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 osascript as arguments, never into the script, so nothing in it is parsed. Not show_fatal_dialog, whose other callers (out of memory, an expired upgrade) do not wait on a button.
wait_for_free 🔒