A session id collected while the terminal ran is not acted on after its leader is gone (martha#220) #276

Manually merged
terra merged 0 commits from vesta/220-reap-session-id into main 2026-11-27 01:15:06 +00:00
Member

Purpose (real harm): a session id collected while the terminal ran can name a different process group by the time it is acted on.

theCommandsSessionsOf collected session ids while the terminal ran. The ids are numbers. endTheRunOnAPty then acts on whatever processesInSessionsUnder lists for them, twice with a 10 s grace between. If the session's leader exits and is reaped in that window, the kernel can hand its pid out again, and a process that takes it and calls setsid() leads a new session with the same number. The teardown would then act on a group that never belonged to the run.

What changed. theCommandsSessionsOf now collects { session, leader } (TheRunsSession), with the leader's identity read in the same look while the terminal still runs (identityOf = boot + start ticks), behind a new seam identityOfTheProcess. endTheRunOnAPty filters every look through stillLedByTheProcessRecorded: a session is the run's while its leader (/proc/<session>, read at teardown time through the new theLeaderNow seam) is gone, or is held with the recorded identity. Held with another identity, unknown, or never recorded: the session is left alone and not called left. A teardown that finds a recorded session it can no longer place refuses by name ("was taken by another process, so nothing in it was killed:

is left for it") and keeps the directory.

Proof. Both files that import the changed source, through the namespace wrapper on the tip: 20/20 pass. The mutation runs each red by name; npm run verify passes. .github/workflows is 0 bytes against the post-268 main, and the private check is clean on both ranges.

Refs #220

Purpose (real harm): a session id collected while the terminal ran can name a different process group by the time it is acted on. `theCommandsSessionsOf` collected session ids while the terminal ran. The ids are numbers. `endTheRunOnAPty` then acts on whatever `processesInSessionsUnder` lists for them, twice with a 10 s grace between. If the session's leader exits and is reaped in that window, the kernel can hand its pid out again, and a process that takes it and calls `setsid()` leads a new session with the same number. The teardown would then act on a group that never belonged to the run. **What changed.** `theCommandsSessionsOf` now collects `{ session, leader }` (`TheRunsSession`), with the leader's identity read in the same look while the terminal still runs (`identityOf` = boot + start ticks), behind a new seam `identityOfTheProcess`. `endTheRunOnAPty` filters every look through `stillLedByTheProcessRecorded`: a session is the run's while its leader (`/proc/<session>`, read at teardown time through the new `theLeaderNow` seam) is `gone`, or is held with the recorded identity. Held with another identity, `unknown`, or never recorded: the session is left alone and not called left. A teardown that finds a recorded session it can no longer place refuses by name ("was taken by another process, so nothing in it was killed: <dir> is left for it") and keeps the directory. **Proof.** Both files that import the changed source, through the namespace wrapper on the tip: 20/20 pass. The mutation runs each red by name; `npm run verify` passes. `.github/workflows` is 0 bytes against the post-268 main, and the private check is clean on both ranges. Refs #220
theCommandsSessionsOf collects each session with its leader's identity, read while the terminal still ran. The
teardown re-reads /proc/<session> at every look and ends only a session it can still place there: a leader the kernel
no longer holds (the run's own, ended), or one held with the identity the run recorded. A leader that answers with
another identity, one the kernel will not answer for, and one that was never read are all unplaceable: nothing in that
session is killed, nothing in it is called left, and the teardown names it and leaves the directory.

Four cases pin it, each given the finder, the signaller and the leader seam before anything could signal, so no case
hands a real pid to a killer. Four mutants of the guard are each killed by name, the end-to-end pty case among them.
terra manually merged commit 61ec8da029 into main 2026-11-27 01:15:06 +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!276
No description provided.