Skip to content

Server liveness, list error handling, and EnvironmentMixin errors #704

Open

Description

@tony

Note

Shipped since filing: 0.64.0 (#727, closing #723) resolved Server.__repr__ socket paths; 0.66.0 (#730, closing #725) raises SocketPathTooLong; 0.68.0 (#902, closing #340) raises TmuxObjectDoesNotExist on closed targets; 0.70.0 suppresses Server.raise_if_dead() output (#641), emits one ERROR record when Server.sessions/clients/attached_sessions swallow a failure (#748), and propagates TmuxCommandTimeout across all list accessors (#807); and sessionless server startup under exit-empty moved to #923. Three items remain open here: (1) error-handling symmetry between Server.sessions/clients and Server.windows/panes, (2) a public error-classification surface over _is_daemon_not_up_error / _is_target_not_found_error, and (3) making EnvironmentMixin raise a LibTmuxException instead of bare ValueError.

Summary

Four server, listing, and environment error-handling gaps remain open from the v0.61.0 downstream MCP audit after #713 and #714 (shipped in v0.62.0) resolved self-location (Server.from_env(), Session.from_env(), Window.from_env(), Pane.from_env() anchored on $TMUX_PANE) and removed the unreachable socket_path derivation in Server.__init__ (Server.__repr__'s hardcoded /tmp fallback is tracked separately in #723).

Defects

Server.start_server() leaves a stale socket under exit-empty

Server.start_server() (src/libtmux/server.py lines 1486–1496) runs tmux start-server without verifying liveness. With exit-empty on (tmux's default), a sessionless server exits immediately: server.is_alive() still returns False, yet a stale socket file remains on disk and survives server.kill(). Socket-file existence cannot test liveness, and start_server() alone neither ensures a running daemon nor tells the caller why nothing stayed up.

Error-handling asymmetry across Server list accessors

Server.sessions (src/libtmux/server.py lines 2400–2420) and Server.clients (src/libtmux/server.py lines 2461–2492) catch every LibTmuxException and return an empty QueryList, making a permission error or overlong socket path (File name too long) indistinguishable from "no sessions". Server.windows (src/libtmux/server.py lines 2423–2439) and Server.panes (src/libtmux/server.py lines 2442–2458) instead delegate to _fetch_or_empty (src/libtmux/server.py lines 65–82), which swallows only daemon-not-up errors via _is_daemon_not_up_error and re-raises other failures. Note that lenient list accessors are deliberate policy (v0.57.0 tried raise-on-error and reverted it in v0.57.1); the defect is the behavioral split between the two accessor pairs, not empty-on-absent-daemon itself.

Private stderr classifiers lack a public error-classification surface

_is_daemon_not_up_error (src/libtmux/server.py lines 52–62) and _is_target_not_found_error (src/libtmux/neo.py lines 779–823, added in #713) classify tmux stderr phrasings (no server running, error connecting to ... (No such file or directory), can't find pane/window/session) privately across two modules. Downstream consumers still have to string-match raw tmux stderr by hand.

EnvironmentMixin raises bare ValueError instead of LibTmuxException

set_environment (src/libtmux/common.py line 115), unset_environment (src/libtmux/common.py line 144), and remove_environment (src/libtmux/common.py line 173) each raise a bare ValueError on tmux stderr, bypassing LibTmuxException. Callers that catch LibTmuxException miss routine set-environment failures such as a dead server.

Invariants

The invariants below are non-negotiable; everything under Intent is open.

  • Server.sessions, Server.windows, Server.panes, and Server.clients preserve the empty QueryList contract when no tmux server is running on the socket, and share a single consistent rule for non-daemon errors.
  • Every tmux command failure raised by EnvironmentMixin inherits from LibTmuxException (subclassing ValueError as well if needed for backward compatibility with except ValueError: callers).
  • Socket paths for -L named sockets are never guessed in Python without asking tmux (#{socket_path}), preserving the decision recorded in feat(Server,Session,Window,Pane): Resolve the pane you run inside (from_env) #714.

Intent

Non-binding direction:

  • Document exit-empty behavior on Server.start_server() (or pair it with an opt-in liveness check).
  • Consolidate _is_daemon_not_up_error and _is_target_not_found_error behind one error-classification surface rather than accreting per-module string matchers.

References

Exact lookup before deleting a registry row

On 6c92651, Server.has_session(name, exact=True) returned False both for an absent name on a responding server and for an unreachable socket. Adding exact=True changes name matching. It does not distinguish those two outcomes. The AWS Labs CLI Agent Orchestrator needs that distinction before deleting a row from its local SQLite registry. Current boolean conversion · Downstream teardown

An opt-in lookup such as has_session_strict(name) could answer from one request to the selected server. Return True for the exact name and False for an authoritative miss, including a responding daemon with no sessions. Raise on an unreachable or denied endpoint, timeout, or malformed reply. A prefix-only match must leave the unrelated session alone. The existing inventory accessors can keep their lenient return contract.

A local adapter exercised the downstream service against temporary SQLite databases and 15 tmux builds. Confirmed misses allowed deletion. Permission denial, a live daemon whose socket path had disappeared, malformed output, and timeout all preserved the row. The matrix ran 91 cases in total. #944 covers the different success result for a checked pane capture.

Activity

  1. tony commented on Jul 11, 2026

    @tony
    MemberAuthor

    Status update, because this issue's linked PR (#705) is now closed and the live work is elsewhere.

    Addressed by #713 + #714 (stacked; #713 → master, #714 → #713):

    I have not used a closing keyword, deliberately: #714 addresses two of this issue's asks, and the papercuts in §3 are untouched and unowned. Closing this on #714's merge would bury them.

    Still open, still true on master, tracked nowhere else:

    • 3(a) Server.start_server() has no liveness check.
    • 3(b) Server.sessions / .clients swallow every LibTmuxException, while .panes / .windows re-raise via _fetch_or_empty. Worth reframing: AGENTS.md deliberately blesses empty-on-error as the contract for list accessors (raise-on-error shipped in 0.57.0 and was reverted), so the defect is the inconsistency between the two groups, not the leniency itself.
    • 3(c) the stderr classifier is private. Note fix(Pane,Window): Resolve point lookups through tmux #713 adds a second private one (neo._is_target_not_found_error), so there are now two — an argument for promoting a single error-classification surface rather than accreting more.
    • 3(d) understated as filed: common.py raises three bare ValueErrors, not one.

    Adjacent, and not claimed by this issue: Server.__repr__ still fabricates socket_path=/tmp/tmux-{euid}/default. #714 deleted the unreachable path guess and left this reachable one, which also ignores TMUX_TMPDIR. Worth its own issue.

    Also note §2's benchmark table goes partly stale when #713 merges: Pane.from_pane_id stops doing a list-panes -a server-wide scan, so its number drops substantially.

    Suggest rescoping this to §3 (or splitting 3(a)–(d) out) rather than closing it wholesale.

  2. changed the title [-]No self-location API (TMUX_PANE), and the socket_path derivation in Server.__init__ is unreachable dead code[/-] [+]`Server` liveness, list error handling, and `EnvironmentMixin` errors[/+] on Nov 21, 2026
  3. tony commented on Nov 24, 2026

    @tony
    MemberAuthor

    The first defect here (Server.start_server() leaving nothing running under exit-empty on) is now tracked as a feature in #923, which proposes Server.connect_or_start() and shows a one-call start that keeps a sessionless server up. This issue keeps the other three defects. Lifecycle conflicts and ordering are in #925.

  4. added
    area: lifecycle
    on Nov 24, 2026
  5. added this to the 0.70.0 milestone on Nov 28, 2026
  6. modified the milestones: 0.70.0, 0.72.0 on Nov 28, 2026
  7. tony commented on Dec 4, 2026

    @tony
    MemberAuthor

    #955 adds Server.has_session_strict(name) for one exact name. A live daemon with no matching session can confirm absence. Socket denial, disconnection, timeout, and malformed replies keep the outcome uncertain. In the AWS Labs CLI Agent Orchestrator’s local SQLite fixture, strict lookup retained all 60 rows on uncertain reads and removed all 30 confirmed misses. The listing and EnvironmentMixin items in this issue remain open.

  8. modified the milestones: 0.73.0, 0.71.0 on Dec 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: lifecyclebugenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions