A terminal that has ended is not asked for its children, so a reused pid cannot name a stranger's sessions (martha#216) #218

Manually merged
terra merged 3 commits from pallas/216-reused-terminal-pid into main 2026-11-26 04:55:36 +00:00
Member

Refs #216, #206, #205.

Purpose (defect): the sessions a run ends are read only from a terminal that is still the one the run started, so a reused pid can never put a stranger's processes in the way of the teardown's kills.

The defect

theCommandsSessionsOf watches the terminal's children while it runs, and its returned closure looked once more. That last look can happen after script has exited and been reaped — endTheRunOnAPty calls the closure after awaiting the terminal's end — and terminal.pid is still set, so /proc/<pid>/task/<pid>/children answers for whatever process holds that number now. Every session found that way is added, and then ended: another run's members, or the operator's own work.

The fix

A look is taken only while the terminal is still running: once exitCode or signalCode is set, its pid is not read at all. The command's own session is still collected while script runs — that is the martha#724 path, and its tests stay green. sessionsOfTheChildren is a seam with the real read as its default, so a test never reads a pid it invented from this machine.

Done when

  1. A look only while the terminal is still the one it started. — the ended() guard in look.
  2. A test with an injected finder: an ended terminal's pid is never looked at, while a running terminal's still is, so the guard cannot be satisfied by never looking. — the two cases in a_run_on_a_pty_ends_whole.node-test.ts.
  3. The command's own session is still collected while script runs. — "a stopped run on a pseudo-terminal leaves no process in its command's session, and its directory goes (martha#724)" passes unchanged.
  4. No new check.

Red-first: with the guard taken out (the seam kept, so nothing is read or signalled for real), the ended-terminal case fails; with it back the file is 3/3.

Found by Neptunus in the r=1 review of #206.

Refs #216, #206, #205. Purpose (defect): the sessions a run ends are read only from a terminal that is still the one the run started, so a reused pid can never put a stranger's processes in the way of the teardown's kills. ## The defect `theCommandsSessionsOf` watches the terminal's children while it runs, and its returned closure looked once more. That last look can happen after `script` has exited and been reaped — `endTheRunOnAPty` calls the closure after awaiting the terminal's end — and `terminal.pid` is still set, so `/proc/<pid>/task/<pid>/children` answers for whatever process holds that number now. Every session found that way is added, and then ended: another run's members, or the operator's own work. ## The fix A look is taken only while the terminal is still running: once `exitCode` or `signalCode` is set, its pid is not read at all. The command's own session is still collected while `script` runs — that is the martha#724 path, and its tests stay green. `sessionsOfTheChildren` is a seam with the real read as its default, so a test never reads a pid it invented from this machine. ## Done when 1. A look only while the terminal is still the one it started. — the `ended()` guard in `look`. 2. A test with an injected finder: an ended terminal's pid is never looked at, while a running terminal's still is, so the guard cannot be satisfied by never looking. — the two cases in `a_run_on_a_pty_ends_whole.node-test.ts`. 3. The command's own session is still collected while `script` runs. — "a stopped run on a pseudo-terminal leaves no process in its command's session, and its directory goes (martha#724)" passes unchanged. 4. No new check. Red-first: with the guard taken out (the seam kept, so nothing is read or signalled for real), the ended-terminal case fails; with it back the file is 3/3. Found by Neptunus in the r=1 review of #206.
a terminal that has ended is not asked for its children, so a reused pid cannot name a stranger's sessions (martha#216)
All checks were successful
dependency advisories / node in . (pull_request) Successful in 15s
dependency advisories / node in carry_marthas_own_node/try_a_single_executable (pull_request) Successful in 12s
dependency advisories / node in . (container) (pull_request) Has been skipped
dependency advisories / node in carry_marthas_own_node/try_a_single_executable (container) (pull_request) Has been skipped
dependency advisories / node in installer (container) (pull_request) Has been skipped
dependency advisories / advisories (pull_request) Successful in 0s
c4 model / c4-model-1 (pull_request) Successful in 3s
c4 model / c4-model (pull_request) Successful in 0s
dependency advisories / node in installer (pull_request) Successful in 12s
CI / links resolve (pull_request) Successful in 16s
CI / structural floor (pull_request) Successful in 23s
CI / Martha's names are its own (pull_request) Successful in 26s
CI / no import cycle (pull_request) Successful in 22s
CI / the posted text check bites (pull_request) Successful in 8s
CI / the engine drift check bites (pull_request) Successful in 30s
CI / the ring reaches the owner on the live run's tmux (pull_request) Successful in 15s
CI / workflows are valid (pull_request) Successful in 14s
CI / the host drift check bites (pull_request) Successful in 1m4s
CI / nothing private (pull_request) Has been skipped
CI / no test the base passed goes missing (pull_request) Successful in 32s
CI / the pictures change only with the version (pull_request) Successful in 13s
CI / no literal restates a defined value (pull_request) Successful in 59s
CI / every check runs in a job (pull_request) Successful in 10s
CI / every job has a timeout (pull_request) Successful in 10s
CI / installer (pull_request) Successful in 2m30s
standalone / standalone Martha runs alone (ubuntu-latest) (pull_request) Successful in 27s
standalone / the pinned Node is nodejs.org's (pull_request) Successful in 19s
CI / the relay loads in the recorded host (pull_request) Successful in 15m32s
CI / the clean-install proof removes its container (pull_request) Successful in 20m46s
CI / gate coverage (pull_request) Successful in 18m1s
011eafb12c
The r=1 review found the guard's signalCode half pinned by no test: test 1
ends its terminal with a plain exit, so `|| terminal.signalCode !== null`
could be dropped and stay green. A second terminal, killed by a signal, is
read the same way: not at all. With the half dropped the new case is red;
restored, the file is 4/4.
Merge remote-tracking branch 'origin/main' into pallas/216-reused-terminal-pid
All checks were successful
dependency advisories / node in . (pull_request) Successful in 13s
dependency advisories / node in . (container) (pull_request) Has been skipped
dependency advisories / node in installer (pull_request) Successful in 17s
dependency advisories / node in carry_marthas_own_node/try_a_single_executable (container) (pull_request) Has been skipped
dependency advisories / node in installer (container) (pull_request) Has been skipped
dependency advisories / node in carry_marthas_own_node/try_a_single_executable (pull_request) Successful in 14s
dependency advisories / advisories (pull_request) Successful in 0s
c4 model / c4-model-1 (pull_request) Successful in 3s
c4 model / c4-model (pull_request) Successful in 0s
CI / links resolve (pull_request) Successful in 6s
CI / structural floor (pull_request) Successful in 28s
CI / Martha's names are its own (pull_request) Successful in 1m2s
CI / no import cycle (pull_request) Successful in 1m2s
CI / the engine drift check bites (pull_request) Successful in 55s
CI / the ring reaches the owner on the live run's tmux (pull_request) Successful in 14s
CI / workflows are valid (pull_request) Successful in 12s
CI / the posted text check bites (pull_request) Successful in 16s
CI / the host drift check bites (pull_request) Successful in 1m16s
CI / the pictures change only with the version (pull_request) Successful in 19s
CI / no test the base passed goes missing (pull_request) Successful in 34s
CI / installer (pull_request) Successful in 2m14s
CI / every check runs in a job (pull_request) Successful in 11s
CI / every job has a timeout (pull_request) Successful in 20s
standalone / standalone Martha runs alone (ubuntu-latest) (pull_request) Successful in 31s
standalone / the pinned Node is nodejs.org's (pull_request) Successful in 21s
CI / no literal restates a defined value (pull_request) Successful in 1m18s
CI / the clean-install proof removes its container (pull_request) Successful in 19m29s
CI / the relay loads in the recorded host (pull_request) Successful in 15m38s
CI / gate coverage (pull_request) Successful in 17m9s
CI / nothing private (pull_request) Has been skipped
f41a53d941
terra manually merged commit a10a6e98b4 into main 2026-11-26 04:55:36 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
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!218
No description provided.