Repository navigation
Conversation
…s pid
tmux 3.8 prints #{pane_pid} blank once a pane's program has exited.
parsePaneRows() skipped any row without a numeric pid, so the watcher
never saw an exited agent: the session stayed idle with no paneExit and
the clean-exit sweep (Ark0N#446) never closed it. reconcileSessions() read the
same rows, so at server start such a session's record was dropped while
its tmux session stayed on the socket.
Keep a dead row with no pid (a live one is still a bad read), tell one
exit from the next by #{pane_dead_time} next to the pid, and keep a
tracked session with a dead pane alive with its last known pid. An
untracked one is still not rediscovered: a made-up pid would reach
killSession()'s process-tree walk.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
killSession() read `#{pane_pid}` and fell back to the recorded pid when
tmux printed none, which tmux 3.8 does for every dead pane. That pid
belongs to the program that exited; the OS may have reused it, and the
kill path walked its process tree and SIGKILLed it. It now reads
`#{pane_dead}` with the pid (parsePaneKillRead) and, for a dead pane,
only runs kill-session. Survivors of an exited program were already out
of reach (reparented, and the group kill only ran for a live leader),
so nothing a live pane gets is lost. Strategies 1 and 2 move into
killPaneProcessTree() unchanged.
Docs: the architecture-invariants paragraph says a kept dead pane is
respawned by the restore at the next server start (measured on tmux
3.8; tmux 3.7 and older always did this), and describes the kill rule.
CLAUDE.md's paneExit rule gains the no-pid warning. The
PaneExitObservation comment no longer claims tmux before 3.4 lacks
`#{pane_dead_time}`, which was never measured.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Pushed df494b2 after a review pass against CLAUDE.md:
Checks on df494b2:
Hand-tested on tmux 3.8 with an isolated socket and data dir:
🤖 Generated with Claude Code |
…ts pid The kill rule was pinned only through parsePaneKillRead(). Drive killSession() with tmux commands enabled and exec answering like tmux 3.8 (a dead pane, pid blank), and assert nothing signals the recorded pid while kill-session still runs. Against bee4948 it fails: pid 4242 is signalled 201 times. Group the three no-pid tests in their own describe instead of the launch-cwd one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
One more review pass, and 67aa28a:
Gates pass, and the tmux, pane-cwd, pane-exit and sweep tests pass (228). Ready for review. Two related pre-existing things that this PR doesn't change, for a possible follow-up:
🤖 Generated with Claude Code |
|
Thank you @kkalisz for this one. With it, Codeman sees an exited agent on tmux 3.8, where a dead pane's pid prints blank, and the close path no longer signals that pane's stale recorded pid. The diagnosis matches tmux's own source (pane_pid is only printed while the pane's fd is open). Every change keeps the old behaviour on tmux 3.7 and older, and the new tests fail on master and on your first commit in the places they should. Typecheck, lint, the full test gate and CI are all green, so this is ready to merge. There are two small things to adjust at merge time. You don't need to change anything for them:
The other |
Review follow-ups on Ark0N#840: `#{pane_dead_time}` is stamped in whole seconds, so two same-status exits in one second read as one; and the changeset tells users how to remove a dead codeman-* session orphaned before this fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Pushed d7c141e2 with both merge-time notes, so nothing is left to adjust:
Comments and changeset only. Typecheck, lint, format:check and the tmux tests pass. |
|
Thank you @kkalisz for this one, and for the quick d7c141e. With it, Codeman sees an exited agent on tmux 3.8 and keeps the session across a restart. Closing a dead pane also no longer signals its stale pid. I checked it against tmux 3.8's source and ran it end to end with a shim that prints 3.8's pane formats over a real 3.4. The bug reproduces on the base and is gone on this branch. Typecheck, lint, the full test gate and CI are green, it merges cleanly with current master, and both earlier notes are done. A second pass found two edge cases the first one missed, and the changeset and tests need a little more. These are fixes for merge time, so nothing is needed from you:
One thing is outside this PR and the same on master: on 3.8 The next step is to merge with these fixes applied. Thanks again for the careful work. |
…it sign
Review follow-up on the tmux 3.8 dead-pane fix.
- parsePaneRows() skipped a row with a blank pid and pane_dead 0. tmux
blanks the pid when the pty closes, and pane_dead turns 1 only once
the exit status is collected (seconds for some exits on tmux 3.4), so
a restart in that window dropped the session. Only a row with neither
a pid nor a dead flag is skipped now.
- Before tmux 3.7 pane_dead means only that the pty is closed. The kill
read now also reads #{pane_dead_time}, and counts a pane as dead only
with a blank pid or a set exit time, so a program that closed its tty
and ignores SIGHUP is still killed on tmux 3.3a to 3.6.
- Tests pin the last two pane format fields and add a live-pane
counterpart to the dead-pane kill test.
- Changeset notes that finished sessions piled up on 3.8 are relaunched
once at the first start after the update.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the second pass. Pushed ccf502b with all four items, so nothing is left to apply at merge time:
Typecheck, lint, format and the frontend checks pass, and the 4 pane test files pass (231 tests). The 🤖 Generated with Claude Code |
…ads /proc The live-pane close test mocked process.kill to always succeed, so the pane never exited and the kill path's wait polled isProcessRunning(). On Linux that reads /proc/<pid>/stat, which this file mocks to return undefined, and the test threw "Cannot read properties of undefined (reading 'lastIndexOf')". macOS skips that read, so it passed locally. The mock now models a pane that exits on its first real signal, after which kill(pid, 0) throws ESRCH. Reproduced the CI error locally by forcing the Linux branch; it passes with this change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you @kkalisz for the quick ccf502b and 891f3a1. With this PR Codeman sees an exited agent on tmux 3.8, and closing a session no longer signals a dead pane's stale pid. All four items from the last round are in. The closing-window row and the live-pane test are right, and CI is green. One thing has to change before this can merge. Two earlier rounds missed it, and the second-sign rule I asked for last time makes it reachable on more tmux versions, so part of this comes from my own request. The blocker is at I tested the change below. It gives the same signals as master for an empty pane and keeps the pane tests green: // parsePaneKillRead(): 0 is no usable pid, but it is not a blank one either
const pid = parsedPid > 1 ? parsedPid : null;
const exited = pidField === '' || !Number.isNaN(parseInt(deadTimeField, 10));
// killSession()
const knownPid = pane.pid ?? session.pid;
const currentPid = !pane.dead && knownPid > 1 ? knownPid : null;The Please add these as well:
There are also three smaller test gaps. Each of these one-line mutations leaves the tests green:
One optional point: the comment at Nothing else is open. The next step is a push with the guard and its tests, and then this can merge. Thank you for your patience. |
Resolves the killSession() conflict with babb55e (never signal pid 0 or 1). The dead-pane read decides first; a pid that is not signalable (isSignalablePid) then also means nothing is signalled and only `tmux kill-session` runs. killPaneProcessTree() sends every signal through signalProcess(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you @kkalisz for merging master and resolving the conflict with babb55e. With this PR Codeman sees an exited agent on tmux 3.8 and keeps its session across a restart. It also stops signalling a dead pane's stale pid. The blocker from the last round is gone. I compared your head with master's killSession() over ten pane answers, with These are fixes for merge time, so nothing is needed from you:
I have the first three written and tested. Your pane tests stay green with them, and the new cases fail on your head where they should. I withdraw one request from my last comment, the pid guard in The next step is to merge with these fixes applied. Thank you for staying with this through four rounds. |
Review follow-up (owner's merge-time items, applied here).
- killSession() used `pane.pid ?? session.pid`, which kept tmux's 0 for
an empty active pane (`split-window ''`: `1|0|` up to tmux 3.6, `0|0|`
on 3.7) beside a running agent, so the close signalled nothing where
master signals the agent's tree. `||` restores that; isSignalablePid()
still refuses 0 or 1.
- kill-pid-guard.test.ts answered the old pid-only read, which the
three-field parser read as no pid, so no case gave killSession() tmux's
own 0. Its mock now answers the kill read, with cases for `1|0|`,
`0|0|` and `0||` against a recorded agent pid and a recorded 0.
- Tests pin the whole kill read format, and the reconcile rule that a
pane without a pid never overwrites a live pane's pid. Dropping
`#{pane_dead_time}`, using `??` or `pane.pid` alone, or a plain
`active.set(...)` each fail now.
- parsePaneKillRead() cases for `1|0|`, `0|0|` and `1|-1|`.
- Comments and docs: the blank pid with a late dead flag is tmux 3.8;
on 3.4 only the seconds to collect the status were measured. A pid
below 2 is no pid. The recorded pid is unreaped in the closing window
only when it is the pane's start pid (`respawn-pane` breaks that).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks. I applied the merge-time items myself in 9309500, so you don't need to:
🤖 Generated with Claude Code |
|
Thank you @kkalisz for 9309500. With this PR, Codeman sees an exited agent on tmux 3.8 and keeps its session across a restart, and closing a dead pane no longer signals its stale recorded pid. All four merge-time items from my last comment are in. I also tried nine one-line mutations of the new rules, and each one now fails a test: One small fix is left for merge time, and you don't need to change anything for it:
The next step is to merge with that applied. Thank you for staying with this, and for the careful tmux 3.8 measurements. |
Problem
On tmux 3.8, a session whose agent exited cleanly (
/exit, Ctrl+C twice) is never seen as exited. It stays on the board asidlewithpaneExit: null, and the clean-exit sweep from #446 never closes it. Attaching to it shows only tmux'sPane is dead (status 0, …).The reason: once a pane's program has exited, tmux 3.8 prints
#{pane_pid}blank. The comments around the pane watcher say its behaviour was measured on tmux 3.2a, which still reported the pid there.parsePaneRows()skips any row whose pid is not a number:So the one row that carries the exit is thrown away before
derivePaneExits()sees it.Seen on a real install (Codeman 1.51.0, macOS, tmux 3.8), with the watcher's own format:
GET /api/sessionsstill showed that session as"status": "idle", "paneExit": nullminutes later.The same rows also feed
reconcileSessions(), so there is a second effect at server start. A tracked session whose only pane is dead is missing from theactivemap, so it is reported dead and its record is deleted. Its tmux session stays on the socket, and the rediscovery loop skips it for the same reason, so nothing ever lists it again.Fix
All in
src/tmux-manager.ts:parsePaneRows():pidis optional on a dead row. A row with no pid is kept when#{pane_dead}is1and still skipped otherwise, since a live pane with no pid is a bad read.applyPaneExits()used the pane pid to tell "the same dead pane, read again" from "a second command in the same pane that also exited the same way". With the pid blank, that would treat every exit as the same one.PANE_LIST_FORMATnow also reads#{pane_dead_time}(inserted before#{pane_current_path}, which has to stay last), andsameExitcompares it next to the pid. tmux stamps it once per exit, so two reads of one exit still count as 2 for the sweep, and a hand-runrespawn-panewhose command exits 0 again starts a new observation. On a tmux without the variable the field is empty and the pid works as before.reconcileSessions():activeholds every session on the socket, with its pid when tmux printed one. A tracked session with a dead pane stays alive and keeps its last known pid, which is what tmux reported before 3.8. An untrackedcodeman-*session with no pid is still not rediscovered: a made-up pid would reachkillSession()'s process-tree walk. That matches what happens today.Kept alive also means restored: at the next server start the restore takes the dead-pane branch of
Session._setupOrAttachMuxSession(), which respawns the pane and clearspaneExit. That is what tmux 3.7 and older always did, since they still printed the pid, but it means a row kept as crash or startup-error evidence lasts across a restart only until the CLI is relaunched in it.killSession(): it read#{pane_pid}and fell back to the recorded pid when tmux printed none, which tmux 3.8 does for every dead pane. That pid belongs to the program that exited, and the OS may have reused it, so the kill path could walk and SIGKILL an unrelated process's tree. It now reads#{pane_dead}with the pid (parsePaneKillRead()) and, for a dead pane, only runskill-session. Nothing a live pane gets is lost: an exited program's survivors were already out of reach (reparented, and the group kill only ran for a live leader). Strategies 1 and 2 move unchanged intokillPaneProcessTree().docs/architecture-invariants.md(the paneExit section) records the tmux 3.8 behaviour next to the existing tmux 3.2a measurements, the respawn on restart, and the kill rule. The paneExit rule inCLAUDE.mdgains the no-pid warning.Tests
parsePaneRows: a dead pane with a blank pid is kept with its status and exit time; a live pane with a blank pid is still skipped; the exit time is read, and is undefined while the pane runs.derivePaneExits: a clean exit is reported from a dead pane with a blank pid.reconcileSessions: a tracked session whose only pane is dead with no pid stays alive and keeps its pid; an untracked one is not rediscovered.parsePaneKillRead: a live pane reads as its pid; a dead pane reads as dead whether tmux printed its pid or left it blank; an unreadable answer is not dead, so the recorded pid is still used.killSession(tmux commands enabled, exec answering like tmux 3.8): a dead pane is closed withkill-sessionand its recorded pid is never signalled. Against the first commit of this PR it fails: the recorded pid is signalled 201 times.test/tmux-manager.test.tsandtest/pane-cwd-tracking.test.tsthat include a path get one more empty field for the exit time. That change is mechanical and every assertion is unchanged.The new parser, derive, bookkeeping and tracked-session tests fail on
masterand pass with the fix. The rediscovery test passes on both, since it pins the current behaviour.By hand, on a real tmux 3.8 with Codeman on its own socket and data dir. In each run, a shell session's pane was made to exit with a hand-run
respawn-pane 'exit 0', and tmux then lists it ascodeman-xxxx||1|0|<time>:masterkept itidlewithpaneExit: nullfor the whole 24 s.paneExit: {status: 0}and keeps the row, which is the startup-error rule.masterdrops the record and leaves the dead tmux session on the socket (mux-sessions.jsonempty). This branch keeps it, and the restore respawns the pane.Killing session codeman-… (pane dead, PID 13283 not signalled)and removes the tmux session. A live pane still logs(PID 13706)and takes the usual tree kill.The branch also merges cleanly with current
master, and typecheck and the tmux tests pass on the merged tree.npm run typecheck, lint, format:check, check:frontend-syntax and check:browser-excludes pass. Fullvitest run(at df494b2): 17075 of 17144 pass. The 69 failures are in the same 20 files unrelated to tmux (git, cron, remote files, folder routes and so on) that fail onmasteron this machine.Follows up #446.
🤖 Generated with Claude Code