fix(ci): ignore exited and zombie KFD PIDs in box_step.sh so CI steps do not self-preempt

Merged
DU
8d ago
+234-13

Based on main d552394eb (#1060–#1065 merged).

What

On lucebox3, .github/ci/box_step.sh preempts its own ctest steps when a short-lived test child exits, waits 120 s for the GPUs to stay quiet, and restarts the step from test #1.

In main run 43754866765, all 7 GPU yields (5 on R9700, 2 on Strix Halo, ~20 min total wall time) were self-kills immediately after a passing ctest child exited:

20:54:18.094  105/136 Test #1402: ds4_maskless_prefill_disabled ... Passed 0.23 sec
20:54:18.095  box_step.sh: line 39: /proc/346852/environ: No such file or directory
20:54:18.096  box_step.sh: line 45: /proc/346852/stat: No such file or directory
20:54:18.099  ##[warning]Another process started using a GPU; stopping this step, to rerun it once the GPUs are free. In use by:
              pid 346852 (exited)

Cause: Linux KFD tears down /sys/class/kfd/kfd/proc/<pid> asynchronously after /proc/<pid> is reaped. While that entry lingers, ours() and monitor() fail to open /proc/<pid>/{environ,stat,cmdline} and return 1, so others() reports the exited child PID as an external GPU process.

Fix (.github/ci/box_step.sh):

  • Add alive() checking that /proc/<pid>/stat is readable and not in state Z, X, or x, and call it both before and after ours/monitor in others() to close the TOCTOU window when a process exits mid-check.
  • Recognize step session descendants via sid == $step in ours() (covers grandchildren reparented to PID 1 inside setsid).
  • Wrap /proc reads in { ...; } 2>/dev/null so vanished or other-user /proc files do not leak bash open errors to stderr.
  • Allow env overrides for kfd, proc, vmstat, and poll/quiet intervals (defaults unchanged) so the script can be unit-tested without KFD hardware.

Behavior for live external GPU processes is unchanged: a live non-monitor process in KFD still preempts the step, waits for the quiet window, and reruns.

Tests

  • New .github/ci/test_box_step.py (4 cases):
    • test_exited_kfd_pid_does_not_preempt_step: stale KFD dir with no /proc/<pid> does not yield and emits no No such file or directory stderr.
    • test_zombie_kfd_pid_does_not_preempt_step: zombie (Z) entry in KFD does not yield.
    • test_monitor_and_own_job_kfd_pids_do_not_preempt: rocm-smi and own RUNNER_TRACKING_ID entries are ignored.
    • test_live_external_gpu_process_yields_and_reruns: live external GPU process (with chmod 000 environ simulating another user) still preempts, waits, and reruns the step cleanly with no Permission denied stderr.
  • Run locally: bash -n .github/ci/box_step.sh, pytest .github/ci/ (109 passed), ruff check on .github/ci/*.py, and check_commit_messages.py.
  • Run on CI: uv-workspace, build-megakernel, and gpu-tests (DGX GB10) passed; lucebox3 jobs are queued.

Known limits, not addressed here

  • Not yet observed live on lucebox3 (jobs are queued behind the current runner backlog); the failing sequence from run 43754866765 is reproduced by test_exited_kfd_pid_does_not_preempt_step.