Skip to content

fix(tmux): see an exited agent on tmux 3.8, which blanks a dead pane's pid - #840

Open
kkalisz wants to merge 8 commits into
Ark0N:masterfrom
kkalisz:fix/dead-pane-blank-pid
Open

kkalisz wants to merge 8 commits into
Ark0N:masterfrom
kkalisz:fix/dead-pane-blank-pid

Conversation

@kkalisz

@kkalisz kkalisz commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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 as idle with paneExit: null, and the clean-exit sweep from #446 never closes it. Attaching to it shows only tmux's Pane 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:

const pid = parseInt(fields[1] ?? '', 10);
if (!sessionName || Number.isNaN(pid)) continue;

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:

$ tmux -L codeman list-panes -a -F '#{session_name}|#{pane_pid}|#{pane_dead}|#{pane_dead_status}|#{pane_dead_signal}|#{pane_current_path}'
codeman-55ad9fd1||1|0||

GET /api/sessions still showed that session as "status": "idle", "paneExit": null minutes 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 the active map, 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(): pid is optional on a dead row. A row with no pid is kept when #{pane_dead} is 1 and still skipped otherwise, since a live pane with no pid is a bad read.
  • Exit identity: 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_FORMAT now also reads #{pane_dead_time} (inserted before #{pane_current_path}, which has to stay last), and sameExit compares 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-run respawn-pane whose 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(): active holds 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 untracked codeman-* session with no pid is still not rediscovered: a made-up pid would reach killSession()'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 clears paneExit. 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 runs kill-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 into killPaneProcessTree().

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 in CLAUDE.md gains 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.
  • Pane-exit bookkeeping: with no pid, repeated reads of one exit count up to 2; a new exit time starts the count again.
  • 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 with kill-session and its recorded pid is never signalled. Against the first commit of this PR it fails: the recorded pid is signalled 201 times.
  • The existing fixtures in test/tmux-manager.test.ts and test/pane-cwd-tracking.test.ts that 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 master and 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 as codeman-xxxx||1|0|<time>:

  • Sweep: after 12 s of uptime, this branch closed the session within 2 s. master kept it idle with paneExit: null for the whole 24 s.
  • Exit within 10 s of start: this branch publishes paneExit: {status: 0} and keeps the row, which is the startup-error rule.
  • Restart while that row is kept: master drops the record and leaves the dead tmux session on the socket (mux-sessions.json empty). This branch keeps it, and the restore respawns the pane.
  • DELETE: on a dead pane this logs 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. Full vitest 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 on master on this machine.

Follows up #446.

🤖 Generated with Claude Code

kkalisz and others added 2 commits November 19, 2026 15:11
…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>
@kkalisz

kkalisz commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Pushed df494b2 after a review pass against CLAUDE.md:

  • killSession() no longer signals the recorded pid of a dead pane. It used to read #{pane_pid} and fall 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 closing the session could walk and SIGKILL an unrelated process's tree. The kill path now reads #{pane_dead} with the pid (parsePaneKillRead(), unit-tested) and, for a dead pane, only runs kill-session. Strategies 1 and 2 moved unchanged into killPaneProcessTree(). A live pane is killed exactly as before.
  • Docs: restart respawns a kept dead pane. The architecture-invariants paneExit paragraph now says that a dead pane kept alive by reconcileSessions() is respawned by the restore at the next server start, which clears paneExit. I measured this on tmux 3.8. tmux 3.7 and older always did it, but a row kept as crash or startup-error evidence lasts only until then. The paragraph also describes the kill rule.
  • CLAUDE.md: the paneExit rule gains the warning that a dead pane may have no pid, so its row must never be skipped and its recorded pid never signalled.
  • PaneExitObservation comment: it no longer claims tmux before 3.4 lacks #{pane_dead_time}, which was never measured. It is rewrapped to 120 columns.
  • Changeset: gains a sentence about the close path.

Checks on df494b2:

  • typecheck, lint, format:check, check:frontend-syntax, check:browser-excludes: pass.
  • tmux, pane-cwd, pane-exit and sweep tests: 227 pass.
  • Full vitest run: 69 failures in the same 20 non-tmux files as master here.
  • The branch merges cleanly with current master.

Hand-tested on tmux 3.8 with an isolated socket and data dir:

  • Sweep: an exited pane was closed by the sweep within 2 s. On master it stayed idle.
  • Restart: on master the record was dropped and the dead tmux session orphaned. This branch keeps the session and respawns it.
  • DELETE: on a dead pane it logs pane dead, PID … not signalled and removes the tmux session. A live pane still gets the tree kill.

🤖 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>
@kkalisz

kkalisz commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

One more review pass, and 67aa28a:

  • killSession()'s dead-pane rule was pinned only through parsePaneKillRead(). There is now an end-to-end test: tmux commands are enabled, and exec answers like tmux 3.8 (dead pane, blank pid). It asserts that the recorded pid is never signalled and that kill-session still runs. Against the first commit of this PR it fails, because the recorded pid is signalled 201 times.
  • The three no-pid tests now have their own describe instead of sitting in the launch-cwd one.

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:

  • The stats collector still runs ps -p on the recorded pid of a dead pane, so the monitor can show a reused pid's numbers. That is display only.
  • killSession() falls back to the recorded pid when the display-message read fails outright (the tmux session is already gone), as it did before.

🤖 Generated with Claude Code

@kkalisz
kkalisz marked this pull request as ready for review November 24, 2026 14:42
@Ark0N

Ark0N commented Nov 24, 2026

Copy link
Copy Markdown
Owner

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:

  • .changeset/dead-pane-blank-pid.md: add one sentence telling affected users that a dead codeman-* tmux session orphaned before this fix is still not rediscovered (src/tmux-manager.ts:3644), and that it can be removed with tmux -L codeman kill-session -t codeman-<id>.
  • src/tmux-manager.ts:286-289 and :3965-3968: note that #{pane_dead_time} is stamped to the second, so two exits with the same status in the same second read as one.

The other #{pane_pid}-only reads (getPanePid() after a respawn, listPanes(), and the stats ps -p you already flagged) are outside this PR. Thanks again for the careful measurements on a real tmux 3.8.

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>
@kkalisz

kkalisz commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Pushed d7c141e2 with both merge-time notes, so nothing is left to adjust:

  • .changeset/dead-pane-blank-pid.md: one sentence that a dead codeman-* session orphaned before this fix is still not rediscovered, and that tmux -L codeman kill-session -t codeman-<id> removes it.
  • src/tmux-manager.ts: the PANE_LIST_FORMAT and applyPaneExits() comments now say #{pane_dead_time} is stamped to the second, so two same-status exits in one second read as one.

Comments and changeset only. Typecheck, lint, format:check and the tmux tests pass.

@Ark0N

Ark0N commented Nov 24, 2026

Copy link
Copy Markdown
Owner

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:

  • src/tmux-manager.ts:397: a blank pid with pane_dead 0 is a real state on 3.8, so the row should not be skipped as a bad read. The pid goes blank when the pty closes, and pane_dead turns 1 only once tmux has collected the exit status. On tmux 3.4 here that took several seconds for some exits. A restart in that window still drops the session and orphans its tmux session. The fix is to keep every row whose pane_dead tmux answered (pid === undefined && dead === undefined as the skip condition). The test at test/tmux-manager.test.ts:1514 and the sentence in docs/architecture-invariants.md change with it.
  • src/tmux-manager.ts:428: before tmux 3.7, pane_dead means only that the pty is closed. On 3.4 a program that closed its tty and ignores SIGHUP now survives a close that killed it before. Reading #{pane_dead_time} as well, and trusting a dead reading only when the pid is blank or that time is set, keeps the 3.8 fix and restores the old close on 3.3a to 3.6.
  • .changeset/dead-pane-blank-pid.md: add a sentence that finished sessions which piled up on 3.8 are relaunched at the first start after the update (two out of two in my run).
  • test/tmux-manager.test.ts:1235: assert the last two fields of the pane format, since dropping #{pane_dead_time} from it leaves every test green. Your dead-pane kill test also needs a live-pane counterpart.

One thing is outside this PR and the same on master: on 3.8 createSession() (src/tmux-manager.ts:2856) and respawnPane() (:3083) read a blank pid as a failed launch when the CLI exits at once.

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>
@kkalisz

kkalisz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the second pass. Pushed ccf502b with all four items, so nothing is left to apply at merge time:

  • src/tmux-manager.ts parsePaneRows(): a row is now skipped only when tmux answered neither a pid nor #{pane_dead}. A blank pid with pane_dead 0 (pty closed, exit not collected yet) keeps the session. The test and the docs/architecture-invariants.md sentence changed with it, and so did the CLAUDE.md line.
  • The kill read is now #{pane_dead}|#{pane_pid}|#{pane_dead_time}. A pane counts as dead only when the flag is 1 AND either the pid is blank or the exit time is set, so tmux 3.3a to 3.6 keep the old close for a program that closed its tty and ignores SIGHUP. In the 3.8 closing window the recorded pid is still used as the fallback, which is safe because tmux has not reaped that process yet. Checked on a real tmux 3.8: live 0|<pid>|, dead 1||<time>.
  • .changeset/dead-pane-blank-pid.md: added that finished sessions piled up on 3.8 are relaunched once at the first start after the update.
  • Tests:
    • The reconcile test asserts |#{pane_dead_time}|#{pane_current_path}'.
    • There is a live-pane counterpart to the dead-pane kill test: the pid tmux printed is signalled, not the recorded one.
    • New parsePaneKillRead cases cover pre-3.7.
    • With the previous src, the closing-window test and the pre-3.7 kill test fail.

Typecheck, lint, format and the frontend checks pass, and the 4 pane test files pass (231 tests). The createSession()/respawnPane() blank-pid launch issue you noted is left out of this PR, as you suggested.

🤖 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>
@Ark0N

Ark0N commented Nov 25, 2026

Copy link
Copy Markdown
Owner

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 src/tmux-manager.ts:3472 (with :443-444): a pane pid of 0 reaches the tree kill. An empty pane (tmux split-window '' or split-window -I) has no process. tmux 3.2a to 3.6 print 1|0| for it under the new kill read (measured on 3.4), and 3.7 prints 0|0| (from its source). parsePaneKillRead() reads both as { dead: false, pid: 0 }, and pane.pid ?? session.pid keeps the 0, where || used to fall back to the recorded pid. killPaneProcessTree(mode, 0) then walks the children of pid 0, which is the whole machine up to the walk's 500-process cap, and process.kill(-0, ...) signals the server's own group. I confirmed it in vitest with process.kill stubbed and a fake ps table. Master signals only the recorded pane's tree, and this branch signals everything. Please do not reproduce it by hand, because it ends every process of your user.

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 pane dead, PID ... not signalled log line then also covers "no usable pid", so its wording needs a small change.

Please add these as well:

  • parsePaneKillRead cases for 1|0|, 0|0| and 1|-1|, and a killSession test that answers 1|0| and asserts that only the recorded pid's tree is signalled. Stub process.kill as you do now, and mock ps too, because the walk reads the real process table.
  • The same guard in parsePaneRows() at src/tmux-manager.ts:400 (a pid below 2 is not reported). Without it reconcileSessions() writes 0 over the recorded pid for such a session. Master does that too, but you are changing these lines, and your comment at :3663 states the rule.
  • One clause in the CLAUDE.md line and in docs/architecture-invariants.md saying that a pid below 2 is no pid (an empty pane prints 0 before tmux 3.8).

There are also three smaller test gaps. Each of these one-line mutations leaves the tests green:

  • Dropping #{pane_dead_time} from the kill read (:2941). Assert the whole format in the two kill tests.
  • Replacing pane.pid ?? session.pid with pane.pid. Add a killSession case for 0||, the closing window.
  • Replacing the rule at :3601 with a plain active.set(...). Add a reconcile case with one live pane and one pane without a pid.

One optional point: the comment at :3469 says the recorded pid cannot have been reused. That holds only when it is the pid the pane was started with, and a hand-run respawn-pane breaks that.

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>
@Ark0N

Ark0N commented Nov 25, 2026

Copy link
Copy Markdown
Owner

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 process.kill and ps stubbed, and your head signals nothing outside the session in any of them. CI is green.

These are fixes for merge time, so nothing is needed from you:

  • src/tmux-manager.ts:3490: pane.pid ?? session.pid keeps tmux's 0. Closing a session with an empty active pane (split-window '', which answers 1|0| up to tmux 3.6 and 0|0| on 3.7) beside a running agent therefore signals nothing now. Master signals the agent's tree there, and so does your branch on 3.8, where that pane answers 0||. kill-session alone is not enough: on tmux 3.4 a program that ignores SIGHUP and a setsid child both survived it. pane.pid || session.pid restores the old behaviour, and isSignalablePid() still refuses 0.
  • test/kill-pid-guard.test.ts:54: the mock still answers the old pid-only read, which your three-field parser reads as no pid. So every close in that file goes through the recorded pid, and none of them gives killSession() tmux's own 0. The mock has to answer the new format, with cases for 1|0|, 0|0| and 0||.
  • src/tmux-manager.ts:2941 and :3622: the tests stay green if you drop #{pane_dead_time} from the kill read, or replace the reconcile rule with a plain active.set(...). Both need a test that pins them.
  • test/tmux-manager.test.ts:1575: the comment says the blank pid and the late dead flag come from tmux 3.4. On 3.4 the pid stays and the flag is set immediately. Only the seconds to collect the status were measured there.

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 parsePaneRows(): babb55e leaves a recorded 0 on the record on purpose and pins it in a test.

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>
@kkalisz

kkalisz commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. I applied the merge-time items myself in 9309500, so you don't need to:

  • killSession() uses pane.pid || session.pid again. An empty active pane (1|0| up to 3.6, 0|0| on 3.7) beside a running agent signals the agent's tree, as master does, and isSignalablePid() still refuses 0 and 1.
  • test/kill-pid-guard.test.ts mocks the three-field kill read. It has cases for 1|0|, 0|0| and 0||, each against a recorded agent pid (that pid's tree is signalled and nothing else) and against a recorded 0 (nothing is signalled). Each case also asserts that the close sent the three-field format.
  • Pinned by tests: the whole kill read format in both kill tests, and the reconcile rule. The new reconcile case has a split session with the live pane first and a pane without a pid second. Each of these mutations now fails a test: dropping #{pane_dead_time}, ??, pane.pid alone, and a plain active.set(...).
  • parsePaneKillRead cases for 1|0|, 0|0| and 1|-1|.
  • Fixed the 3.4 claim in the test comment, the parsePaneRows() doc and the invariants: the blank pid with a late flag is 3.8, and only the seconds to collect the status were measured on 3.4. I also took the optional respawn-pane point into the kill comment. The CLAUDE.md line and the invariants say that a pid below 2 is no pid.
  • No parsePaneRows() guard, as you withdrew it.

🤖 Generated with Claude Code

@Ark0N

Ark0N commented Nov 26, 2026

Copy link
Copy Markdown
Owner

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. pane.pid || session.pid is back, the test/kill-pid-guard.test.ts mock answers the three-field kill read with cases for 1|0|, 0|0| and 0||, the kill read format and the reconcile rule are pinned, and the tmux 3.4 test comment is corrected.

I also tried nine one-line mutations of the new rules, and each one now fails a test: ?? or pane.pid alone in the close, #{pane_dead_time} dropped from the kill read, a plain active.set(...), master's row skip in parsePaneRows(), sameExit without the exit time, the dead flag trusted alone, a pid-less session rediscovered, and the tracked check done by pid instead of has(). Typecheck, lint, format, the frontend checks and CI are green.

One small fix is left for merge time, and you don't need to change anything for it:

  • test/tmux-manager.test.ts:1412: the live-pane close test drives the real killSession(), and this file does not mock execFile, so the tree walk runs the real ps -eo pid=,ppid= and walks the machine's process table from pid 4343. process.kill is stubbed, so nothing gets signalled. But on a host where 4343 is a real process with children, the test waits out the kill timeouts, and its check that 4242 is never signalled depends on that host's process tree. The fix is to move the case into test/kill-pid-guard.test.ts, which already mocks ps with a fixed table: add pane 4343 with a child 4344, answer the kill read with 0|4343| and recorded pid 4242, and check that only 4343 and 4344 are signalled.

The next step is to merge with that applied. Thank you for staying with this, and for the careful tmux 3.8 measurements.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants