Repository navigation
Description
Summary
Add an owned application API that starts literal argv in a PTY, accepts interactive input, and returns the application's exit status or signal with a bounded final screen. The existing Request and control-watch machinery owns asynchronous work, but the public core has no Program owner combining application startup, completion and teardown.
Motivation
A Lua or Neovim caller can create a pane, send input and capture its screen, but must assemble application completion, final-output accounting and cleanup itself. Server:command completion and a visible-text match provide narrower evidence. The draft resource-lifecycle PR #27 overlaps ownership machinery and needs reconciliation before Program implementation proceeds.
Evidence
Current source and scope
Source inspection at 8c4def75911a9db561f27c5426a1befa3d02bff1:
Server:commandsubmits one native command through the existing asynchronous execution path.- Domain launch encoding already separates literal launch data from shell source.
- The capability table drives feature metadata; version evidence fences the daemon PID, start time and version.
- Lifecycle(feat): Add owned tmux resource scopes #27 remains a draft with unresolved accepted-daemon cleanup failures and pending floor/installed qualification. Its branch is not trunk support.
This is a source-backed proposal. No new Lua runtime qualification was performed for this issue.
Proposal
Deliver Server:start_program(argv, options) returning a Request for an owned Program, an owning run-to-completion call, and Request-returning wait, input, screen and stop operations. Preserve existing value/error settlement and expose status/signal, output loss and cleanup receipts. Reuse domain encoding, bound endpoints, runtime scopes and control watches; extend appropriate #27 machinery rather than adding a competing lifecycle engine.
- Copy and validate argv, cwd, environment, geometry and limits before effects. Preserve singleton executables, empty later arguments and metacharacters as data. Reject invalid or unrepresentable requests before creation.
- Extend the existing registry and generated manifest for the program contract and required event/drain primitives; use Expose the capability map through the public API #104 for public capability discovery. Bind decisions to the connected daemon evidence. Qualify the first path on released tmux 3.8, with pre-effect refusal below each requirement or for unknown profiles unless an equivalent fallback is evidenced. Test patch/prerelease policy, client/daemon mismatch, replacement and manifest drift.
- Register lifetime and completion observation before release. Keep application exit, shell-command completion and visible readiness distinct. Return normal status versus signal and bounded final rendered bytes, with merged PTY stdout/stderr, encoding rules and explicit history/byte loss.
- Separate waiter timeout/cancellation from owning-run cancellation. On owning cancellation, stop and join accepted resources while retaining primary and cleanup failures and a recoverable owner for incomplete cleanup.
- Fence input and cleanup against external respawn, pane removal, daemon replacement and reused IDs. Establish process-group termination with ignored TERM, owner death and orphan recovery; state the limit for descendants that daemonize and for filesystem locality.
- Keep both luv and Neovim event loops responsive with bounded callbacks, queues and retained bytes. Lua 5.1 requires explicit scopes; neither
__gcnor Lua 5.4-only__closeestablishes the portable cleanup contract. - Add native tests for fast exit/final writes, interactive input, pressure, setup/wait/run cancellation, replacement and cleanup on owned sockets, with negative controls for critical gates. Run floor/current adapters, an installed rock consumer, complete command/interactive/cancellation examples, LuaLS/native docs checks and exact-head CI.
- Document capability discovery, rendered screen versus terminal stream and cleanup recovery; keep changelog-only commits separate. Preserve Lifecycle(feat): Add owned tmux resource scopes #27's unresolved failures and Fix what the verification pass flagged #51's remaining qualification findings.
Raw replayable streams, borrowed-shell OSC 133 completion and layout work remain follow-ups. Existing visible-text waiting retains its own contract. No MCP server exists in this trunk; a future adapter should share core-owned program handles and capability/status/loss/cleanup data.
References
- tmux, released 3.8 event waiters and pending-waiter claims.
- Expose the capability map through the public API #104 owns capability discovery; Add a standalone, CI-run example program for each core capability #84 owns standalone capability examples and should consume this API when it exists.
Completion and cancellation cases for an owned program
On native tmux 3.8, a staged command that exited with status 23 produced a 26-byte final screen when completion was armed before releasing it. A later lookup of an already-removed pane returned target_missing. Capture the exit result and bounded output while the program is still owned.
A second case respawned a different program in the same pane before a pending stop was dispatched. The pane ID then resolved to the replacement group. The original group was still alive. A Linux prototype that retained the original group identity could retire that group. A child that created its own session survived group retirement, and killing the sole owner also left its group alive.
Include fast exit, respawn, owner death and a detached descendant in the acceptance cases. The public contract still needs to define what completion and cancellation promise on each supported host. PR 27 supplies the related tmux object-ownership work.
Activity
tony commentedon Dec 5, 2026
Draft PR 154 runs a syntax check twice in a private tmux server. Both commands print
doneand close their panes. Lua can still tell the valid file exited 0 and the invalid file exited 23. An explicit exit 143 and a death by SIGTERM give different structured results.The checkout experiment covers the immediate exit, a pane reused for another command, and looking up the result after the server stops. A caller that loses the supervising process before receiving the result gets an unknown outcome. The standalone Linux tests leave restart recovery, a complete terminal transcript, detached descendants and a public Neovim API open. Examples and limits
tony commentedon Dec 5, 2026
Lua can tell whether a terminal command succeeded after tmux closes its pane. The Program example ran from a clean development install on Lua 5.1.5 with tmux 3.3a, Lua 5.5.1 with tmux 3.8, and in Neovim 0.12.5. Two commands can leave the same text on screen and return different exit codes. Program PR #154 · Exit-code test #208.
I also tested what happens if the Lua script itself exits after starting an app. I started
/bin/catwithserver:start_program()on a private tmux 3.8 server that already had another session. Once the call returned, I ranos.exit(23)in the script. On Lua 5.5.1 and Neovim 0.12.5, the app and its supervisor exited, tmux closed their pane, and the other session stayed open. Both runs left one empty/tmp/libtmux-lua-program-*directory. Callingprogram:stop():await()before exiting removed it.The earlier PR and private 0.1.2 candidate behaved the same. The two socket files were gone before the script exited. The directory stayed until cleanup ran in the script that created it. Original cleanup.
PR #154 now releases the directory once both connections are open. The running app can still send output and report its exit status. I tested the revised branch and the freshly installed private 0.1.2 rock. All eight combinations of normal stop or immediate script exit, standalone Lua or Neovim, and tmux 3.3a or 3.8 kept the original session and left no Program directory. Recovery if the script exits during setup or if the supervisor disappears remains open. Corrected channel · Regression through the public API.
tony commentedon Dec 6, 2026
Closing the Lua runtime while tmux was creating a Program session could
return
cancelledwithout telling the caller which session to inspect.The request had already sent
new-session, so the caller could not tellwhether a pane remained.
PR #154 now returns
err.cleanup_error.code == "cleanup_failed"and thesession name in
err.program_namewhen libtmux cannot confirm the paneclosed. A caller can look up that name on the same tmux server. This
applies to both
Server:start_programandServer:run_program.Program guide
The regression closes the runtime immediately after the request sends
new-session. It covers both calls, before and after the supervisorconnects. With the previous rock, it expected
cleanup_failedand gotnil. With the corrected rock installed in a fresh directory, it readthe cleanup error and the expected session name on Lua 5.1 and 5.5.
Server regression
If Lua restarts
With the installed 0.1.2 candidate on Linux, the same test passed on Lua 5.1.5 with tmux 3.3a and on Lua 5.5.1 with tmux 3.8. On each pair, a second Lua process could inspect the session named by the first process. The test let tmux create the session and delayed its reply. When the first process closed its runtime, it saved
err.program_namefrom the retired request. Bothstart_programandrun_programreturned a name.Before launch, the first process also recorded tmux’s process ID, start time and version using
server:command({ "display-message", "-p", "#{pid} #{start_time} #{version}" }). After reconnecting, the second process compared those values and calledserver:snapshot({ strict = true })on the same handle. Looking upsnapshot.sessions:where({ name = saved_name })found the retained session. With normal pane removal the lookup returned zero matches. The unrelated session stayed open.A replacement tmux daemon at the same socket accepted a session with the same name. Comparing the recorded values caught the replacement before the reader inspected it. If the original Lua process exits before it receives the error, it has no receipt to save. The original Program handle and its exit result belong to that process.