Repository navigation
Description
Summary
libtmux's server and session lifecycle is being extended in several directions at once: keeping a server running before any session exists, making with blocks safe, get-or-create helpers, cleanup ownership, private servers, discovery, leases, and tracking launched programs. Several of these overlap or conflict. This issue names each feature, the conflicts between them, the order they have to land in, and which need a newer tmux than libtmux's 3.3a floor. Issue and PR numbers appear only as pointers to where each feature is tracked today; the feature descriptions are meant to stay true if those threads change.
Motivation
- A
withblock on a session, window or pane destroys things it did not create (Server.__exit__was fixed in0.69.0via Scoping a Server no longer kills it #728 sowith Server()leaves running servers alive unlesskill_on_exit=True).Session.__exit__still kills wheneverhas_session(self.session_name)is true (src/libtmux/session.pyL233-L234), andWindow.__exit__(src/libtmux/window.pyL242-L246) andPane.__exit__(src/libtmux/pane.pyL246-L250) unconditionally kill their target the same way. Any helper that returns an existing session, window or pane (get_or_create_session(),get_or_create_window(),Session.new_window(..., select_existing=True)) inherits that:with server.get_or_create_session("build")orwith session.new_window("logs", select_existing=True)kills a session or window someone else made (0.68.0documents thatWindow.__exit__caveat onselect_existing=Truein Session(docs[new_window]): NoteWindow.__exit__onselect_existingreuse #926, while safe runtime__exit__behavior is scheduled for0.72.0after0.71.0's non-breaking fixes). - The same feature is being built more than once under different names: session get-or-create three ways, server teardown four ways, server discovery three ways, capability reporting two ways.
- There is no call that keeps a server running with no sessions, so global options, environment and hooks cannot be set before the first session.
Evidence
Features
| Feature | What it is | State |
|---|---|---|
| Server that stays up with no sessions | Server.connect_or_start(): start if absent, keep alive with zero sessions, report whether this call started it |
Proposed for 0.72.0; a working startup proof exists in a draft branch. Tracked in #923 |
Safe server with block |
Leaving with Server() must not kill a server the block did not start |
Shipped in 0.69.0 (#728 / #724) via Server(..., kill_on_exit=True) |
Safe session, window and pane with blocks |
Leaving with on a session, window or pane that was looked up or reused must not kill it |
Staged across 0.72.0 (FutureWarning + created / kill_on_exit in #963 / #959) and 0.73.0 (enforced preservation in #964); raised in #916 and #804 |
| Teardown-safe pane formatting | repr(pane) and str(pane) format the stored pane_id without spawning tmux clients or raising after teardown |
Drafted in #950 (0.72.0 alongside safe with blocks). Tracked in #945 |
| Session and window get-or-create | Return the named session or window, creating it only when missing | Drafted and green as get_or_create_session() / get_or_create_window(), scheduled for 0.72.0 after naming and safe __exit__. Tracked in #916 |
| Created-vs-reused result and cleanup ownership | Tell the caller whether a resource was created or reused, and clean up only what the call created | Drafted for sessions as FoundOrCreated, scheduled for 0.72.0 after 0.71.0's single-reply new_session() parsing (#942). Tracked in #804 |
| Private throwaway server | A context manager that makes an isolated server on a temporary socket and removes it afterwards | Proposed for 0.72.0 as Server.private(). Tracked in #872 |
| Server discovery | List the tmux servers on this machine without starting or changing any | Three drafts, scheduled for 0.72.0. Tracked in #924 |
| Default socket choice | Which server a bare Server() talks to when $TMUX is inherited, and keeping returned handles on that socket |
Staged across 0.72.0 (FutureWarning + Server.from_env() guidance in #961 / #960) and 0.73.0 (-L default + isolated child env in #962 / #840, with socket retention stacked in #954 without libtmux.engine). Tracked in #840 |
| Session leases | A server-side timer that removes a session whose owner disappeared | Experimental proposal (0.73.0+). Tracked in #805 |
| Launched-program lifetime | Start a program in a pane and own it through exit status, output collection and cleanup | Drafted (0.73.0+); needs tmux 3.8. Tracked in #823 |
| Wait for a pane the caller did not launch | Block until an existing pane exits, with a polling fallback | Proposed (0.73.0+). Tracked in #869 |
| Per-call client environment | Pass env and cwd to one tmux client call without changing os.environ, and preserve UTF-8 text under an ASCII locale |
UTF-8 text retargeted directly onto master in #953 for 0.72.0 without libtmux.engine (#739). Tracked in #882 |
| Capability reporting | Ask which optional tmux features the connected server supports, built on src/libtmux/_internal/support/capabilities.py (libtmux-capabilities/1) |
Competing public proposals atop the internal table (0.73.0+). Tracked in #871 |
Conflicts
| Conflict | What collides | What it needs |
|---|---|---|
A reused session, window or pane dies on with exit |
get_or_create_session(), get_or_create_window() and new_window(select_existing=True) return existing objects; Session.__exit__, Window.__exit__ and Pane.__exit__ kill any live target; the ownership rule says reuse never grants permission to delete |
Warn on unowned handles and add created / kill_on_exit in 0.72.0 (#963 / #959), then preserve unowned handles on __exit__ in 0.73.0 (#964) |
| Formatting a retired pane raises during teardown | Pane.__repr__ looks up self.window and self.session in tmux, spawning two clients on live handles and raising TmuxObjectDoesNotExist after window teardown (#902) |
Format Pane from its stored pane_id in 0.72.0 (#945 / #950) |
| Uncertain session creation on multiline paths | A newline in start_directory or after-new-session hook output splits new-session -P output so new_session() raises after tmux created the session, obscuring creator ownership (#804) |
Parse the delimited creation reply in 0.71.0 (#942, unstacking #951 onto master) ahead of session ownership (#831) |
A joined server dies on with exit |
Server.connect_or_start() returns servers it did not start; Server.__exit__ used to kill any live server |
Resolved in 0.69.0 (#728): Server.__exit__ preserves running servers unless kill_on_exit=True |
| Two get-or-create vocabularies | get_or_create_session() returning the session, against find_or_create_session() / create_session() / reuse_session() returning a FoundOrCreated wrapper |
One naming family and one way to report "created" (0.72.0) |
| One wrapper type defined twice | FoundOrCreated and find_or_create_session exist in two separate drafts |
Keep one implementation (0.72.0) |
| Server teardown spelled four ways | kill_on_exit=True, resource.own(), Server.owned(), Server.private() |
Server(..., kill_on_exit=True) shipped in 0.69.0 (#728); align Server.private() (#872) and ownership (#804) onto it in 0.72.0 |
| Discovery spelled three ways | TmuxLobby.servers, Server.discover(), discover_servers() |
One API (0.72.0) |
| Capabilities spelled multiple ways | Server.capabilities(), module-level capabilities(), libtmux.capabilities module |
One public API over _internal.support.capabilities (0.73.0+) |
| Socket defaults decided by side effect | LIBTMUX_SOCKET_PATH / LIBTMUX_SOCKET_NAME defaults in a draft, while the default-socket question is open |
Decide the default socket first (0.72.0) |
Lifecycle drafts stacked on libtmux.engine |
Qualification drafts #951, #952, #953, #954, and #955 previously targeted engine-seam-minimal (#739), while engine operations land last (0.74.0+) |
Resolved: #951, #952, and #955 (0.71.0) and #953 (0.72.0) target master directly, and #954 stacks on #962 without libtmux.engine |
| Command timeouts built three times | Server-wide timeout, per-call deadline, and a bundle carrying both | Shipped in 0.70.0 via #807 (superseding #809, #735, and #757) |
| Log redaction built twice | Mask-by-default against caller-chosen redactor | Shipped in 0.70.0 via #748 (with #898; closing #905 and #906) |
Where these live today: get-or-create #920; FoundOrCreated #831 and #771; handle with ownership #963 (#959) -> #964 (#804); creation reply #951 (#942); strict session lookup #955 (#704); pane repr #950 (#945); teardown #728, #771, #872; discovery #764, #771; capabilities #833, #871, #739; connected-daemon version fence #965 (#958) -> #966 (#777); socket defaults and pinning #771, #840, #961 (#960) -> #962, #954; client locale #953 (#882); timeouts #807 (superseded: #809, #735, #757); redaction #748 and #898 (closed: #905, #906).
Release sequencing
0.70.0(shipped — logging, failure ownership, timeouts, and strict typing): Structured logging, failure ownership, and symmetric environment masking (logging(feat): Document logging and define failure ownership #748, closing common(feat[logging]): Mask typed keys and buffer data in logs #905 and common(feat[logging]): Let callers choose the logged argv redactor #906), unified command,wait-for, and listing timeouts (Command(feat[timeout]): Bound commands, waits, and listings #807, superseding server(feat[wait]) Bound ordinary channel waits #809, Bound a tmux command that may never return #735, and Bound every tmux command from a server-wide timeout, listings included #757), non-breaking fixes and docs, andty+ RuffANN(dev(ty): Replacemypywith stricttyand RuffANN#682).0.71.0(non-breaking fixes, opt-in checks, CI, and conformance tests): Ship harmlessmaster-ready fixes and opt-in checks first so pins below0.72.0keep them:REVIEW.md+check-workarounds(docs(policy): Add REVIEW.md, PR template, and workaround gate #967, shipped),setup-tmuxCI (Replace.github/scripts/tmux_build.pywithlibtmux/setup-tmux#941 / Replace.github/scripts/tmux_build.pywithlibtmux/setup-tmux#940, shipped),Server.attached_sessions(List sessions with one or more attached clients #949 /Server.attached_sessionsomits sessions with attached clients #943),Pane.send_keysstatus check (Check the text send before pressing Enter #948 /Pane.send_keys()proceeds to Enter after a silent client failure #946), unstackednew_sessionmultiline reply parsing (Read the session ID and path from the creation reply #951 /new_session()raises after creating a session in a newline path #942), opt-inPane.capture_pane(check=True)(Distinguish blank pane captures from failed reads #952 / Add a checkedPane.capture_pane()for callers that need a real read #944), opt-inServer.has_session_strict()(Confirm exact session absence before removing saved state #955 /Serverliveness, list error handling, andEnvironmentMixinerrors #704), the FIRE conformance suite (Verify pane job results with the FIRE suite #957 / Add a FIRE test for pane output, input delivery and job exit #956), and ready docs/test PRs.0.72.0(deprecation wave, pane formatting, and server/session get-or-create): RenderPanefrom its stored ID (Format pane handles using their stored ID #950 /repr(pane)launches tmux clients and can raise during teardown #945); shipFutureWarningdeprecation windows andMIGRATIONtables for bareServer()inside non-default$TMUX(Server(feat[socket]): Warn when bareServer()follows$TMUX#961 / Warn withFutureWarningwhen bareServer()follows non-default$TMUX#960), unowned{Session, Window, Pane}.__enter__withcreated/kill_on_exit(Session/Window/Pane(feat[ctx]): Warn on unowned__enter__#963 / Warn withFutureWarningbefore__exit__preserves unowned handles #959), and< 3.3aconnected-daemon reads (Server(feat[versions]): Warn on < 3.3a lenient daemon reads #965 / Warn withFutureWarningon< 3.3adaemon reads ahead ofVersionTooLow#958); unstack socket pinning (Keep session creation and returned handles on the selected socket #954) and per-call clientenv/ UTF-8 text (Support per-call client flags, cleanenv/cwd, andspawn_client#882 / Keep typed tmux text in UTF-8 under an ASCII locale #953) ontomaster; add sessionlessServer.connect_or_start()(AddServer.connect_or_start()to keep a server up with no sessions #923, extracted from Lifecycle(feat): Add server defaults and owned scopes #771), get-or-create (libtmux(feat[get_or_create]): Add window and session helpers #920), session ownership (Track ownership when creating or reusing sessions #831),Server.private()(AddServer.private()context manager #872), and server discovery (Lobby(feat): Discover local tmux servers #764 / Discover local tmux servers without starting them #924).0.73.0+(enforcement cuts, observation, optionallibtmux[vt], program lifetime, andtmux 3.8+ lifecycle features): Enforce-L defaulton bareServer()(Server(feat[socket]): Target default server on bareServer()#962 /Server()without a socket follows an inherited$TMUXto another server #840), unowned handle preservation on__exit__(Session/Window/Pane(feat[ctx]): Preserve unowned handles #964 / Create or reuse tmux resources with explicit cleanup ownership #804), andVersionTooLowon< 3.3alenient reads (Server(feat[versions]): RaiseVersionTooLowon < 3.3a reads #966 / Verify connectedtmuxdaemon meets the3.3aminimum before dispatch #777); land optionallibtmux[vt]capture and-Cobservation (vt(feat[libvt]): Add optional VT integration #934, tests(vt): Exercise interactive picker lifecycle #937, tests(vt): Verify captured paste state #947, Window(feat[vt]): Add multi-pane window VT capture #939 for Add optionallibtmux[vt]pane capture and live observation on Python3.12+#932 / Prototypelibtmux[vt]capture,-Csync, input, and test helpers #933), public capability reporting (Packagecapabilities.jsonin distributions and exposeServer.capabilities()#871), explicit program arguments (Preserve explicit program arguments across launches #830), launched-program lifetime (session(feat): Track fresh program lifetimes #833), unowned pane waits (AddPane.wait()to wait for exit of an existing unowned pane #869), observation / capture cursors (Retain immutable pane capture observations #810, Add bounded visible-text presence and absence waits #829, Add Pane.capture_since() for cursor-based incremental pane reads #741 / Capture retained history with counter-backed cursors #832), and remaining non-engine tracks in 0.63.x and beyond Roadmap #907.0.74.0+(last — engine seam, async dispatch, and transport operations): Landlibtmux.engine(Engine(feat): Add raw-byte libtmux.engine seam and capabilities #739) andlibtmux.aio/ReplayEngine(Aio(feat): Addlibtmux.aioand offlineReplayEnginetapes #738) last, alongsideExecEngine(Run tmux commands through a caller-supplied transport (docker exec,ssh, sandbox exec) #841),ControlClient(AddControlClientwith%subscription-changedand hook-safe guards #884), command chains (Typed command descriptors for native tmux command chains #683), and asyncwait-forcancellation (ReapAsyncServer.wait_foron task cancel and exposetmux 3.8wait-for -l/-w#870).
tmux version gates
libtmux's floor is TMUX_MIN_VERSION = "3.3a" (src/libtmux/common.py L34). "First in" is the tmux release that first contained the mechanism, read from tmux's git history; rows marked "stated" repeat what the tracking issue says.
| Feature | tmux mechanism it depends on | First in | Above the 3.3a floor? |
|---|---|---|---|
| Server that stays up with no sessions | exit-empty option; format lookup falling back to the server environment; if-shell -F |
2.7; 2.2; 2.0 or earlier | No |
Safe with blocks |
none | any | No |
| Session and window get-or-create | new-window -S |
3.2 | No |
| Created-vs-reused and ownership for sessions | new-session -P -F, format-guarded command queues |
3.2a (stated) | No |
| Server discovery | #{version}, #{pid} formats |
3.1 | No |
| Session leases | run-shell -d timers, if-shell -F |
3.2 | No |
| Launched-program lifetime | wait-for -E pane-exit events |
3.8 | Yes, 3.8 |
| Wait for a pane the caller did not launch | wait-for -E; polls pane_dead below 3.8 |
3.8 | Partly |
| Event-driven waits for text or completion | wait-for -E |
3.8 (stated) | Yes, 3.8 |
| Incremental capture with cursors | history counters | 3.8 (stated) | Yes, 3.8 |
wait-for -l and -w |
new wait-for flags |
3.8 (stated) | Yes, 3.8 |
| Monitor hooks | set-hook -B/-T/-E |
3.8 (stated) | Yes, 3.8 |
tmux 3.8 formats, modal new-pane flags, JSON layouts |
new formats and flags | 3.8 (stated) | Yes, 3.8 |
| Capture line numbers and flags | capture-pane -L/-F |
3.7 (stated) | Yes, 3.7 |
| Library-managed control-mode features | control-client stability fixes | 3.7 (stated) | Yes, 3.7 |
run_shell returning output |
run-shell output behavior |
3.5 (shipped in #918) | Yes, 3.5 |
| Native program status, popup option removal | OSC 7501 pane_program_*; removed popup-* options |
3.9-dev (stated) | Yes, 3.9 |
The sessionless-server recipe was run on tmux 3.3a, 3.6 and 3.8a: under no config, a config that creates a session, and a config with exit-unattached on plus a session, the first call reported created, the second existing, and the server stayed up. Twelve parallel starters on one socket, 20 rounds per version, gave exactly one created every round.
Tracked in: launched programs #823, #833; unowned pane wait #869; event waits #673; capture cursors #740; wait-for -l/-w #870; monitor hooks #875; 3.8 formats #874; capture flags #876; control mode #884; run_shell #911; 3.9-dev #877, #878.
Proposal
Decisions:
- Default socket (
0.72.0->0.73.0): bareServer()warns on non-default$TMUXin Server(feat[socket]): Warn when bareServer()follows$TMUX#961 (Warn withFutureWarningwhen bareServer()follows non-default$TMUX#960, withServer.from_env()andfilterwarnings/PYTHONWARNINGSsuppression) and targets-L defaultin Server(feat[socket]): Target default server on bareServer()#962 (Server()without a socket follows an inherited$TMUXto another server #840; socket retention stacked on Server(feat[socket]): Target default server on bareServer()#962 in Keep session creation and returned handles on the selected socket #954 withoutlibtmux.engine). - Get-or-create (
0.72.0->0.73.0): one naming family, with read-onlycreated: boolandkill_on_exit: bool | Nonestaged in Session/Window/Pane(feat[ctx]): Warn on unowned__enter__#963 (Warn withFutureWarningbefore__exit__preserves unowned handles #959) -> Session/Window/Pane(feat[ctx]): Preserve unowned handles #964 (Create or reuse tmux resources with explicit cleanup ownership #804). - Server teardown (
0.72.0):Server(..., kill_on_exit=True)shipped in0.69.0(Scoping a Server no longer kills it #728); settle howServer.private()(AddServer.private()context manager #872) and resource ownership (Create or reuse tmux resources with explicit cleanup ownership #804) compose with it. - Capability reporting (
0.73.0+): one public API overlibtmux._internal.support.capabilities.
Ordering:
- Safe
Server.__exit__before the sessionless server ships (shipped in0.69.0via Scoping a Server no longer kills it #728). - Logging redaction, structured logging / failure ownership, and command /
wait-fortimeout consolidation (shipped in0.70.0via logging(feat): Document logging and define failure ownership #748, Command(feat[timeout]): Bound commands, waits, and listings #807). - Non-breaking fixes, opt-in checks, and single-reply
new_session()parsing (new_session()raises after creating a session in a newline path #942) in0.71.0ahead of breaking lifecycle changes and session ownership (Create or reuse tmux resources with explicit cleanup ownership #804). - Teardown-safe
Pane.__repr__(repr(pane)launches tmux clients and can raise during teardown #945 / Format pane handles using their stored ID #950) and safeSession.__exit__,Window.__exit__, andPane.__exit__in0.72.0before session and window get-or-create (libtmux(feat[get_or_create]): Add window and session helpers #920) ships. - Unstacked socket pinning (
Server()without a socket follows an inherited$TMUXto another server #840) and per-call client environment (Support per-call client flags, cleanenv/cwd, andspawn_client#882) onmasterbefore the sessionless server (0.72.0), without pullinglibtmux.engine(Engine(feat): Add raw-byte libtmux.engine seam and capabilities #739) forward. - Created-vs-reused and ownership (
0.72.0) before leases and launched-program lifetime (0.73.0+). - tmux 3.8 lifecycle features behind capability reporting (
0.73.0+), andlibtmux.engine/libtmux.aiooperations (Engine(feat): Add raw-byte libtmux.engine seam and capabilities #739, Aio(feat): Addlibtmux.aioand offlineReplayEnginetapes #738) last (0.74.0+).
Consolidation:
- Timeouts and log redaction (
0.70.0): shipped in Command(feat[timeout]): Bound commands, waits, and listings #807 (closing server(feat[wait]) Bound ordinary channel waits #809, Bound a tmux command that may never return #735, Bound every tmux command from a server-wide timeout, listings included #757) and logging(feat): Document logging and define failure ownership #748 (closing common(feat[logging]): Mask typed keys and buffer data in logs #905, common(feat[logging]): Let callers choose the logged argv redactor #906). - Unstack qualification drafts (Read the session ID and path from the creation reply #951, Distinguish blank pane captures from failed reads #952, Confirm exact session absence before removing saved state #955 for
0.71.0; Keep typed tmux text in UTF-8 under an ASCII locale #953 onmasterand Keep session creation and returned handles on the selected socket #954 on Server(feat[socket]): Target default server on bareServer()#962) fromengine-seam-minimal(Engine(feat): Add raw-byte libtmux.engine seam and capabilities #739) with privatetmux_cmdhelpers. - Sessionless server (
0.72.0): extract the working startup proof from the lifecycle draft into its own small change, then retire the draft (Lifecycle(feat): Add server defaults and owned scopes #771). - Retire the older bundle whose pieces now have their own homes (API(feat): Add owned scopes and command results #758).
- Discovery (
0.72.0): choose one of the three APIs. - Capture cursors and bounded waits (
0.73.0+): pick one implementation of each.
Tracking:
- Topic labels (
area: lifecycle,area: observation,area: engines,area: options-formats,area: tmux-versions,area: logging),requires: tmux 3.8,requires: tmux 3.9-dev,blocked,documentation,roadmap. - Milestones 0.68.0, 0.69.0, and 0.70.0 closed; Milestones 0.71.0, 0.72.0, 0.73.0, and 0.74.0 aligned with 0.63.x and beyond Roadmap #907 so non-breaking fixes ship first and engine operations land last.
- Trim the broader roadmap ([Agentic DX] libtmux: consolidated roadmap (core + async + engines) #629) into a pointer to 0.63.x and beyond Roadmap #907, Lifecycle roadmap: overlaps, conflicts, blockers and tmux version gates #925, and Bullet proofing for
capture_pane#456.
References
- Release plan: 0.63.x and beyond Roadmap #907. Broader roadmap: [Agentic DX] libtmux: consolidated roadmap (core + async + engines) #629.
- rmux, for API comparison:
Session::was_created()(session.rsL98), and an owned session that only ever creates (owned_session.rsL129).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn Progress
Activity
Session(docs[new_window]): Note reuse with exit (#926)
Session/Window/Pane(feat[ctx]): Preserve unowned handles
Session/Window/Pane(feat[ctx]): Warn on unowned __enter__
Session/Window/Pane(feat[ctx]): Preserve unowned handles