Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #728 +/- ##
==========================================
- Coverage 52.37% 52.35% -0.02%
==========================================
Files 26 26
Lines 3729 3732 +3
Branches 747 747
==========================================
+ Hits 1953 1954 +1
- Misses 1472 1474 +2
Partials 304 304 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
846fb7c to
7ea0444
Compare
Code reviewFound 1 issue:
libtmux/docs/topics/context_managers.md Lines 117 to 141 in 7ea0444 "Nested context managers" still says the block gives you "every layer torn down for you", and item 4 reads "The server is killed when exiting its context". The libtmux/docs/topics/context_managers.md Lines 142 to 149 in 7ea0444 "Benefits" then says "you never manually call the {meth} The doctests cannot catch this: the nested block asserts no output, so the prose can drift from the behaviour silently. Lines 145 to 150 in 7ea0444 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
600c845 to
c023026
Compare
why: A Server is a handle on a socket, not a connection -- the same handle addresses a daemon whether or not this process started it, and a bare Server() addresses whichever tmux the caller has open. Scoping one to a block was destroying it, along with every session in it. Inferring ownership from is_alive() was considered and rejected. That predicate folds every way of failing to reach a server into False by contract, so a transient tmux error at __enter__ would have read as "this block started it" and killed a daemon that predated the block -- the same bug through a different door. Fixes #724. what: - Default kill_on_exit to False; __exit__ kills only when asked - __enter__ returns self and probes nothing - Say in the Server docstring that a server, unlike a session, window or pane, does not tear itself down, and why - Rework docs/topics/context_managers.md, which promised unconditional teardown for all four classes - Test the default, the opt-in, and a bare Server() on the default socket -- the shape the report was actually about, which the TestServer factory cannot reproduce
why: The page promised unconditional teardown for all four classes, so a reader following it would expect `with Server()` to kill a server it did not start. what: - Say that a `Server` context leaves the daemon running unless it was built with `kill_on_exit=True`, and show both. - Correct the nested-context walkthrough, whose summary still listed the server among the layers torn down.
c023026 to
60c8056
Compare
why: A context manager that kills a server it did not start can take down the tmux a user has been working in all day, so the change of behaviour needs to be findable before someone upgrades into it. what: - Record the `kill_on_exit` breaking change under `Breaking changes`, with the migration a caller relying on the old teardown needs.
60c8056 to
9114092
Compare
why: Qualify the server scope correction independently against current master while preserving the published branch history. what: - Merge master into the server context-manager branch - Preserve the explicit kill_on_exit opt-in
why: Scope exit must preserve the daemon and programs selected by a borrowed handle, including on exceptions and concurrent creation. what: - Check daemon and program identity across normal and exceptional exit - Cover a daemon started by another handle during the scope - Isolate the default-socket regression and always clean its server - Document explicit teardown migration and child context ownership
why: Keep development and CI linting on the same Ruff release, including corrected f-string conversions and safer lint fixes. what: - Raise Ruff floors in the development and lint dependency groups - Lock Ruff 0.17.3 with its published source and wheel hashes Ruff release notes: https://github.com/astral-sh/ruff/releases/tag/0.17.2 https://github.com/astral-sh/ruff/releases/tag/0.17.3
why: Contributors need the lint-tool requirement alongside other development environment changes. what: - Document the Ruff 0.17.3 minimum for development and lint checks
4d60f41 to
9befff4
Compare
Summary
with Server() as server:destroying a tmux daemon it had nothing to do with.__exit__wasif self.is_alive(): self.kill(), unconditionally — so a block that did no work at all took out the reader's default server and every session in it.kill_on_exitfor when teardown is what you want.Server,__exit__, indocs/topics/context_managers.md, and inMIGRATION.Why scoping is not ownership
A
Serveris a handle on a socket, not a connection. The same handle addresses a daemon whether or not this process started it, and a bareServer()addresses the default socket — usually the tmux the reader has been working in all day. Entering awithblock says "I want this scoped", not "I am entitled to destroy this".Session,WindowandPaneretain their existing context-manager behavior: leaving the block destroys the selected object, including one retrieved from an existing server. A handle does not prove creation ownership.Normal and exceptional exits preserve the selected server, including a daemon started by another client during the block. The native
kill-servercommand destroys every session on that server. tmux may still exit after its last session ends according toexit-empty.Before / After
Ask for teardown explicitly:
Design decisions
Inference was implemented, then rejected. An earlier revision of this branch had
__enter__record whether the daemon was already alive and__exit__kill only one the block started. It reads well and has real precedent —zipfile._filePassed,tarfile._extfileobj,gzip.myfileobjall decide cleanup by whether they opened the resource. It was dropped for two reasons.The first is a defect. The ownership signal was
is_alive(), which catches bareExceptionand returnsFalseby contract — every way of failing to reach a server is a "no". So a transient tmux failure at__enter__would have read as "this block started it", and__exit__would have killed a daemon that predated the block. That is this issue's bug, reachable through a different door, and closing it would have meant hardening a deliberately lenient predicate into a strict one.The second is that the stdlib's inference cases infer from provenance — what the object did — not from liveness.
Serverhas no provenance to record: the socket does not say who started the daemon. Inference here was a guess wearing the costume of a fact.Explicit opt-in has its own precedent, including in languages built around ownership.
subprocess.Popen.__exit__unambiguously owns its child and still does not kill it.sqlite3.Connection.__exit__commits or rolls back and never closes. Rust'sstd::process::Childhas noimpl Dropat all — "The standard library does not automatically wait on child processes (not even if theChildis dropped), it is up to the application developer to do so."kill_on_exitis a plainbool, not a tri-state. With no inference there is no third state to spell. It also matches the codebase: every one of libtmux's 188bool | Noneparameters is consumed asif x is not None and x:, soNonealready meansFalsehere — aNonemeaning "maybe kill" would have inverted the house idiom in the destructive direction.The name is action-shaped on purpose. libtmux already ships
Pane.display_popup(close_on_exit=...), and tmux's own vocabulary isremain-on-exit,exit-empty. An ownership-shaped name (owns_server) would assert a fact libtmux cannot verify.No
temp_server()helper.temp_serveris already a doc anchor for theTestServerfixture, which creates auto-cleaned servers. A scoped-server helper can be designed on its own merits later.Test plan
test_server_context_manager— the default leaves a server alive, including one the block started. This previously asserted the opposite; the change is the breaking change made visible in the suitetest_server_context_manager_spares_borrowed_serverpreserves daemon, session and program identity across normal and exceptional exits, for pre-existing servers and daemons started by another handle during the blocktest_server_context_manager_spares_the_default_socket— a bareServer()under a monkeypatched$TMUX_TMPDIR. Every other test routes through theTestServerfactory, which mints a private socket and structurally cannot reproduce this issue's shapetest_server_context_manager_kill_on_exit_true— the opt-in kills a server the block did not starttest_server_context_manager_kill_on_exit_true_when_block_started_it— and one it didServer,__enter__,__exit__, plus the reworkeddocs/topics/context_managers.md— all collected and run4d60f411eb05b12e80b3fe28f1a9196d25b182baremain FAIL: tmux 3.2a, 3.3a pass; 3.4, 3.5, 3.6, 3.7a, 3.7b fail. CodeQL passes; codecov/project fails. The development-tmux job allows failures and is not full-suite pass evidence. The cached-binary ABI failure is tracked in tmux(fix[3.8]): Support hooks and terminal fixtures #825.uv run ruff check ./uv run ruff format ./uv run mypycleanjust build-docscleanFollow-up, not in this PR
Session.from_session_id,Window.from_window_idandPane.from_pane_idall exist, so a child handle can be obtained without creating the object —with Window.from_window_id(...)kills a window you did not make. Positive creation-ownership helpers remain separate under #804. This PR addresses #724 without changing child-context behavior.Note for the merger
CHANGESwill conflict with the sibling PRs for #723, #725 and #726, which all add to the same block — keep both sides. This one lands under### Breaking changes.