Skip to content

gpu-gate self-test: the lib-test stub exits at once on TERM - #780

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-fix-gpu-gate-self
Oct 24, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-fix-gpu-gate-self

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

gpu-gate 자체 시험에서 가끔 143으로 실패하던 시험용 stub가 TERM을 받으면 바로 끝나게 고칩니다.

What and why

On a loaded machine, the lib path propagates signal check in the gpu-gate.sh self-test sometimes reports 143 where 23 is wanted, and lib child is stopped after signal reports the same code with it.

The gate is not at fault. The cause is the Python stub that stands in for the lib test. Its TERM handler ended with sys.exit(23). On one TERM, GNU timeout calls kill on the child and then kill(0, SIGTERM) on its own process group. While sys.exit runs the interpreter shutdown, CPython puts the default TERM action back. A second TERM that lands in that short window ends the stub by signal, and timeout hands that code on. A loaded machine can delay timeout between its two signals long enough to reach the window.

The stub handler now calls os._exit, so it ends with the wanted code at once and has no shutdown window. The check, its wait events and its expected values stay as they were. The stub writes nothing to stdout before TERM, so skipping the flush loses no output.

Real runs are not affected. The Rust test binary installs no TERM handler and ends with 143 on the first TERM, which gate.sh returns as is.

I found no open issue or PR for this.

Release notes: internal: a test fixture ended with the wrong code when a second TERM arrived during its shutdown.

Code shape

  • No second copy. No new function, constant or helper; one line changes.
  • Model code holds only architecture facts. No model code is touched.
  • Dead code is gone. Nothing is left unused.
  • No silent failure. The stub still ends with the code LIB_TERM names, 143 when unset.
  • Comments state what is true now. The two added comment lines say why os._exit is used.
  • No relaxed gate. No band, tolerance or lint moved. The check still catches a runner that returns the wrong code; before, the stub could produce a 143 by itself and blur that.
  • cargo fmt and cargo clippy: no Rust changed, so I did not run them.

Duplication found or removed (path:line): none.

What I ran

The change is in tools/gpu-gate.sh, 3 insertions and 1 deletion, in the self-test stub only.

The load runs use gpu-gate.sh --self-test --part 4 on a 12-core Linux machine with GNU coreutils 9.7 timeout and Python 3.14.4, with 12 busy loops running. Four copies start together, in three rounds. "base" is tools/gpu-gate.sh from upstream main, "head" is this branch.

RESULT base: 1 of 12 runs FAIL 'lib path propagates signal'
base r1.4: FAIL lib path propagates signal: rc 143 (want 23), /./
base r1.4: FAIL lib child is stopped after signal: rc 143 (want 23), /^child-stopped$/
RESULT head: 0 of 12 runs FAIL 'lib path propagates signal'

A longer load run gave the same result on both arms. The failure is rare, so this run does not separate base from head:

RESULT base: 0 of 24 part-4 runs FAIL 'lib path propagates signal'; 0 of 24 not all ok
RESULT head: 0 of 24 part-4 runs FAIL 'lib path propagates signal'; 0 of 24 not all ok

An strace of timeout on one TERM shows the two kills:

  strace: 707343 kill(707344, SIGTERM)            = 0
  strace: 707343 kill(0, SIGTERM)                 = 0

To test the mechanism without waiting for the rare case, I ran the handler line of each version and sent a second TERM shortly after the first, at gaps of 300 and 700 microseconds, with 30 tries per gap:

base gap300 idle x30: rc143=30
head gap300 idle x30: rc23=30
base gap700 idle x30: rc143=30
head gap700 idle x30: rc23=30

With a real timeout and a busy loop pinned to CPU 0, one head run ended with the 60 second bound. A rerun of 600 tries per arm did not repeat it:

base gnu hog x300: rc23=300
head gnu hog x300: rc124=1 rc23=299
head gnu hog1 x300: rc23=300
head gnu hog2 x300: rc23=300

The stub handler is not involved when a TERM is lost before the handler is installed, so I read the single timeout as timeout missing a TERM right after fork. I did not confirm that.

Reproduce: run bash tools/gpu-gate.sh --self-test --part 4 in batches of four on a loaded machine and count the FAIL lib path propagates signal lines.

Not run: cargo checks (no Rust change), the other gate self-test parts, and any GPU gate. The change touches no device path.

Hardware (if the change is for a machine)

Not a machine change. The runs used a CPU-only load on a 12-core Linux machine and no GPU.

AI help

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

GNU timeout sends its TERM to the child and then to its process group.
The stub's handler called sys.exit, whose interpreter shutdown restores
the default TERM action; when the group's TERM came during that window
on a loaded host, the stub died with 143 and the signal case read 143
in place of the 23 it asked for. os._exit leaves no such window.
@github-actions github-actions Bot added the tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo label Oct 24, 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 fixture preserves its requested TERM exit code by skipping interpreter shutdown.

Checked

Duplicates: 0 new functions, types or constants; no new duplication.
Complexity: no branches added or changed.
Silent failure: the unchanged LIB_TERM default selects 143; external cancellation sets 23 and checks the returned status.
Tests: shell syntax and embedded lib-test Python parsing passed. Isolated probes of the changed handler passed for configured/default TERM and ignored TERM followed by KILL. The existing status assertion expects 23 for external cancellation.
Gates: no thresholds, cases or assertions changed.
Escape catalog: no C1–C4 pattern matched the diff.
Performance: tooling only; no inference hot path touched.

Notes

The full self-test and repeated-signal race reproduction were not run during validation.

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

@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 a43f516 into midagedev:main Oct 24, 2026
7 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.

1 participant