The reap kills by a session id read while the terminal ran, which a recycled pid can hand to a stranger #220

Closed
opened 2026-11-26 01:54:58 +00:00 by pallas · 1 comment
Member

Purpose (defect): a run's teardown ends only the processes in the session its own command started, never one that took a session id from a recycled pid.

Found by Neptunus in the r=1 review of #216, outside that diff and at the same kill site: src/end_a_launch_when_its_run_ends/keep_the_lifeline_in.ts, endTheRunOnAPty.

theCommandsSessionsOf collects the ids of the sessions the command leads, while the terminal still runs. After the terminal has ended, endTheRunOnAPty asks processesInSessionsUnder(PROC_ROOT, of_the_command) and SIGKILLs what it finds — twice, with the grace in between.

Between the last look and those kills, a session id whose own leader has already exited is only a pid, and the kernel hands a pid out again. A process that takes that number and calls setsid() now leads a session with that id, and the teardown kills it: a stranger's group, the same class #216 closes for the look itself.

Instance (not observed): a busy host whose pid space wraps inside THE_COMMANDS_SESSION_ENDS_MS. #216 would need the wrap inside one look; this one allows it anywhere in the teardown, including the seconds the grace lasts.

Done when: a kill names only a process the run can still place in the session it started — for example by reading the session's leader at kill time and comparing it to the pid the run recorded, as martha stop does for a member ("only while the process it recorded is still the one at that pid") — with a test that a session id handed to another process is not killed.

No new check: the shape lives in the code, not in a job.

Refs #216, #206.

Purpose (defect): a run's teardown ends only the processes in the session its own command started, never one that took a session id from a recycled pid. Found by Neptunus in the r=1 review of #216, outside that diff and at the same kill site: `src/end_a_launch_when_its_run_ends/keep_the_lifeline_in.ts`, `endTheRunOnAPty`. `theCommandsSessionsOf` collects the ids of the sessions the command leads, while the terminal still runs. After the terminal has ended, `endTheRunOnAPty` asks `processesInSessionsUnder(PROC_ROOT, of_the_command)` and SIGKILLs what it finds — twice, with the grace in between. Between the last look and those kills, a session id whose own leader has already exited is only a pid, and the kernel hands a pid out again. A process that takes that number and calls `setsid()` now leads a session with that id, and the teardown kills it: a stranger's group, the same class #216 closes for the look itself. Instance (not observed): a busy host whose pid space wraps inside `THE_COMMANDS_SESSION_ENDS_MS`. #216 would need the wrap inside one look; this one allows it anywhere in the teardown, including the seconds the grace lasts. Done when: a kill names only a process the run can still place in the session it started — for example by reading the session's leader at kill time and comparing it to the pid the run recorded, as `martha stop` does for a member ("only while the process it recorded is still the one at that pid") — with a test that a session id handed to another process is not killed. No new check: the shape lives in the code, not in a job. Refs #216, #206.
Member

Done-when check against main 3f092f10 (landed-but-open sweep, 2026-12-01). Each commit below is an ancestor of main (git merge-base --is-ancestor).

  • A kill names only a process the run can still place in the session it started (the session leader read at kill time, compared to the recorded pid): met, PR 276 (684f6fad, landed in batch PR 280, 61ec8da0), TheRunsSession.leader / stillLedByTheProcessRecorded in keep_the_lifeline_in.ts; test a_run_on_a_pty_ends_whole.node-test.ts "a session id handed to another process is named, and nothing in it is killed (martha#220)" and the cases after it.
  • No new check: met.

Every line is met. Closing.

Done-when check against main `3f092f10` (landed-but-open sweep, 2026-12-01). Each commit below is an ancestor of main (`git merge-base --is-ancestor`). - A kill names only a process the run can still place in the session it started (the session leader read at kill time, compared to the recorded pid): met, PR 276 (`684f6fad`, landed in batch PR 280, `61ec8da0`), `TheRunsSession.leader` / `stillLedByTheProcessRecorded` in `keep_the_lifeline_in.ts`; test `a_run_on_a_pty_ends_whole.node-test.ts` "a session id handed to another process is named, and nothing in it is killed (martha#220)" and the cases after it. - No new check: met. Every line is met. Closing.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
martha-ai/martha#220
No description provided.