mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-30 16:39:33 +01:00
fix(tmux): a pane pid of 0 falls back to the recorded pid on close
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>
This commit is contained in:
1 parent
95918b80b4
commit
9309500d40
5 files changed
+113
-17
No files matched your search
+13
-9
@@ -382,9 +382,10 @@ function paneField(fields: string[], index: number): number | undefined {
|
||||
* - Skips entries with an empty name, and entries where tmux answered neither a
|
||||
* pid nor `#{pane_dead}`, which is a bad read. tmux 3.8 blanks `#{pane_pid}`
|
||||
* as soon as the pane's pty closes, while `#{pane_dead}` turns 1 only once
|
||||
* tmux has collected the exit status (several seconds for some exits,
|
||||
* measured on tmux 3.4). A row with no pid and `pane_dead` 0 is that window,
|
||||
* and dropping it would report a live session as gone.
|
||||
* tmux has collected the exit status. Collecting it took several seconds for
|
||||
* some exits (measured on tmux 3.4, where the pid itself stays). A row with
|
||||
* no pid and `pane_dead` 0 is that window, and dropping it would report a
|
||||
* live session as gone.
|
||||
* - Leaves every field after the pid undefined when it is blank or absent, so a
|
||||
* row from an older tmux still yields its pid.
|
||||
*/
|
||||
@@ -3482,12 +3483,15 @@ export class TmuxManager extends EventEmitter implements TerminalMultiplexer {
|
||||
// check the fallback below would pick that stale pid every time. Only the
|
||||
// kill-session below runs for it. A blank pid with `#{pane_dead}` still 0
|
||||
// (tmux 3.8, pty closed, exit not collected yet) keeps the fallback: tmux
|
||||
// has not reaped that process, so its pid cannot have been reused.
|
||||
// An empty pane has no process either: tmux says 0, and so does the record
|
||||
// once a server start has read it. Nothing is signalled for pid 0 or 1
|
||||
// (isSignalablePid), and only tmux is asked to close the session.
|
||||
// has not reaped the pane's process yet. That holds when the recorded pid is
|
||||
// the one the pane was started with; a hand-run `respawn-pane` breaks it.
|
||||
// A pid of 0 is no pid either: tmux prints it for an empty active pane
|
||||
// (`split-window ''`) before 3.8, beside a session's running agent, so
|
||||
// `||` falls back to the recorded pid as master always did. Nothing is
|
||||
// ever signalled for 0 or 1 (isSignalablePid): then only tmux is asked to
|
||||
// close the session.
|
||||
const pane = await this.readPaneForKill(session.muxName);
|
||||
const candidatePid = pane.dead ? null : (pane.pid ?? session.pid);
|
||||
const candidatePid = pane.dead ? null : pane.pid || session.pid;
|
||||
const currentPid = candidatePid !== null && isSignalablePid(candidatePid) ? candidatePid : null;
|
||||
|
||||
console.log(
|
||||
@@ -3495,7 +3499,7 @@ export class TmuxManager extends EventEmitter implements TerminalMultiplexer {
|
||||
? `[TmuxManager] Killing session ${session.muxName} (PID ${currentPid})`
|
||||
: pane.dead
|
||||
? `[TmuxManager] Killing session ${session.muxName} (pane dead, PID ${session.pid} not signalled)`
|
||||
: `[TmuxManager] Killing session ${session.muxName} (no process, pane pid ${candidatePid})`
|
||||
: `[TmuxManager] Killing session ${session.muxName} (no usable pid, recorded ${session.pid}, nothing signalled)`
|
||||
);
|
||||
|
||||
const allPids: number[] = [];
|
||||
|
||||
Reference in new issue
Block a user