Skip to content

repro-hostgemm-lock: stop orphaning a forward-serve on the NPU (the setsid/$! trap) - #2472

Merged
bong-water-water-bong merged 5 commits into
mainfrom
verify/hostgemm-no-orphan
Nov 15, 2026
Merged

bong-water-water-bong merged 5 commits into
mainfrom
verify/hostgemm-no-orphan

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

My own 22 h orphan, found in a repo script. The line is identical:

NPU_INFER_HOST_GEMM=1 setsid "$BIN" forward-serve ... &
PID=$!
trap 'kill $PID 2>/dev/null; wait $PID 2>/dev/null' EXIT

setsid makes $! the setsid pid, so the trap kills a process that has already exited and never reaches forward-serve. That server then survives with PPID 1, no ticket, holding the NPU hardware context.

Why I know exactly what it does

On 2026-11-15 a flm-real serve lfm3:1.7b -p 8199 left by an npu-model-chart.sh run with this same line held every NPU context for 22 h 44 min. cl-npuperf and cl-flm got -19 on every hwctx create for most of a day. The chart is fixed (setsid removed at 3 launch sites, port-scoped pkill at all 7 kill sites) and this is the same fix in the repo copy.

The change

  • setsid dropped — $! becomes the server, so the existing trap/wait works as written, and kill -0 $PID in the readiness loop now watches the process that matters.
  • Port-scoped pkill -f "forward-serve .* -p $PORT" in the trap — the belt, because cleanup should not depend on $! being the server. That dependency is the whole bug.

bash -n clean, copyright.py --check rc=0.

The gap this exposes, which is bigger than the line

tests/gpu_hold_tree_test.sh already exists and asserts exactly the property that was violated — "0 = the tree died with the ticket, 1 = something survived". It tests gpu-hold's own tree, so it could not see my ~/bin/npu-model-chart.sh, and it cannot see a script like this one either.

Scripts in ~/bin are outside every check this repo runs. That is where the 22 h orphan lived, and it is why the fleet's carefully built tree-death test did not catch it. The durable fix is not more discipline in ~/bin: it is that anything that launches a server belongs in scripts/, where gpu_hold_tree_test.sh and tests_referenced_check can see it. npu-model-chart.sh is a candidate to move; I have not moved it in this PR because it lives outside the tree and the move deserves its own review rather than riding along with a bug fix.

bong-water-water-bong added 5 commits November 14, 2026 09:24
engine#374 is why this exists: model_buffer_from_mmap() retagged a CPU buffer as
mapped_buft while leaving its context a CPU context, and the result was correct output
at 8.4 t/s instead of 31.3 — a 3.7x regression that no correctness test caught, because
every test watching that buffer was watching the assertion it satisfied, not the speed
it satisfied it at. hrx-buffer-test went red much later, on an alignment assert.

A rate floor measures the thing users feel and fails in the direction a correctness
check cannot: a run that is 3x too slow still emits the right tokens. Values named on
failure, SKIP (77) when the log carries no rate at all — a missing rate is not a pass.

Four arms in --self-test, the second being #374's own before/after pair (31.3 passes a
20 floor, 8.4 fails it). Wired as a ctest row so it cannot become a checker with no
caller; the device mode is --log <llama-cli output> --floor N.
…inimum of three runs

Both from the review's asks, both from measurements this box already made:

- JUDGED <subject> before the verdict. A floor is a number tied to a model, quant,
  context and box; without the subject a pasted 'below_floor: 8.4' is a recollection,
  not evidence. Same lesson engine#2426 landed for AUDITED <sha> tonight.
- The usage now says to set the floor below the MINIMUM of >=3 interleaved runs, and
  says why with the number: four identical 128-token decode runs on engine#679 measured
  7.94 / 11.78 / 10.39 / 12.57 t/s -- median 11.09, spread 1.58x. A floor judged on one
  sample flaps for reasons unrelated to a regression, and a flapping row gets ignored.

Judging a range instead (tools/ci/medians.py's disjoint-ranges A/B) is more correct and
more work; not done here, named as the better next step. Fifth arm pins that every
verdict carries its subject.
…ce 15:16Z)

The file carried '# Copyright' and '# SPDX-License-Identifier' but not the licence block, so
copyright.py reported 'missing copyright notice' and the build failed at the configure/check step.

The sequence matters and the first advice on the PR was wrong: --fix on the partial header inserts
14 lines that DUPLICATE those two, producing 'copyright notice duplicated inside the header window'
-- one red row traded for another. Delete the two partial lines first, then --fix inserts the 12-line
block and --check returns rc=0.

Verified locally: copyright.py --check rc=0, --self-test 5 arms 0 failed.
…aying 'not a failure'

Two asks from the review at 1a5785d, both right:

1. --log had no caller. One ctest row ran --self-test; the mode that would have caught engine#374
   was invoked by nothing in the tree -- engine#2418's defect (arms green, never applied) in the tool
   written to catch that class. tools/ci/token_rate_floor_device.sh judges one real 1bit serve rate
   inside a gpu-hold ticket and exits 77, naming the missing prerequisite, when it cannot run.

2. below_floor printed '-- a slowdown, not a failure' while exiting 1: the status said failed and the
   sentence said not. It now prints the multiplier -- 'correct output, 2.4x below the floor' -- which
   is the number that made engine#374 worth measuring.
… NPU

`setsid "$BIN" forward-serve ... &" makes $! the setsid pid, so the trap's `kill $PID` kills a
process that has already exited and never reaches the server: it survives with PPID 1 and holds the
NPU hardware context.

That is not hypothetical — on 2026-11-15 a `flm-real serve` left by an `npu-model-chart.sh` run with
this same line held every NPU context for 22 h 44 min, and cl-npuperf and cl-flm got -19 on every
hwctx create. The chart is fixed (setsid removed, port-scoped pkill at every kill site) and this is
the same fix in the repo copy.

Dropping setsid makes $! the server, so the existing trap works as written; the port-scoped pkill is
the belt for when it does not. `bash -n` clean, 0 setsid left.
@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

Process Cleanup Bug

The change removes setsid from the command that starts forward-serve, which was causing the trap to kill the wrong process. The trap now correctly kills the forward-serve process, and a port-scoped pkill is added as a safety measure to ensure cleanup works even if $! is not the server process. This fixes a bug where forward-serve would orphan and hold the NPU hardware context after the script exits.

NPU_INFER_HOST_GEMM=1 "$BIN" forward-serve -m "$MODEL/model.q4nx" --kernels "$MODEL" -p "$PORT" > "$LOG" 2>&1 &
PID=$!
trap 'kill $PID 2>/dev/null; pkill -f "forward-serve .* -p $PORT" 2>/dev/null; wait $PID 2>/dev/null' EXIT
New Token Rate Tool

A new Python script token_rate_floor.py is added to enforce a minimum token generation rate, which helps catch performance regressions that would otherwise go unnoticed in correctness tests. It parses logs for token rates and compares them against a specified floor, exiting with code 0 if the rate meets or exceeds the floor, 1 if below, and 77 if no rate is found.

#!/usr/bin/env python3
# Copyright 2026 bong-water-water-bong
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""token_rate_floor.py: fail when a model generates slower than a floor, so a silent slowdown is caught.

engine#374 is why this exists. `model_buffer_from_mmap()` retagged a CPU buffer as `mapped_buft` while leaving
its context a CPU context. The result was **correct output at 8.4 t/s instead of 31.3** -- a 3.7x regression that
no test caught, because every test that watched the buffer was watching the *assertion* it satisfied, not the
speed the machine was doing it at. `hrx-buffer-test` went red much later, on an alignment assert, and the rate
had been quietly wrong for as long as the retag had.

A rate floor is the direct measurement of the thing users feel, and it fails in the direction a correctness
check cannot: a run that is 3x too slow still produces the right tokens.

    token_rate_floor.py --log run.log --floor 20            # judge a saved llama-cli / 1bit run
    token_rate_floor.py --log run.log --floor 20 --json      # machine-readable verdict
    token_rate_floor.py --self-test                         # the four arms, no device needed

**Set the floor below the MINIMUM of at least three interleaved runs, not below a median or a single good one.** A single
rate is not a stable subject on this box: four *identical* 128-token decode runs at one config on engine#679 measured
7.94 / 11.78 / 10.39 / 12.57 t/s -- median 11.09, **spread 1.58x**. A floor judged on one sample flaps for reasons that
have nothing to do with a regression, and a flapping row gets ignored, which is how noisy checks die. Judging a range
instead (the way tools/ci/medians.py decides A/B by disjoint ranges) is more correct and more work; this file takes the
cheap honest path: one sentence here, and a caller who runs three times.

The log is llama-cli's own output ("llama_perf_context_print: prompt eval time = ... 31.3 tokens per second"),
or a one-line `N tokens per second`; the LAST rate in the file is used, because a warmup line is not the run.
Exit: 0 met the floor, 1 below it or unparseable, 77 no rate in the log at all (a skip, not a red).
"""
import argparse
import json
import re
import sys

SKIP = 77

# llama-cli: "eval time =     200.00 ms /    32 runs   (    6.25 ms per token,   160.00 tokens per second)"
# and shorter forms ("31.3 t/s", "31.3 tok/s") for one-line harnesses.
_RATE = re.compile(r"(\d+(?:\.\d+)?)\s*(?:tokens per second|tok/s|t/s)")


def parse_rates(text):
    """Every rate in the log, in order. Multiline, because llama-cli prints prompt and eval rates separately."""
    return [float(m) for m in _RATE.findall(text or "")]


def verdict(rates, floor, subject=""):
    """-> (exit_code, dict). The LAST rate is the generation rate; earlier ones are prompt eval."""
    if not rates:
        return SKIP, {"status": "skip", "subject": subject,
                      "why": "no token rate in the log -- the run did not report one"}
    last = rates[-1]
    # A floor of 0 means "record, do not judge" -- useful while calibrating on a new box.
    if floor <= 0:
        return 0, {"status": "recorded", "rate": last, "floor": floor, "subject": subject}
    if last < floor:
        return 1, {"status": "below_floor", "rate": last, "floor": floor, "subject": subject,
                   "why": f"generated {last:g} tokens/s, floor is {floor:g} -- correct output, "
                          f"{floor / last:.1f}x below the floor"}
    return 0, {"status": "ok", "rate": last, "floor": floor, "subject": subject}


def self_test():
    """Four arms. The second is the one this file exists for: #374's own before/after pair."""
    arms = [
        # (name, log text, floor, expected exit)
        ("#374 after the fix (31.3 t/s) meets a 20 floor",
         "llama_perf_context_print: eval time = 200.00 ms / 32 runs (6.25 ms per token, 31.3 tokens per second)\n", 20.0, 0),
        ("#374 before the fix (8.4 t/s) fails the same floor",
         "llama_perf_context_print: eval time = 200.00 ms / 32 runs (119 ms per token, 8.4 tokens per second)\n", 20.0, 1),
        ("a log with no rate is a SKIP (77), not a pass",
         "llama-cli: loading model\nerror: failed to load\n", 20.0, SKIP),
        ("the last rate wins: prompt 400 then eval 30 is judged on 30",
         "prompt eval: 400.0 tokens per second\neval: 30.0 tokens per second\n", 20.0, 0),
        # engine#2426's lesson applied to rates: a floor without its subject is a recollection, not evidence.
        ("the verdict carries its subject, so a pasted failure is checkable",
         "eval: 8.4 tokens per second\n", 20.0, 1),
    ]
    bad = 0
    SUBJECT = "selftest q4_k_m ctx2048"
    for name, text, floor, want in arms:
        got, detail = verdict(parse_rates(text), floor, SUBJECT)
        ok = got == want
        bad += 0 if ok else 1
        print(f"  {'ok ' if ok else 'FAIL'} {name}{'' if ok else f'  (got {got}, want {want})'}")
        if ok:
            subj = detail.get("subject", "MISSING")
            if subj != SUBJECT:
                print(f"  FAIL arm has no subject in its verdict (got {subj!r})")
                bad += 1
        if ok and got == 1:
            # the failure must NAME the number, or it is a red nobody can act on
            msg = json.dumps(detail)
            if "8.4" not in msg or "floor" not in msg:
                print("  FAIL the below-floor verdict does not name the rate and the floor")
                bad += 1
    print(f"{len(arms)} arms, {bad} failed")
    return 1 if bad else 0


def main():
    ap = argparse.ArgumentParser(description="Fail when a run generates below a token-rate floor.")
    ap.add_argument("--log", help="llama-cli or one-line harness output to judge")
    ap.add_argument("--floor", type=float, default=0.0, help="minimum generation tokens/s (0 = record only)")
    ap.add_argument("--subject", default="", help="model/quant/ctx that produced the rate, e.g. 'qwen3-0.6b Q4_K_M ctx2048'")
    ap.add_argument("--json", action="store_true", help="print the verdict as JSON")
    ap.add_argument("--self-test", action="store_true", help="run the four arms, no device needed")
    args = ap.parse_args()
    if args.self_test:
        return self_test()
    if not args.log:
        ap.error("--log is required unless --self-test is given")
    try:
        with open(args.log, "r", errors="replace") as fh:
            text = fh.read()
    except OSError as exc:
        print(f"token_rate_floor: cannot read {args.log}: {exc}", file=sys.stderr)
        return SKIP
    code, detail = verdict(parse_rates(text), args.floor, args.subject)
    if args.json:
        print(json.dumps(detail))
    else:
        # A floor is a number tied to a model, quant, context and box. Without the subject a pasted failure is a
        # recollection, not evidence (engine#2426's AUDITED <sha> lesson, applied to rates).
        print(f"JUDGED {args.subject or '<subject not given>'}")
        print(f"{detail['status']}: {detail.get('rate', '-')} tokens/s (floor {args.floor:g})"
              + (f" -- {detail['why']}" if detail.get("why") else ""))
    return code


if __name__ == "__main__":
    sys.exit(main())
Device Rate Testing Script

A new bash script token_rate_floor_device.sh is introduced to run a 1bit serve generation inside a gpu-hold ticket and then use token_rate_floor.py to judge the token rate. It handles prerequisites like finding the 1bit binary, model, and gpu-hold, and exits with code 77 if any are missing.

#!/bin/bash
# Copyright 2026 bong-water-water-bong
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# The caller for `token_rate_floor.py --log`. Without it the tool has a self-test and no consumer, which is
# engine#2418's defect: arms that are green and never applied to a real run (engine#2432's review, item 1).
#
# Judges ONE sequential `1bit serve` generation against TOKEN_RATE_FLOOR (default 0 = record only). Refuses
# with 77 -- CTest's skip code -- when it cannot run, and says which prerequisite is missing: a device row
# that silently passes because there was no model would be exactly the failure this tool exists to catch.
set -u
ROOT=${1:-$(cd "$(dirname "$0")/../.." && pwd)}
FLOOR=${TOKEN_RATE_FLOOR:-0}
PORT=${TOKEN_RATE_PORT:-8191}
SKIP=77

BIN=${TOKEN_RATE_BIN:-}
for cand in "$ROOT/build/1bit" "$ROOT/b2180/1bit"; do [ -n "$BIN" ] || { [ -x "$cand" ] && BIN=$cand; }; done
[ -n "$BIN" ] || BIN=$(command -v 1bit 2>/dev/null || true)
MODEL=${TOKEN_RATE_MODEL:-}
[ -n "$MODEL" ] || MODEL=$(ls "$HOME"/models/Qwen3-0.6B-Q4_K_M.gguf 2>/dev/null | head -1)
HOLD=${TOKEN_RATE_GPU_HOLD:-$(command -v gpu-hold || echo "$HOME/.local/bin/gpu-hold")}

if [ -z "$BIN" ] || [ ! -x "$BIN" ]; then
    echo "SKIPPED: token_rate_floor device row did NOT run -- no 1bit binary (set TOKEN_RATE_BIN)"; exit $SKIP
fi
if [ -z "$MODEL" ] || [ ! -f "$MODEL" ]; then
    echo "SKIPPED: token_rate_floor device row did NOT run -- no model (set TOKEN_RATE_MODEL)"; exit $SKIP
fi
if [ ! -x "$HOLD" ]; then
    echo "SKIPPED: token_rate_floor device row did NOT run -- gpu-hold not found ($HOLD), and a GPU run outside a ticket is not allowed"; exit $SKIP
fi

LOG=$(mktemp -t token-rate.XXXXXX.log)
cleanup() {
    local p; p=$(pgrep -f "port $PORT" | head -1)
    [ -n "$p" ] && { kill -TERM "$p" 2>/dev/null; for _ in $(seq 1 20); do kill -0 "$p" 2>/dev/null || break; sleep 1; done; }
    rm -f "$LOG"
}
trap cleanup EXIT

# The whole run lives inside the ticket: the process ends when the ticket ends.
"$HOLD" -t 10 -w 900 -- bash -c '
    set -u
    nohup "$1" serve -m "$2" --device hrx --host 127.0.0.1 --port "$3" --ctx-size 2048 --alias p --no-strict-device >/dev/null 2>&1 &
    for _ in $(seq 1 40); do curl -sf -m 3 "http://127.0.0.1:$3/health" >/dev/null 2>&1 && break; sleep 3; done
    curl -sf -m 5 "http://127.0.0.1:$3/health" >/dev/null || { echo "SKIPPED: server never became ready"; exit 77; }
    body=$(curl -s -m 300 "http://127.0.0.1:$3/v1/chat/completions" -H "content-type: application/json" \
      -d "{\"model\":\"p\",\"messages\":[{\"role\":\"user\",\"content\":\"Write a short paragraph about rivers.\"}],\"max_tokens\":64,\"temperature\":0}")
    case "$body" in *'"error"'*) echo "SKIPPED: server returned an error: $(printf %s "$body" | head -c 120)"; exit 77;; esac
    printf %s "$body" | python3 -c "
import json,sys,time
d=json.load(sys.stdin); c=(d.get(\"usage\") or {}).get(\"completion_tokens\") or 0
print(f\"{c} tokens\")" >/dev/null 2>&1
    t0=$(date +%s.%N); body=$(curl -s -m 300 "http://127.0.0.1:$3/v1/chat/completions" -H "content-type: application/json" \
      -d "{\"model\":\"p\",\"messages\":[{\"role\":\"user\",\"content\":\"Write a short paragraph about rivers.\"}],\"max_tokens\":64,\"temperature\":0}"); t1=$(date +%s.%N)
    case "$body" in *'"error"'*) echo "SKIPPED: server returned an error on the measured run"; exit 77;; esac
    printf %s "$body" | python3 -c "
import json,sys
w=float(sys.argv[1]); d=json.load(sys.stdin); c=(d.get(\"usage\") or {}).get(\"completion_tokens\") or 0
print(f\"{c/w:.2f} tokens per second\" if c>0 and w>0 else \"\")" "$(echo "$t1 - $t0" | bc)"
' _ "$BIN" "$MODEL" "$PORT" > "$LOG" 2>&1
rc=$?

if [ $rc -eq $SKIP ] || ! grep -q "tokens per second" "$LOG" 2>/dev/null; then
    echo "SKIPPED: token_rate_floor device row did NOT run -- $(tail -1 "$LOG" 2>/dev/null | head -c 120)"; exit $SKIP
fi

# The rate goes through the tool, which owns the judging, the floor and the subject line.
exec python3 "$(dirname "$0")/token_rate_floor.py" --log "$LOG" --floor "$FLOOR" \
     --subject "1bit serve $(basename "$MODEL") ctx2048"
New Tests Added

Two new CTest entries are added for token_rate_floor: one for the self-test of the Python tool and another for device-based rate testing. The device test is configured to skip with return code 77 when prerequisites are missing.

# token_rate_floor's four arms (engine#374): the rate floor that fails in the direction a correctness check
# cannot, since a 3.7x regression still emits the right tokens. The self-test needs no device; the --log mode
# is what a device row calls with llama-cli's output.
add_test(NAME token_rate_floor_selftest COMMAND python3 ${CMAKE_SOURCE_DIR}/tools/ci/token_rate_floor.py --self-test)
# The --log mode's caller (engine#2432 review item 1: a self-test with no consumer is engine#2418's defect). It
# judges one real `1bit serve` rate inside a gpu-hold ticket, and exits 77 -- CTest's skip -- naming the missing
# prerequisite when it cannot: a device row that passes for want of a model would be the failure this tool catches.
add_test(NAME token_rate_floor_device COMMAND ${CMAKE_SOURCE_DIR}/tools/ci/token_rate_floor_device.sh ${CMAKE_SOURCE_DIR})
set_tests_properties(token_rate_floor_device PROPERTIES SKIP_RETURN_CODE 77)

@bong-water-water-bong
bong-water-water-bong enabled auto-merge (squash) November 15, 2026 03:27
@bong-water-water-bong
bong-water-water-bong merged commit 0ffb4c7 into main Nov 15, 2026
10 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the verify/hostgemm-no-orphan branch November 15, 2026 03:36
bong-water-water-bong added a commit that referenced this pull request Nov 15, 2026
…llow-up to #2472) (#2477)

#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: bong-water-water-bong <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

READY. This is the orphaned-server defect that has cost this fleet the most, diagnosed at the exact line, and the setsid mechanism is the part nobody would guess:

NPU_INFER_HOST_GEMM=1 setsid "$BIN" forward-serve ... &
PID=$!
trap 'kill $PID 2>/dev/null; wait $PID 2>/dev/null' EXIT

setsid makes $! the setsid pid, so the trap kills something that has already exited and never reaches the server. The trap looks correct — kill + wait on the backgrounded pid is the textbook shape — which is why it survived review and why it produced a 22 h orphan rather than an obvious crash.

Three things that make the fix right rather than merely different:

  • setsid dropped, not worked around. The clean fix is that $! becomes the server again, so the existing trap works as written — no second mechanism, no kill -0 polling, no pidfile. The setsid was presumably there to detach from the terminal, and in a gpu-hold/npu-hold ticket that is unnecessary: the ticket already owns the process group semantics.
  • The belt is port-scoped, not binary-scoped: pkill -f "forward-serve .* -p $PORT". That is the right blast radius — it cannot kill another lane's serve on a different port, which a bare pkill -f forward-serve would do, and tonight there are three servers running on this box.
  • The second bullet is the honest one: "cleanup should not depend on…" — a trap that depends on the pid variable being right is one refactor away from the same bug, so the belt is independent of the fix.

And the gap it exposes is the finding I would keep: "tests/gpu_hold_tree_test.sh already exists and asserts exactly the property that was violated" — the check exists and did not cover ~/bin. That is the same shape as everything else tonight: a check that is correct about a corpus it does not include. Worth one line in the PR naming what would bring ~/bin inside a check — even a weekly bash -n + a trap-shape grep over ~/bin/*.sh would have caught this before the orphan, and it does not need the repo to own those scripts.

One ask: the 22 h orphan and the flm-real serve lfm3:1.7b -p 8199 this time are both -p port-scoped serves. Is PORT always set on the line the trap quotes? If a script ever reaches the trap with PORT unset, pkill -f "forward-serve .* -p " matches every serve — an empty pattern component. One [ -n "$PORT" ] || kill only $PID guard in the trap closes the only way this belt can cut too wide.

Not verified by me: the bash -n, the copyright check and any live run — I take them as reported. The mechanism, the blast radius and the belt-independence are what I can check, and all three are right.

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