Skip to content

Server(feat[socket]): Target default server on bare Server() - #962

Open
tony wants to merge 2 commits into
warn/bare-server-inherited-tmuxfrom
feat/bare-server-default-socket
Open

tony wants to merge 2 commits into
warn/bare-server-inherited-tmuxfrom
feat/bare-server-default-socket

Conversation

@tony

@tony tony commented Dec 5, 2026

Copy link
Copy Markdown
Member

Summary

  • Route bare Server() through -L default instead of inherited $TMUX.
  • Keep inventory reads and Server.new_session() on the same socket.
  • Add keyword env to tmux_cmd for isolated child environments.
  • Strip TMUX per child in new_session() without mutating os.environ.
  • Promote the MIGRATION entry from FutureWarning to enforced default.

Fixes #840 (stacked on #961).

Changes

  • src/libtmux/common.py: accept optional keyword env on tmux_cmd and forward it to subprocess.Popen without altering callers that omit env.
  • src/libtmux/server.py: pass -Ldefault in Server._socket_args() and resolve Server.__repr__ via resolve_socket_path() when neither socket_name nor socket_path is set, drop the FutureWarning from Server(feat[socket]): Warn when bare Server() follows $TMUX #961, and isolate Server.new_session()'s child environment with contextvars.ContextVar instead of deleting os.environ["TMUX"].
  • docs/topics/configuration.md, MIGRATION, CHANGES: document the enforced -L default behavior, Server.from_env() migration path, and thread-safe child environment handling.
  • tests/test_server.py: test two-server isolation with colliding $0 session IDs, thread-synchronized os.environ["TMUX"] preservation during new_session(), tmux_cmd(..., env=...), and $TMUX_TMPDIR socket length checks.

Design decisions

  • Pass -Ldefault in Server._socket_args() rather than stripping TMUX globally on every command. In tmux.c, -Ldefault skips getenv("TMUX") and calls make_label("default") with CLIENT_DEFAULTSOCKET, keeping child commands' pane environment intact unless new_session() explicitly strips TMUX.
  • Propagate new_session()'s TMUX-free environment via a ContextVar read in Server.cmd so custom Server.cmd subclasses that accept no env parameter continue working unchanged across threads.

Test plan

  • Bare Server() lists and creates sessions on -L default while Server.from_env(), -L, and -S controls stay isolated (test_bare_server_targets_default_socket_over_inherited_tmux)
  • Concurrent thread reads original os.environ["TMUX"] during new_session() Popen dispatch while child env omits TMUX (test_new_session_preserves_parent_tmux_env_across_threads, test_tmux_cmd_accepts_explicit_env)
  • MIGRATION, docs/topics/configuration.md, and docs/history.md doctests pass under pytest
  • Formatting, lint, typecheck (ruff, ty), and Sphinx docs (just build-docs) pass
  • Full matrix in CI

@tony tony added this to the 0.73.0 milestone Dec 5, 2026
@tony tony added behavior-change Fixes a bug by changing observable or documented behaviour; needs a minor release area: lifecycle Server start, context managers, ownership, get-or-create, discovery, leases, program lifetime documentation Docs, examples, recipes labels Dec 5, 2026
@tony tony added this to libtmux Dec 5, 2026
@codecov

codecov Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 62.08%. Comparing base (f836370) to head (2294297).

Files with missing lines Patch % Lines
src/libtmux/server.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@                         Coverage Diff                         @@
##           warn/bare-server-inherited-tmux     #962      +/-   ##
===================================================================
- Coverage                            62.09%   62.08%   -0.01%     
===================================================================
  Files                                   29       29              
  Lines                                 5105     5096       -9     
  Branches                              1085     1080       -5     
===================================================================
- Hits                                  3170     3164       -6     
+ Misses                                1595     1594       -1     
+ Partials                               340      338       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

tony added 2 commits December 5, 2026 10:13
why: Bare Server() without socket_name or socket_path previously omitted
-L/-S so inventory followed inherited $TMUX while new_session() deleted
os.environ["TMUX"] in the parent process (#840).

what:
- Pass -Ldefault in Server._socket_args() and resolve Server.__repr__
  against resolve_socket_path() when no socket selector is given
- Add keyword env to tmux_cmd and isolate new_session() child env via
  ContextVar without mutating os.environ across threads
- Promote MIGRATION table and examples from FutureWarning (#960) to
  enforced default (#840)
why: Record bare Server() -L default targeting and isolated child
environments in the unreleased changelog.

what:
- Add Breaking changes and What's new entries for bare Server()
@tony
tony force-pushed the feat/bare-server-default-socket branch from aabca4d to 2294297 Compare December 5, 2026 16:15

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: lifecycle Server start, context managers, ownership, get-or-create, discovery, leases, program lifetime behavior-change Fixes a bug by changing observable or documented behaviour; needs a minor release documentation Docs, examples, recipes enhancement

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant