fix(tmux): never signal the recorded pid of a dead pane on close

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>
This commit is contained in:
Kamil KaliszandClaude Opus 5.5 committed 2026-11-24 13:22:42 +01:00
1 parent bee4948e1a
commit df494b21ce
5 files changed
+135 -70

No files matched your search

+22
View File
@@ -16,6 +16,7 @@ import {
buildRemoteLaunchCommand,
formatPaneSnapshot,
parsePaneRows,
parsePaneKillRead,
derivePaneExits,
hasObservablePaneSession,
endedAdoptedAttaches,
@@ -1481,6 +1482,27 @@ describe('parsePaneRows', () => {
});
});
describe('parsePaneKillRead', () => {
it('reads a live pane as its pid', () => {
expect(parsePaneKillRead('0|4242\n')).toEqual({ dead: false, pid: 4242 });
});
it('reads a dead pane as dead, with the pid tmux 3.8 leaves blank', () => {
// killSession must not walk or signal the recorded pid of an exited program:
// the OS may have reused it for an unrelated process.
expect(parsePaneKillRead('1|\n')).toEqual({ dead: true, pid: null });
});
it('reads a dead pane as dead on a tmux that still prints its pid', () => {
expect(parsePaneKillRead('1|4242')).toEqual({ dead: true, pid: 4242 });
});
it('treats an unreadable answer as not dead, so the recorded pid is still used', () => {
expect(parsePaneKillRead('')).toEqual({ dead: false, pid: null });
expect(parsePaneKillRead('|')).toEqual({ dead: false, pid: null });
});
});
describe('derivePaneExits', () => {
const NOW = 1_700_000_000_000;