Skip to content

Server() without a socket follows an inherited $TMUX to another server #840

Open

Description

@tony

Summary

A Server() built without socket_name or socket_path passes neither -L nor -S, so the tmux client uses the socket named in $TMUX. Inside a pane, or in any process that inherited a pane's environment, libtmux then talks to that server, not the default one, and kill_session() and kill_server() act there. tmux_cmd has no env=, so a caller cannot strip TMUX for the tmux client without changing os.environ.

Reproduction

  1. Start a private server, point $TMUX at its socket, and list sessions through a default Server():
import os, subprocess, libtmux
priv = libtmux.Server(socket_name="tmuxenv", config_file="/dev/null")
priv.new_session("inherited-target", window_command="sh")
sock = subprocess.run(["tmux", "-L", "tmuxenv", "display-message", "-p", "#{socket_path}"],
                      capture_output=True, text=True).stdout.strip()
os.environ["TMUX"] = f"{sock},1,0"
print(sorted(s.name for s in libtmux.Server().sessions))
priv.kill()

Expected

libtmux.Server() addresses the default server, or documents that it follows $TMUX.

Actual

['inherited-target']: the default-looking Server() lists the private server's sessions.

Environment
  • libtmux: master at 886b1cd (v0.62.0 plus 114 commits)
  • tmux: 3.8 (system build reports 3.8a)
  • Python: run with uv run --frozen from the libtmux checkout
  • OS: Linux (WSL2), private -L socket, -f /dev/null
Evidence
libtmux.Server() socket_name/socket_path: None None
sessions seen by libtmux.Server(): ['inherited-target']
follows inherited TMUX: True

References

Keep inventory and creation on the same socket

On 6c92651, a bare Server() inside tmux listed sessions on the inherited socket. Detached new_session() through that same object created the worker on the fixture's private default socket. During dispatch, a second thread could also observe that TMUX had disappeared from the parent environment. Restoring the variable after the subprocess returns leaves that interval visible. Parent environment mutation · Restoration

Give two private servers different sentinel sessions. Compare the socket path with the native client, then verify inventory, creation and the returned session all address that socket. Session IDs such as $0 can occur on both servers. Test explicit -L and -S selectors as controls. At the dispatch boundary, synchronize a second thread that reads os.environ and verify the original value throughout. Local tests exercised this on tmux 3.3a and 3.8. #882 covers passing a child environment to the launch layer.

Activity

  1. tony commented on Nov 21, 2026

    @tony
    MemberAuthor

    Cross-port socket-selection contract is tracked in libtmux/central#17 and libtmux/central#16 (ADR 0004); tmux_cmd (src/libtmux/common.py lines 331–338) also needs an explicit env parameter so callers and Server() can scrub TMUX without mutating os.environ.

  2. added
    needs-decision
    area: lifecycle
    on Nov 21, 2026
  3. tony commented on Nov 24, 2026

    @tony
    MemberAuthor

    #923 (Server.connect_or_start()) depends on this decision: which server a bare Server() ensures when $TMUX is inherited. #771 adds LIBTMUX_SOCKET_PATH / LIBTMUX_SOCKET_NAME defaults that would settle it implicitly. Ordering is in #925.

  4. added this to the 0.71.0 milestone on Nov 28, 2026
  5. tony commented on Dec 4, 2026

    @tony
    MemberAuthor

    #954 exercises nested and explicit sockets, per-request environment changes, and retained session, window, and pane handles. Private servers with overlapping IDs make misrouting visible. Tests distinguish the default command runner from an injected control client already attached to a particular daemon.

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: lifecyclebugneeds-decision

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions