fix(tmux): closing a session never signals pid 0 or 1

tmux answers 0 for the pid of a pane without a process (`split-window ''`).
The pane list read at server start recorded that 0 on the session, and the
next close of the tab walked the children of pid 0, which is the whole
machine: every process of the account was signalled, all sessions, tmux
itself and the systemd user manager included.

killSession() now decides once whether there is a process to signal
(isSignalablePid(), an integer above 1) and otherwise leaves the close to
`tmux kill-session`. The descendant walk of the kill path returns nothing
for such a root, and signalProcess(), the only place in tmux-manager.ts
that sends a signal, refuses it for the process group form as well.

proc-walk-bounds used pid 1 as the root of its fixture tree, which the kill
path now refuses on purpose, so the fixture is rooted at a real pid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-11-25 16:03:54 +01:00
1 parent 5548c17c4a
commit babb55e4d9
6 files changed
+212 -17

No files matched your search

+19 -6
View File
@@ -146,11 +146,14 @@ describe('collectDescendants', () => {
* even with both caps bypassed.
*/
describe('TmuxManager uses the bounded walk', () => {
/** Build a tree `width` wide and `depth` deep, rooted at 1. */
/** A pane's pid. Never 0 or 1: the kill path walks nothing for those (kill-pid-guard.test.ts). */
const ROOT = 1000;
/** Build a tree `width` wide and `depth` deep, rooted at ROOT. */
function bigTree(width: number, depth: number): Map<number, number[]> {
const t = new Map<number, number[]>();
let next = 2;
let frontier = [1];
let next = ROOT + 1;
let frontier = [ROOT];
for (let d = 0; d < depth; d += 1) {
const nf: number[] = [];
for (const p of frontier) {
@@ -163,7 +166,7 @@ describe('TmuxManager uses the bounded walk', () => {
return t;
}
async function walkVia(fixture: Map<number, number[]>): Promise<number[]> {
async function walkVia(fixture: Map<number, number[]>, root = ROOT): Promise<number[]> {
const { TmuxManager } = await import('../src/tmux-manager.js');
const Klass = TmuxManager as unknown as {
refreshProcSnapshot(): Promise<Map<number, number[]>>;
@@ -174,7 +177,7 @@ describe('TmuxManager uses the bounded walk', () => {
Klass.procSnapshot = { at: Date.now(), byParent: fixture };
try {
const mgr = new TmuxManager();
return await (mgr as unknown as { getChildPidsFresh(pid: number): Promise<number[]> }).getChildPidsFresh(1);
return await (mgr as unknown as { getChildPidsFresh(pid: number): Promise<number[]> }).getChildPidsFresh(root);
} finally {
Klass.refreshProcSnapshot = original;
Klass.procSnapshot = null;
@@ -190,7 +193,7 @@ describe('TmuxManager uses the bounded walk', () => {
it('honours the depth cap on a deep chain', async () => {
const chainTree = new Map<number, number[]>();
for (let i = 1; i < 40; i += 1) chainTree.set(i, [i + 1]);
for (let i = ROOT; i < ROOT + 39; i += 1) chainTree.set(i, [i + 1]);
const out = await walkVia(chainTree);
@@ -203,6 +206,16 @@ describe('TmuxManager uses the bounded walk', () => {
const out = await walkVia(bigTree(4, 6));
expect(out.length).toBeLessThanOrEqual(PROC_WALK_MAX_NODES);
});
it.each([0, 1])('walks nothing below pid %i, whose children are the whole machine', async (root) => {
const machine = new Map([
[0, [1, 2]],
[1, [900]],
[900, [901]],
]);
expect(await walkVia(machine, root)).toEqual([]);
expect(await walkVia(machine, 900)).toEqual([901]);
});
});
describe('descendantsInPaneGroup (a shared daemon outlives the pane that started it)', () => {