Detect concurrent tmux servers via sockets, not ps argv#160
Open
CosminRadu wants to merge 1 commit into
Open
Conversation
The previous heuristic in `all_tmux_processes` grepped `ps` output for
lines starting with the literal string "tmux". This had two failure
modes that both broke auto-save in practice:
- False negative: tmux invoked via absolute path
(e.g. `/opt/homebrew/bin/tmux ...` on macOS Homebrew installs)
never matched `^tmux` and was invisible to the count.
- False positive: every client process whose argv[0] started with
"tmux" was counted as a server. Any single tmux server with two
or more clients attached would trip the "another server running"
gate, causing continuum to silently skip injecting its save
interpolation into status-right and disable auto-save until the
extra clients went away.
The post-startup branch of `another_tmux_server_running` tried to
compensate by subtracting `tmux list-clients` from the ps count, but
that only listed clients of the current server and inherited the same
ps-matching weaknesses.
Replace with socket-based counting. Each tmux server owns exactly one
Unix domain socket in its socket directory; a live server responds to
`tmux -S <socket> list-sessions`. Stale socket files left over from
crashed servers do not respond and are correctly excluded.
This collapses the dual-mode wrapper in continuum.tmux: the same check
is correct on startup and afterward, so the post-startup branch goes
away.
Removes: all_tmux_processes, number_tmux_processes_except_current_server,
number_current_server_client_processes.
Adds: current_tmux_socket_path, number_other_live_tmux_servers.
Public function names (another_tmux_server_running,
another_tmux_server_running_on_startup, current_tmux_server_pid) are
preserved so external callers like continuum_restore.sh keep working.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The "another tmux server running" gate in
helpers.shdecides whether continuum injects its save interpolation intostatus-right. The current check is aps/grepheuristic that fails in two ways:ps -u $UID -o "command pid" | grep "^tmux"matches only rows whose argv[0] starts with the literal four characterstmux. tmux invoked via absolute path (e.g./opt/homebrew/bin/tmux ...on macOS Homebrew) never matches.tmuxis counted as a server. Any single tmux server with two or more clients attached trips the gate, and continuum silently skips injecting the save interpolation. Auto-save then stops without any indication that anything is wrong.The post-startup branch in
continuum.tmuxtries to compensate by subtractingtmux list-clients, but that only lists clients of the current server and inherits the same ps-matching weaknesses.This was reproducible on a Homebrew tmux install: a normal
tmux attach-sessionplus a baretmuxinvocation (PATH-resolved) on a single server caused continuum to disable auto-save for over a week without notice.The fix
Detect tmux servers by looking at Unix-domain sockets, not process argv. A tmux server holds its socket FD with the socket's filesystem path in lsof's NAME column; a client only holds a peer-pointer connection (no path). Unique path-shaped NAMEs across
tmuxprocesses for the current user equal the set of running servers.Each candidate path is then probed with
tmux -S <path> list-sessionsto confirm a live server is listening (this excludes stale socket files left over from crashed servers).Falls back to scanning the current socket's directory if
lsofis unavailable. The fallback covers the default-dir cases (tmux,tmux -L name) but misses cross-directory-S /elsewhere/pathservers — strictly better than the original heuristic in either case.Effects
continuum.tmuxcollapses: the same socket-based check is correct on startup and afterward.another_tmux_server_running,another_tmux_server_running_on_startup,current_tmux_server_pid) socontinuum_restore.shand any external callers keep working.all_tmux_processes,number_tmux_processes_except_current_server,number_current_server_client_processes.current_tmux_socket_path,number_other_live_tmux_servers.Verified
On macOS Homebrew tmux 3.6a:
-S /tmp/continuum-test-XXX/decoyin a directory unrelated to the default socket dir: new code returns 1 (gate trips). ✓Notes
lsoffor the optimal path. Both macOS and most Linux distros ship it; the directory-scan fallback handles the rest.