Skip to content

tools: load-groups.sh kills a process that prints nothing for BOUND seconds - #169

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-load-groups-timeout
Oct 14, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-load-groups-timeout

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

What and why

In lg_process (tools/ref/load-groups.sh), if ! IFS= read -r -t "$BOUND" ...; then st=$? stores the status of the negated test, so st is always 0 and the [ "$st" -gt 128 ] branch, which prints "no line for N s; killing the process" and kills the process, never runs. A grouped arm that stalls without printing a line is not killed after BOUND seconds as the header promises. wait "$pid" blocks until the outer timeout ends the process, BOUND x (arms + 1) seconds after the start, with the timing lease held the whole time. Closes #119.

The change: st=0 and IFS= read ... || st=$? keep read's own status, and the branch tests [ "$st" != 0 ]. A timeout (above 128) kills the process as intended; the end of the stream (status 1) still just leaves the loop.

The --self-test of the file ran only the grouping and the order. It now also drives lg_process on a process that prints its arm line and then stalls, with three arms in the unit. The process's timeout tells the two ends apart without a clock: the idle bound's kill sends it a TERM, which it passes to the process, and it ends 143; the outer bound would end it 124. The case checks that the idle-bound message is printed once, that the stalled arm ends with rc 143, and that the two arms behind it are left for a fresh load. BOUND is one second scaled with the host's load by tools/bloomery/selftest.py (load_cap), so a loaded check-recipes run does not miss the first line. lg_process opens its descriptors with exec {fd}<>, which needs bash 4.1, so under the macOS bash 3.2 the case prints skip stall and the rest of the self-test runs as before.

A host with coreutils timeout (Linux, CI) runs the case under it. A host with none (the Mac) needs a stand-in, and tools/gpu-gate.sh --self-test already wrote one inside its function (:408-412 at fadec9d0), which this case could not call. That one also died on a TERM and left its command running. So the stand-in becomes one file, tools/ref/stub-timeout.py, beside stub-llama-server.py, and both self-tests copy it in as timeout when command -v timeout finds none. It is not in tools/ref/card-tests/bin/, because card-tests/run.sh puts that folder on PATH on a host with no flock, and a timeout there would change the card-tests that check for one (lease.sh, depth-serve.sh). It takes timeout [--kill-after=K] S COMMAND... and ends the two ways coreutils does: 124 at its bound, with the command killed, and the command's status (143 for a TERM) when it is sent a TERM, which it passes on. It leaves no process behind, so the end of the stream reaches the reader when the command ends. The stand-in sits in one shared file because otherwise the inline stand-in in gpu-gate.sh and the new case would each carry a copy of the same code. The net change is the same as with a second copy in load-groups.sh, 15 lines: gpu-gate.sh goes from 5 lines to 1 that copies the file in, the file has 18 (a 3-line docstring among them), and load-groups.sh reaches it in one line, where a second copy took 15.

tools/check-recipes.sh's comment on the load-groups block said the self-test starts no process; it now says what the self-test covers.

Code shape

  • No second copy. The driver's one read is fixed in place, and the timeout stand-in has one owner, tools/ref/stub-timeout.py, for both self-tests that need one.
  • Model code holds only architecture facts. No model code changes.
  • Dead code is gone. The branch that never ran now runs; gpu-gate.sh's inline stand-in is removed.
  • No silent failure. A stalled process is killed at the idle bound and says so on stderr.
  • Comments state what is true now. The self-test's header line and the check-recipes.sh block comment name what the self-test covers.
  • No relaxed gate. Only a case is added.
  • cargo fmt and cargo clippy are clean on what I touched; no Rust file is touched.

Duplication found or removed (path:line), or "none": the timeout stand-in of tools/gpu-gate.sh (:408-412 at fadec9d0), now tools/ref/stub-timeout.py, which the new case uses too.

What I ran

FAIL first. lg_process of fadec9d0 with this commit's self-test, on a Mac with bash 5.3.20:

FAIL stall-killed: got [0], want [1]
FAIL stall-term: got [post 0 rc=124], want [post 0 rc=143]
ok stall-left
self-test: FAIL (2 failures)

The mutant the case has to catch: this commit's file with only the idle bound's kill "$pid" line removed ends FAIL stall-term: got [post 0 rc=124], want [post 0 rc=143], because the outer bound then ends the process. The case does not depend on how long either run takes. With this commit:

ok stall-killed
ok stall-term
ok stall-left
self-test: ok (0 failures)
  • /bin/bash tools/ref/load-groups.sh --self-test (3.2.57): skip stall: bash 3.2.57(1)-release has no exec {fd}<>, then self-test: ok (0 failures).
  • tools/gpu-gate.sh --self-test, which takes the shared stand-in on this Mac (it has no timeout): gpu-gate self-test: 99 of 99 ok under bash 3.2.57 and under bash 5.3.20.
  • The stand-in alone: a command that ends first gives rc 0 and the reader its end of stream at once; the bound gives 124; a TERM gives 143; no sleep is left afterwards.
  • bash tools/check-comments.sh: ok. shellcheck -x on load-groups.sh, gpu-gate.sh and check-recipes.sh: no new finding.
  • just mac-static fadec9d0 on a second Mac (Apple M5): mac-static: ok, check-recipes rc 0 (127 s, its blocks run 3 at a time on that Mac; gpu-gate self-test: 99 of 99 ok inside it), combos 0 shapes run and 49 skipped as out of scope. The check ran on this PR's head, rebased on fadec9d0.

Not run here: the case under coreutils timeout, which only Linux has (CI's just contrib-check --tier t0 on Ubuntu runs it, through tools/check-recipes.sh), and a grouped arm that stalls under depth-ds41.sh or depth-qwen3moe.sh on the box. The driver's code path is the one the self-test drives, with a stand-in for the binary.

Hardware (if the change is for a machine)

None. A Mac (Apple M4 Pro, macOS 27) with the system bash 3.2.57 and bash 5.3.20 from Homebrew, and a second Mac (Apple M5) for just mac-static.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

…econds

lg_process read the status of read -t after a negated test, so st was always 0 and the st > 128 kill branch never ran: a stalled grouped arm waited at wait "$pid" for the outer timeout, BOUND x (arms + 1), with the timing lease held. read's own status is kept now, so an idle bound ends the process and EOF still just ends the loop. The self-test drives lg_process on a process that stalls after its arm line and checks that its timeout ended with 143, the idle bound's TERM, and not with 124, the outer bound. A host with no timeout gives that case and gpu-gate.sh's self-test one stand-in, tools/ref/stub-timeout.py, which ends 124 at its bound and passes a TERM on to the command as coreutils does, and leaves no process behind; gpu-gate.sh's inline one is gone.
@github-actions github-actions Bot added the tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo label Oct 14, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: CLEAN: The idle bound now uses read's status, and the new assertions reject the reported defect.

Checked

Duplicates: 5 new named functions checked; the callback overrides are test fixtures, and the timeout stand-in replaces its inline owner. No duplicates found; no dryer pairs available.
Complexity: No Rust functions changed.
Silent failure: 3 paths followed: failed read, child termination, and deadline expiry. Their statuses reach the caller's failure handling.
Tests: The stall assertions pass in an in-memory pipe harness. In tools/ref/load-groups.sh:171, restoring the negated read turns them red. Dropping the diagnostic (:174), idle kill (:175), or remaining-arm assignment (:235) also turns an assertion red. Normal EOF completes with rc 0. The stand-in returns 0, 124, and 143 for normal exit, its deadline, and TERM respectively.
Gates: None relaxed or removed. The added stall case has FAIL-first evidence in the PR body.
Escape catalog: No C1–C4 patterns match the added lines.
Performance: Tool and self-test code only; no inference hot path changed.

Notes

Dryer and crapper did not run because no Rust file changed.
Full self-tests were not run; runtime probes used pipes instead of temporary FIFO files.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

Filed outside this PR: #171

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit cd5bd66 into midagedev:main Oct 14, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

load-groups: negated read hides the timeout status

1 participant