Skip to content

repro-hostgemm-lock: the setsid comment names the session, not $! (follow-up to #2472) - #2477

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-review/setsid-comment
Nov 15, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-review/setsid-comment

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Follow-up to #2472, which merged at 03:36:55Z with a comment that gives the wrong mechanism. Comment only; the code is unchanged.

What the comment said, and what happens

The comment says setsid "makes $! the setsid pid, so kill $PID below would miss the server". In this script that is not what happens. util-linux setsid forks only when the caller is a process-group leader. A & job in a non-interactive script (this one has set -u, no set -m) is not one, so setsid execs in place and $! is the server.

Measured with util-linux 2.41.3:

non-interactive script:  setsid sleep 301 &   $! -> comm=sleep          kill $!  -> sleep gone
with set -m:             setsid sleep 302 &   $! -> the forking parent  kill $!  -> sleep survives

Why removing setsid was still right

setsid put the server in its own session. When the script dies without running its EXIT trap (SIGKILL, an orchestrator stop, a closed terminal), a server outside the session gets no SIGHUP and survives with PPID 1. That is the orphan class. Without setsid, the server shares the script's session and goes down with it.

The comment now says that. The risk with the old wording is that a later reader decides the problem was $!, "fixes" the trap, and puts setsid back.

Verified

bash -n tools/repro-hostgemm-lock.sh is clean. The diff is 6 comment lines in one file; no code changed.

🤖 Generated with Claude Code

…llow-up to #2472)

#2472 removed `setsid` and its comment says setsid "makes `$!` the setsid pid".
In this script that is not what happens: util-linux setsid forks only when the
caller is a process-group leader, and a `&` job in a non-interactive script
(no `set -m`) is not one, so setsid execs in place and `$!` IS the server.

    non-interactive: setsid sleep 301 & -> $! comm=sleep, kill $! -> gone
    with set -m:     setsid sleep 302 & -> $! is the forking parent, kill $! -> sleep survives

Removing setsid is still right, for the other reason: it put the server in
its own session, so a script killed without its EXIT trap left the server
with no SIGHUP and PPID 1. The comment now says that, so a later reader does
not "fix" the trap and bring setsid back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Comment Accuracy

The comment previously incorrectly stated that setsid makes $! the setsid pid, which would cause kill $PID to miss the server. This is inaccurate, especially in non-interactive scripts where setsid does not fork, and $! is the server itself. The updated comment correctly explains that setsid places the server in its own session, which can lead to orphaned processes if the script dies without running its EXIT trap, rather than an issue with $! itself.

# NOT `setsid`: it puts the server in its OWN session. When this script dies without running its EXIT trap
# (SIGKILL, an orchestrator stop, a closed terminal), a server outside the session gets no SIGHUP and survives
# with PPID 1, holding the NPU context -- the orphan class that blocked two lanes' hwctx creates on 2026-11-15.
# (It is not about `$!`: in a non-interactive script, without `set -m`, util-linux setsid does not fork, so `$!`
# IS the server; only under job control does `$!` become the forking setsid parent.) The port-scoped pkill in
# the trap is the belt for any path where `$!` is not the server.

@bong-water-water-bong
bong-water-water-bong enabled auto-merge (squash) November 15, 2026 03:40
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2477

Correcting a comment that states the wrong mechanism is worth a PR on its own, and this one is exemplary in what it does not do: "Comment only; the code is unchanged." A wrong mechanism in a comment is worse than no comment — it survives review, gets cited in future discussions, and is believed precisely because someone bothered to write it down.

Two things I would put in the corrected text, since the point of writing it is that the next reader does not repeat the wrong model:

  1. what the evidence was — the original comment claimed a mechanism; the correction should say how it is known the mechanism is different (a measurement, a read of the code path, a test), because "this is wrong, actually it is X" invites the same doubt that produced the original claim;
  2. the symptom it explains — a comment on a repro script is most useful when it says why the lock exists and what happens without it; the mechanism is instrumental to that.

If #2472's own description already carries that reasoning, one pointer is enough.

@bong-water-water-bong
bong-water-water-bong merged commit 4e088f6 into main Nov 15, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-review/setsid-comment branch November 15, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant