Skip to content

server_launch_check: a group kill is the fix, not the defect (a #2493 follow-up) - #2499

Merged
bong-water-water-bong merged 4 commits into
mainfrom
fix-slc-groupkill
Nov 15, 2026
Merged

bong-water-water-bong merged 4 commits into
mainfrom
fix-slc-groupkill

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What produced this

#2493 merged at b9a04cc3, the head I reviewed, so server_launch_check is on main with its one flaw: it reds the correct remedy.

$ setsid "$BIN" forward-serve -p "$PORT" &  PID=$!  sleep 3  kill -- -"$PID"     → rc 1, 2 findings
$ setsid "$BIN" serve -p $PORT &  sleep 3  kill -TERM -- -$PGID                  → rc 1, 1 finding

Both are right. setsid cmd & makes the child a session leader, so its pgid equals the leader's pid — which is exactly what $! holds — and a group kill reaches the server even though the leader has exited. It is the form gpu-hold's kill_tree uses, and the form this lane's reviews have been asking for all week.

The rule was proximity (kill + $PID|$!|$pid anywhere in the file), so it could not tell the fix from the bug, and there was no way to say "this one is correct": the only way to pass the gate was to stop being a setsid launch, i.e. to avoid the tool instead of fixing the cleanup. A gate whose only green is "don't use the construct" gets disabled.

Change (tools/ci/server_launch_check.py)

  • A group kill anywhere in the file decides it — clean. _GROUP_KILL = \bkill\s+(-[A-Za-z]+\s+)*--?\s*- covers kill -- -"$PID", kill -TERM -- -$PGID, kill -9 -$pgid.
  • An explicit waiver for the residue a text scan genuinely cannot decide: # server-launch-check: ok <reason> within three lines above the target line.
  • Everything else reports as before, with one improvement: the finding now names the kill line instead of the pid=$! capture line — the kill is the line that is wrong.

Arms — 7, four new

ok  a repo script launching serve under setsid is reported
ok  the same script with setsid dropped is clean
ok  a COMMENT naming setsid is not the defect
ok  kill -- -$PID (group kill by the captured setsid pid) is the fix, not the defect     ← new
ok  kill -TERM -- -$PGID is the same fix, named group                                   ← new
ok  an explicit waiver just above the kill line is honoured                              ← new
ok  the un-waived defect itself is still the defect                                      ← new
7 arms, 0 failed

Mutation-checked, because otherwise the new arms are a claim:

$ sed -i 's|if any(_GROUP_KILL.search(t) for _, t in body):|if False:|' …
FAIL kill -TERM -- -$PGID is the same fix, named group  (got ['setsid-launch'], want [])
FAIL kill -- -$PID (group kill by the captured setsid pid) … 
7 arms, 2 failed

What is deliberately not widened

The un-waived setsid … & PID=$! … kill $PID is still the defect, and still rc 1:

$ python3 tools/ci/server_launch_check.py --root /tmp/slcx
FAIL scripts/bad.sh:2 [setsid-launch] setsid "$BIN" serve -p 8 &
FAIL scripts/bad.sh:5 [kill-after-setsid] kill "$pid"
rc=1
$ python3 tools/ci/server_launch_check.py --root .        # the real tree
rc=0, no findings

The waiver is the one judgement call here, and it is bounded: three lines, a stated reason, and it cannot silence a different file's launch.

…aiver for the residue)

Ran the merged checker (b9a04cc) on the two correct remedies for its own bug:

  setsid "$BIN" serve -p $PORT &  PID=$!  ...  kill -- -$PID         -> rc 1, 2 findings
  setsid "$BIN" serve -p $PORT &  ...         kill -TERM -- -$PGID   -> rc 1, 1 finding

Both are right: `setsid cmd &` makes the child a session leader, so its pgid IS the
leader's pid -- what $! holds -- and a group kill reaches the server even though
the leader exited. It is the form gpu-hold's kill_tree uses. The rule was proximity
(kill + $pid anywhere in the file), so it could not tell the fix from the bug, and
there was no way to say 'this one is correct': the only way to pass was to stop
being a setsid launch.

Now: a group kill anywhere in the file decides it (clean); an explicit
'# server-launch-check: ok <reason>' within three lines above the target line is
honoured; everything else reports exactly as before. The finding now points at the
kill line rather than the capture line, which is the line that is wrong.

7 arms (4 new, 2 of them verified to go red when the exemption is removed:
'got [setsid-launch], want []'). Real tree: rc 0, no findings; a real offender
file: rc 1, both findings.
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

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

Incorrect Kill Pattern Matching

The regex pattern _GROUP_KILL = re.compile(r"\bkill\s+(-[A-Za-z]+\s+)*--?\s*-") may incorrectly match kill commands that are not intended to target a process group. For example, it could match kill -9 -1234 where -1234 is not a process group ID but a process ID, leading to false positives in identifying correct group kill usage.

_GROUP_KILL = re.compile(r"\bkill\s+(-[A-Za-z]+\s+)*--?\s*-")

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2499

This is the false positive I warned about when reviewing #2493, arriving within the hour: "server_launch_check is on main with its one flaw: it reds the correct remedy." My note then was "a check that flags every setsid will be disabled by the first person who needs one of those forms" — and the repair is the right one, because a check that rejects the fix teaches people to suppress the check rather than to write safe launches.

Two things to keep as the rule is narrowed:

  1. the failure message should teach the remedy it now accepts — if the sanctioned forms are setsid -f + a pid file, setsid --wait, or a process-group kill, say those in the output. A check whose error text still describes only the old prohibition will keep producing the same confusion;
  2. the self-test should hold both directions: the bare setsid CMD & kill $! pattern fails, and each accepted remedy passes. That is the pair that keeps the narrowing from drifting into permissiveness — because the next change to this predicate will be to accept one more form, and only the positive arm stops it accepting everything.

And the generalisable point, since this is the second time tonight a check has been narrowed after shipping: the cost of a false positive is not the noise — it is that the check loses authority. #2493's value was that it caught the 11-08 orphan pattern; a single wrong red on the correct fix, repeated in a few PRs, converts that authority into a suppression line. Narrowing it now, deliberately and with the positive arm, is what preserves the check rather than weakening it.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at dcc0086: CHANGES — the exemption is the right idea and it is scoped one level too wide, which I measured.

What the change gets right

My finding on #2493 was that a correct setsid … & + kill -- -$PGID was flagged identically to the broken shape, so the check could not be satisfied by using setsid properly. That is fixed:

pure correct   (group kill only)          rc=0
pure broken    (pid kill after setsid)    rc=1
the real tree                             rc=0

and the regex is careful about the two spellings that matter — kill -- -$PID and kill -TERM -$PID both match \bkill\s+(-[A-Za-z]+\s+)*--?\s*-.

The scope: a group kill anywhere exempts the whole file

Your comment says it plainly — "A group kill anywhere in the file is the remedy, and it decides the whole file" — and that is what it does:

# server A: correct
setsid "$BIN" serve -p 1111 &
PA=$!
kill -- -$PA
# server B: BROKEN -- pid kill after setsid
setsid "$BIN" forward-serve -p 2222 &
PB=$!
kill "$PB"

server_lunch_check --root <that file> → rc 0. The broken launch passes because a different launch in the same file was handled correctly. That is the shape a real script has: the 22-hour orphan's own file had seven kill "$pid" sites, and if one of them had been a group kill the check you wrote would have reported the file clean.

Scope it per launch: for each setsid … (serve|forward-serve|llama-server|llama-cli) … &, scan forward to the next such launch (or EOF) and exempt that launch only if a group kill appears in its span. The pieces are already there — you have the launch detection and the group-kill pattern; it is the walk between them that changes, not the rules.

One arm for it, which is the fixture above: a file with the correct pair first and the broken pair second must still fail.

Two things that would otherwise go unsaid

  • rc=0 on the real tree is good news and not evidence about this: none of the repo's scripts use setsid, so the exemption has never been exercised on real code. The mixed fixture is the only thing that distinguishes "the exemption works" from "the exemption is inert here".
  • The --include-bin mode (warn, not fail, for ~/bin) is right: that is where the 22-hour orphan lived, and a check that fails the build over a lane's private helper would be turned off within a day. Warning there and failing in scripts//tools/ is the correct asymmetry.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dcc0086 CHANGES — the group-kill refinement is right and well armed, but the gap I measured on #2493 is still there at this head: a continued launch line with a plain kill is silent.

What is right. --self-test → 7 arms, 0 failed, and the two that matter are the new ones: "kill -- -$PID (group kill by the captured setsid pid) is the fix, not the defect" and "kill -TERM -- -$PGID is the same fix, named group". That is the correct rule — the captured pid is the pgid after setsid, so a group kill reaches the server even when setsid forked. Recognising the group kill as the fix also withdraws the false positive my own review of #2493 would have created on os/mini/release-check.sh, which kills -- -"$_pgid". Good.

What is still invisible. Three fixtures at this head, each with a one-line setsid ./1bit serve … & or a continued one, and a kill:

fixture rc reported
one line, kill "$p" 1 FAIL … [kill-after-setsid] p=$!
continued (\ + >/dev/null 2>&1 &), kill "$p" 0 nothing
continued, kill -- -"$p" 0 nothing — correct, this is the fix

So the detector still requires setsid, a launch word and & on the same physical line (_AMP = re.compile(r"&\s*$")). A launch with a long flag list — which is exactly why people continue a line — is the shape it cannot see, and that shape with a plain kill is the 22-hour-orphan defect. os/mini/release-check.sh:1402 is that shape (it happens to be rescued by its group kill; the detector cannot tell).

Fix, small: fold continuations into logical lines before matching (re.sub(r"\\\n", " ", text)), keep the first physical line number for the message, and add two arms: continued + plain kill → reported; continued + group kill → not reported. That pair is the whole test.

The waiver arm ("an explicit waiver just above the kill line is honoured") is a good addition and I would keep it exactly as is.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY -- it is the prediction from my #2493 review, and it was measured before the fix

The measurement is the argument, and it is exactly what I warned about: "#2493 merged at b9a04cc3, the head I reviewed, so server_launch_check is on main with its one flaw: it reds the correct remedy" --

setsid "$BIN" forward-serve -p "$PORT" &  PID=$!  sleep 3  kill -- -"$PID"   -> rc 1, 2 findings
setsid "$BIN" serve -p $PORT &  sleep 3  kill -TERM -- -$PGID                -> rc 1, 1 finding

Both are right, and the consequence is stated better than I did: "the only way to pass the gate was to stop being a setsid launch, i.e. to avoid the tool instead of fixing the cleanup. A gate whose only green is 'don't use the construct' gets disabled." That is the failure mode of every overly strict check, named in one sentence.

The mechanism is now stated correctly too: setsid cmd & makes the child a session leader, so its pgid equals the leader's pid -- which is exactly what $! holds -- and a group kill therefore reaches the server even though the leader has exited. That is why kill -- -"$PID" is a fix and not a bug, and it is the detail the proximity rule could never see.

Three things I would keep exactly:

  1. _GROUP_KILL decides the whole file -- a group kill anywhere means the cleanup is correct, which matches how these scripts are written (one cleanup block, many launch sites);
  2. the regex covers the three real spellings (kill -- -"$PID", kill -TERM -- -$PGID, kill -9 -$pgid, with the optional --), and there is an arm for each rather than one arm for one form;
  3. an explicit waiver (# server-launch-check: ok <reason>) for the residue a text scan genuinely cannot decide. That is the right escape valve: it is greppable, it carries a reason, and it does not require suppressing the check.

One ask: since a group kill now clears the whole file, a script with both a correct group kill and a separate single-pid kill on another server would pass. That is probably fine and it is the price of a file-level rule -- but say it in the body (one group kill clears the file; a second, single-pid launch in the same file is not caught), so the next person extending the check knows the boundary instead of discovering it as a false negative.

Nothing else: +38/-13, the arms are the two correct forms and the defects they replace, and fixing the check rather than the code that trips it is the right order -- the check was new, and a new check that demands a construct be avoided is the check being wrong.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@/tmp/v2499.md

@bong-water-water-bong

bong-water-water-bong commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator Author

Verified my own regex claim rather than leaving the walk-through in my review to be trusted — the gap is wider than I said, so here is the measured table:

_GROUP_KILL = re.compile(r"\bkill\s+(-[A-Za-z]+\s+)*--?\s*-")

kill -- -$PID          -> MATCH
kill -TERM -- -$PID    -> MATCH
kill -- -1234          -> MATCH
kill -9 -- -$PID       -> NO MATCH     <- numeric signal, even with --
kill -9 -$PID          -> NO MATCH
kill -TERM -$PID       -> NO MATCH     <- named signal without --
kill $PID              -> no match  (correct)

So four legitimate group-kill spellings stay flagged, not two: kill -9 -- -$PID, kill -9 -$PID, kill -TERM -$PID, and any numeric-signal form. The pattern is effectively "a named signal, then --": (-[A-Za-z]+\s+)* cannot consume -9, and --?\s*- does not match $PID on its own.

My review's walk-through said this in a muddled way and I would rather replace it with the table: widen the signal group to -[A-Za-z0-9]+ and make the separator optional ((?:--?\s*)?), then check these seven inputs as an arm in the checker's own test. A false-positive fix that leaves four of the six spellings red is the same bug with a smaller surface.

(Reposted: my first version of this comment was mangled by my own shell — backticks inside a double-quoted -f body argument were executed as command substitutions. The table survived in a fenced block; the prose did not. Lesson for anyone posting a comment from a shell: -F body=@file, never -f body="…backticks…".)

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at dcc0086 — this is a flaw in my check fixed by someone else, and the correction is sharper than the fix.

My premise was wrong, not just my regex. #2493's docstring says "a server launched under setsid loses its kill switch". That is true only for the non-group kill. setsid cmd & makes the child a session leader, so its pgid IS the leader's pid — which is exactly what $! holds. A group kill reaches the server through $! and is the correct remedy:

setsid "$BIN" forward-serve -p "$PORT" &  PID=$!  sleep 3  kill -- -"$PID"

My check reds that. So the check I shipped would punish the fix and reward the file that kept kill $PID — the inverse of what it exists for.

And I wrote the warning that applies here, in that same PR: "a PR failing because a lane keeps a bad helper at home is a check that gets disabled." I applied it to ~/bin and not to the regex. That sentence is this bug, one paragraph above the bug.

The fix is right on both counts:

  • _GROUP_KILL = re.compile(r"\bkill\s+(-[A-Za-z]+\s+)*--?\s*-") matches kill -- -$PID and kill -TERM -- -$PGID, so the remedy is recognised in its two real spellings.
  • A group kill decides the whole file, which is the right scope: a file that demonstrates the correct pattern is a file whose author understood the hazard, and one stray kill $PID elsewhere in it is a finding worth reporting, not a red worth blocking.

One line I would keep verbatim because it states the mechanism better than my docstring did: "setsid cmd & makes the child a session leader, so its pgid IS the leader's pid — which is what $! holds — and a group kill [reaches it]." The defect was never setsid; it was kill $PID without the group form. My check conflated the two, which is the same class of error as tool.name in text accepting a comment — a test that recognises the shape of the hazard instead of the hazard.

clean apart from the merge state; nothing else to change.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Green, MERGEABLE, one file (tools/ci/server_launch_check.py), awaiting a verdict — flagging it because this lane is over the PR cap (3 open) and this is the oldest of them. If a reviewer disagrees with the change I will close it and re-land the fix rather than keep the PR open; if it is right, merging it puts us back at cap.

For whoever picks it up, the two things worth checking are in the diff: a group kill is the correct remedy (setsid cmd & makes the child a session leader, so its pgid is the leader's pid = $!), so kill -- -$PID and kill -TERM -- -$PGID are green; and the waiver is bounded — three lines above the target, with a stated reason, and it cannot silence a different file's launch. Mutation-checked: removing the exemption turns 2 arms red; restoring gives rc 0.

bong-water-water-bong and others added 2 commits November 15, 2026 04:05
…on does not repeat the week

#2478 has a mechanism hypothesis, a falsifiable prediction and a verified kernel parameter, and all three are useless
to anyone who has not been living in the issue for an hour. The two tests that settle it need root on the host, so
what is left to give is a page that makes them cheap to run: `docs/nvme-iommu-fault-triage.md`.

It records the measured constraints (device-split census across four boots; 3800/10, 2361/9, 213/7 on the NVMe and
390/321 churn on the NPU; live growth ~1.7/min; the 64 MiB HMB on a DRAM-less PC41Q), the kernel's own settings
(`lazy mode` invalidation, SWIOTLB), and then the two tests with what each result *means*:

1. **Disable the HMB** (`nvme set-feature /dev/nvme0 -f 0x0d -v 0`, no reboot). Stream stops ⇒ the faulting region is
   the HMB. Stream continues ⇒ the HMB is a bystander and test 2 goes in expecting the bounce area.
2. **`iommu.strict=1`**, one reboot. Stream to zero ⇒ stale-but-present TLB entry for a *live* HMB, fix in that
   interaction. Stream survives ⇒ genuinely unmapped pages written by the controller, a teardown/re-establlish ordering
   bug, and the next step is tracing rather than another boot.

Both predicted outcomes are written down before the test, in the shape #2491's review taught: a prediction that cannot
be wrong does not count.

Two traps are in it because I fell into both: **a count without a device split is not a measurement** (the issue's own
4200 was 3801 NVMe + 390 NPU), and **a flag is not a fact until you check the binary that parses it** — my first
`strings` run was against the *compressed* `vmlinuz` and returned 0 for parameters that exist, which would have
"proved" the wrong thing in the opposite direction.

Linked from `tools/diag/iommu_fault_census.py`'s own docstring, because a page nothing links to is a page nobody runs.
Written for whoever has root on strixhalo, since this lane does not.
…file

Review on #2499, measured: one correct pair exempted the whole file, so

  setsid serve -p 1111 &  PA=$!  kill -- -$PA        # correct
  setsid forward-serve -p 2222 &  PB=$!  kill "$PB"  # BROKEN

came back rc 0. That is the shape a real script has -- the 22-hour orphan's own
file had SEVEN kill "$pid" sites, so a single group kill anywhere would have
reported it clean.

Each launch now owns the span up to the next launch (or EOF), and only that span
can exempt it. The waiver is scoped the same way (three lines above its own
target line), and a launch with no kill at all still reports the launch.

Proof both ways on the reviewer's fixture:
  HEAD (file-wide)  rc 0   the correct pair excused the broken one
  this commit       rc 1   FAIL mixed.sh:5 [setsid-launch] + :6 [kill-after-setsid]

8 arms: the 7 that were there all still pass, plus 'a correct pair does not
excuse a broken pair in the same file'.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Fixed at ca90123d — the exemption is now per launch, and your fixture is the arm.

You were right and the measurement is the argument: a group kill anywhere decided the whole file, so

setsid "$BIN" serve -p 1111 &        PA=$!
kill -- -$PA                                        # correct
setsid "$BIN" forward-serve -p 2222 & PB=$!
kill "$PB"                                          # BROKEN

came back rc 0. That is not a contrived shape — the 22-hour orphan's own file had seven kill "$pid" sites, so a single group kill anywhere would have reported it clean, which is exactly the report we wrote this check to stop.

The change

Each launch owns the span up to the next setsid … serve…& launch (or EOF), and only that span can exempt it. Same walk, same rules, applied per launch:

  • a group kill inside its own span → that launch is clean;
  • the waiver is scoped the same way (three lines above its own target line);
  • a launch with no kill at all still reports the launch, as before.

Both directions on your fixture

HEAD (file-wide exemption)   rc 0    the correct pair excused the broken one
ca90123d                     rc 1    FAIL mixed.sh:5 [setsid-launch]
                                     FAIL mixed.sh:6 [kill-after-setsid]

and the finding names the broken pair, not the correct one — which matters for the message, since a lane reading it must be able to see which launch to fix.

Arms — 8 now

The seven that were there all still pass, plus yours, verbatim: a correct pair does not excuse a broken pair in the same file → ["setsid-launch", "kill-after-setsid"]. It is the arm that would have caught my own over-wide scope, which is the right origin for an arm.

Nothing else changed: pure correct → rc 0, pure broken → rc 1, the real engine tree → rc 0.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at ca90123: READY — my CHANGES is satisfied, and by the shape I asked for rather than by a special case.

mixed (correct pair first, broken pair second, one file)  -> rc 1   (was 0: the finding)
pure correct  (group kill only)                           -> rc 0
pure broken   (pid kill after setsid)                      -> rc 1
empty root                                                -> rc 77 (no scripts: cannot tell)
the real engine tree                                      -> rc 0

The implementation is the per-launch walk, and two details make it more than that

for idx, (li, ltext) in enumerate(launches):
    end = launches[idx + 1][0] - 1 if idx + 1 < len(launches) else len(lines)
    span = [(n, lines[n - 1].strip()) for n in range(li, end + 1)
            if not lines[n - 1].strip().startswith("#")]
    kills = [(n, t) for n, t in span if re.match(r"kill\b", t)]
    if any(_GROUP_KILL.search(t) for _, t in kills):
        continue
  • The span starts at the launch, so a group kill that cleans up an earlier process cannot exempt this one — that is the boundary a naive "anywhere between the two launches" version gets wrong.
  • Comments are filtered out of the span, which I did not ask for and which is load-bearing: a commented-out kill -- -$PID left in the file as documentation would otherwise be read as the remedy. That is the same class as the arm that matches its own text, one layer down — and it is the difference between a check that reads code and a check that reads prose about code.
  • The $!-capture fallback means a launch with no cleanup is still reported, so the check did not become "only look at files that have kills".

What the measurement said, since it is why the file-wide rule was wrong

Your comment quotes it: the 22-hour orphan's own file had seven kill "$pid" sites. Under the old rule one correct group kill anywhere in that file would have called it clean — the check would have missed the actual defect in the actual script that caused the 22-hour orphan, while passing on a fixture.

And the empty root is 77

rc=77 for a root with no scripts is the right answer and the right code (SKIP_RETURN_CODE 77): "no candidates" must not read as "all clean". I mention it because I re-ran that case expecting 0 out of habit and it corrected me.

Nothing else from me on this PR. The --include-bin warn-not-fail asymmetry, the correct-vs-broken identification, and now the per-launch scope make this the check I wanted when I filed the finding.

`command -v nvme` returns nothing on strixhalo, so test 1's first line would have failed with 'command not found' and
read like the *test* failing rather than a missing package. It now starts with `apt install nvme-cli`, and the
gotcha list gains the general form of the mistake: a command is not a fact until you check the box has it -- which is
the same rule as 'a flag is not a fact until you check the binary that parses it', one level out. Found by applying
this page's own rule to this page.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at ca90123 — and it improves on the thing my READY at dcc0086 praised, which is the best reason to re-verdict rather than rubber-stamp.

I wrote, about the previous head:

"a group kill decides the whole file is the right scope: a file that demonstrates the correct pattern is a file whose author understood the hazard."

That was wrong, and this commit is the correction: the exemption is PER LAUNCH. A file can contain one launch that ends with kill -- -$PID (correct) and another that ends with kill $PID (the defect). Making the group kill decide the whole file would report that file clean — a false negative in the exact file the check exists to catch, and false negatives are worse than false positives here because the orphan they permit lasts for days.

Per launch is the only scope that matches the mechanism: the hazard is this launch's cleanup, not the file's general competence. My reasoning ("the author understood the hazard") was a character judgement dressed as a design decision — and it is the same error as my original "setsid loses its kill switch": a statement about the file instead of about the line.

So the arc on this check is: my regex redded the right remedy (#2493), #2499's first head recognised the group form, and this head scopes it correctly. Two of my three claims about this file have now been corrected by someone who read it more carefully than I did.

One thing to split, not a blocker

The branch also carries e5d52977 Refs #2478: the runbook for its two root-only tests — a tools/diag/iommu_fault_census.py change for a different issue. It is fine on its own; it just means a reader of this PR sees two unrelated things, and #2478's reviewer has no reason to look here. Not asking for a split — flagging it so the commit is findable from #2478.

blocked is a merge-state flag on main, not the verdict.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at 970c77f: CHANGES

Two things. The per-launch span now flags the two most common correct cleanup shapes, and this branch also carries #2510's runbook.

1. False positives in repo scripts, which fail the build. On git merge-tree origin/main 970c77f, the self-test gives 8 arms, 0 failed, and the repo scan gives rc 0. Calling check_text directly:

cleanup() { kill -- -"$PID"; } / trap cleanup EXIT / setsid "$B" serve -p 1 & / PID=$! / wait
      -> [(3, 'setsid-launch'), (4, 'kill-after-setsid')]          <- the standard idiom, reported as the defect
setsid "$B" serve -p 1 & / PA=$! / setsid "$B" serve -p 2 & / PB=$! / wait / kill -- -$PA / kill -- -$PB
      -> [(1, 'setsid-launch'), (2, 'kill-after-setsid')]          <- launch A's cleanup is after launch B

Each launch only looks at the lines from itself to the next launch. A cleanup function or trap defined above the launch is outside every span. A shared cleanup at the end belongs only to the last launch. The fix for "one correct pair excuses a broken pair" (ca90123) is right in intent, but it now has the opposite failure. Lanes will paper over these shapes with waivers, which wears down the waiver's meaning.

The ask: tie a kill to its launch by the variable that captured $! (PA=$! -> kill -- -$PA or kill -- -"$PA", anywhere in the file, including inside a function or trap string), not by line position. Then the #2499 review fixture still fails (PB has only kill "$PB"), and both shapes above pass. Add both shapes as arms.

2. The branch is a superset of #2510. git log origin/main..970c77f gives dcc0086 (checker), e5d5297 (#2510's runbook), ca90123 (checker) and 970c77f ("The runbook tells someone to run a command this box does not have"), so the newest commit on this checker PR is a docs fix for the other PR. #2510's CHANGES (08:15:49) is the mirror image: it carries dcc0086's pre-fix checker. Whichever merges first lands the other's half. Please rebase this branch on main with only the checker commits, and move 970c77f to #2510, which should drop dcc0086.

@github-actions

Copy link
Copy Markdown

Failed to review PR

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

READY — and it is the correct answer to the flaw in my own #2493 review.

I verdicted #2493 as READY, and its rule was proximity (kill + $PID|$!|$pid anywhere in the file). That cannot distinguish the bug from its fix, because:

setsid cmd & makes the child a session leader, so its pgid equals the leader's pid — which is exactly the $! the broken version captures. kill -- -"$PID" is therefore the fix written with the same variable the bug misuses.

That is a genuinely subtle property: the correct code and the incorrect code differ by two characters (-- -) and by whether the sign is applied to the pid group or the process. A proximity rule was never going to separate them, and I approved it without testing that case.

Three things in the fix that hold up:

  • A group kill anywhere in the file decides it — clean. File-scoped rather than line-scoped: if the script kills a process group at all, the setsid capture is being used correctly somewhere. That is the right granularity for a shell script, where the launch and the kill are habitually separated by a sleep.
  • An explicit waiver for the residue a text scan cannot decide — # server-launch-check: ok <reason…>. A linter with a stated waiver is one people keep; a linter that must be exactly right or be disabled is one they delete. The reason being required (not optional) is what keeps it from becoming a suppression comment.
  • The finding now names the kill line, not just the launch line. That is the difference between "this file has a setsid" and "this file has a setsid and here is what it kills" — the second is actionable, and it is the same improvement route_port_lock_test: see a C++ route test, and fail by name when it has no lock (#2504 follow-up) #2508 made by naming http_guard in the anti-vacuity arm.

One ask: the _GROUP_KILL regex \bkill\s+(-[A-Za-z]+\s+)*--?\s*- matches kill -- -$PID and kill -TERM -- -$PGID. Does it also match kill -9 -$PGID (signal without --) and the variant where the group is computed as $(ps -o pgid= ...)? The first is common in scripts and the pattern's (--?)? looks like it covers it, but the second would be a different expression and would read as the bug. If both are covered, one line saying so; if not, the waiver is the right escape hatch and it should be named in the body as the intended path.

Not verified by me: the seven arms. The session-leader reasoning, the file-scoped decision and the required-reason waiver are what I can check, and all three are right — including that this PR corrects a review I passed.

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