Skip to content

CI keeps the MPI supervisor's stacks, and they reach native frames - #954

Merged
lmoresi merged 3 commits into
developmentfrom
bugfix/ci-keep-hang-stacks
Nov 7, 2026
Merged

lmoresi merged 3 commits into
developmentfrom
bugfix/ci-keep-hang-stacks

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 6, 2026

Copy link
Copy Markdown
Member

CI now keeps the MPI supervisor's stacks when a shard fails, and those stacks reach native frames, so a hang that happens only on a runner can be told from a slow solve.

What was wrong

Parallel shard 4 hung on #951's runs in test_1064_rotated_freeslip_parallel's fifth test, with every rank in _solve_rotated_iterative (run 42130702511). It does not reproduce elsewhere: the same scripts/test.sh --p 2 --shard 4/4 on hyperion passes, pinned to 2 cores (4033 s) and unpinned (6174 s), and so do the batch and its first three files.

Two things stopped the diagnosis:

  • The stacks went to /tmp/uw-stacks-* on the runner and were lost with it.
  • "Stuck, not slow" reads Python frames only. They stop at the C boundary, so a rank in an MPI wait and a rank in a long KSP solve both read _solve_rotated_iterative() and both burn a core.

The fix

  • scripts/mpi_supervisor.py: when gdb is on the path, it takes each rank's native stack after the Python samples, writes rank_N_pid_P.native beside the .stack file, and quotes the main thread's innermost frames in the log. Without gdb it says so and the Python diagnosis stands.
  • Each rank allows the attach itself with PR_SET_PTRACER, so no root and no sysctl are needed where Yama restricts ptrace. That is a no-op elsewhere.
  • .github/workflows/build_uw3_and_test.yaml: the shards install gdb, without failing the shard if that does not work, and upload /tmp/uw-stacks-* as hang-stacks-shard-N on failure, kept five days. Neither gdb nor py-spy is in the pixi env, so it comes from apt.

A planted hang at np 2 now logs:

native: rank 1: __GI_sched_yield < MPIR_Wait_state < MPIR_Wait < MPIC_Wait < MPIC_Sendrecv < MPIR_Barrier_intra_dissemination < ...

No parallel test file is added, so no MPI batch moves. The optional KSP monitor switch on the test was dropped: the rotated solve builds its own KSP under a per-solve prefix (rotfsN_), so the solver's options do not reach it, and the native stack answers the same question.

Tests

tests/test_0063_mpi_hang_supervisor.py::test_a_hang_gets_native_stacks_that_reach_the_mpi_library, written first, needs rank 1's native stack and the log line to reach the barrier it waits in. Before: expected a native stack per rank, got []. After: 4 passed in the file. It skips where gdb is absent, so without the apt step it would not run on CI.

The workflow change is only checked as valid YAML: it can run only on a runner. A failed shard on this PR would be the first real test of the upload.

Refs #951

Underworld development team with AI support from Claude Code

A parallel batch hung on a CI runner and on no other machine (test_1064's
spherical case, #951's shard 4). The supervisor's diagnosis went to a temporary
directory on the runner and was lost, and its "stuck, not slow" rests on Python
frames, which stop at the C boundary: an MPI wait and a long KSP solve read alike.

The supervisor now takes each rank's native stack with gdb when gdb is on the
path, writes rank_N_pid_P.native beside the Python stack and quotes the main
thread's innermost frames in the log. Without gdb it says so. Each rank allows the
attach itself with PR_SET_PTRACER, so no root and no sysctl are needed where Yama
restricts ptrace.

The CI shards install gdb, without failing the shard if that does not work, and
upload /tmp/uw-stacks-* when the shard fails, kept five days.

tests/test_0063_mpi_hang_supervisor.py (written first) plants a hang at np 2 and
needs rank 1's native stack, and the log, to reach the barrier it waits in. Before:
no native stack. After: 4 passed.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 6, 2026 05:46

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@lmoresi

lmoresi commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

Adversarial review of #954 at 99cd966

The branch keeps the MPI supervisor's stacks as a CI artifact and adds a gdb native stack per rank.

Evidence:

  • This PR's own run, 42170374397. Shard 4 hit the test_1064 hang, logged native frames for both ranks, and uploaded hang-stacks-shard-4 (artifact 13482718419, expires 2026-11-11).
  • Earlier CI logs, cited by run id.
  • Serial probes that put fake gdb scripts on PATH. They need no MPI.

Must fix

M1. [high] .github/workflows/build_uw3_and_test.yaml:146 — if: failure() skips the upload when the hung shard reaches its 60-minute cap, and the hung shard finishes within a minute of that cap.

  • At timeout-minutes: 60 the shard is cancelled, not failed. Runs 41619168536 and 41630414677 (PR The finest level's FAC blocks are cut from every rank's rows (#925) #934) carry "The job has exceeded the maximum execution time of 1h0m0s", with shard 4/4 cancelled and Run tests=cancelled; their post steps still ran. failure() is false after a cancellation, so the upload is skipped and the stacks go with the runner.

  • Every recent shard 4 run hit the same supervisor kill in test_1064. Durations against the 60-minute cap:

    run shard 4
    42130702511, attempt 1 59.2 min
    42130702511, attempt 2 57.5 min
    42095953261 (development push at eddab70) 59.0 min
    42156031963 56.6 min
    42164806343 58.5 min
    42170374397 (this PR, uploaded) 59.1 min, 53 s under the cap
  • The branch adds to that time. In this run: apt 7 s, the new test 5 s of its batch's wall clock (219.46 s against 214.01 s on 42164806343), and gdb 4.3 s (06:37:56.23 to 06:38:00.52).

  • The apt step varies by mirror. On shard 2 of the same run it fetched 4.6 MB in 1 min 52 s at 41.4 kB/s. That delay on the 59.2-minute run crosses the cap, and the upload would not run.

  • Fix: if: failure() || cancelled() on the upload step, and headroom for shard 4 (raise its timeout-minutes).

Should fix

S1. [medium] scripts/mpi_supervisor.py:246-286,461-466 — one native sample cannot tell stuck from slow, and the first real stacks are the case it cannot decide.

The CI run printed both of these lines:

no rank moved in 20 s: this is stuck, not slow
native: rank 0: MatMultTransposeAdd_SeqAIJ < MatMultTranspose_SeqAIJ < MatMultTranspose_MPIAIJ < MatMultTranspose < MatRestrict < PCMGFCycle_Private < PCApply_MG_Internal < PCApply_MG
native: rank 1: sched_yield < MPIR_Waitall_state < MPIR_Waitall < internal_Waitall < PetscSFLinkFinishCommunication_Default < PetscSFReduceEnd_Basic < PetscSFReduceEnd < VecScatterEnd_Internal
  • Both ranks are in the same MatRestrict of the same FMG F-cycle (rank 1's file continues VecScatterEnd < MatMultTranspose_MPIAIJ < MatMultTranspose < MatRestrict < PCMGFCycle_Private). Rank 0 is in its local SpMV, and rank 1 waits for that restriction's scatter.
  • This is not a collective mismatch. A single sample cannot say whether rank 0 is looping inside MatMultTransposeAdd_SeqAIJ or the KSP is iterating without converging.
  • The "stuck, not slow" line above it comes from Python frames, which do not move during any C call. With native frames showing rank 0 computing, that line misleads.
  • The PR's headline claim, "so a hang that happens only on a runner can be told from a slow solve", is not delivered for the hang it was written for.
  • Fix: attach twice, a few seconds apart, and report per rank whether the main thread's frame list changed. A loop in one routine repeats; an iterating solve does not. When native frames are present, base the stuck/slow line on them.

S2. [medium] .github/workflows/build_uw3_and_test.yaml:136-138 with tests/test_0063_mpi_hang_supervisor.py:91 — an apt failure removes the feature's only test without a trace.

The install step is continue-on-error: true and has no apt-get update before it. It worked in this run (gdb 15.1-1ubuntu1~24.04.1 from the image's index), but a superseded package on the mirror fails it quietly. The new test is skipif(shutil.which("gdb") is None), so the shard then passes with the native path untested. In this run the new test did run and pass: its batch went from 243 to 244 passed, with no skip. Fix: sudo apt-get update && sudo apt-get install ..., and fail rather than skip the test when GITHUB_ACTIONS is set and gdb is missing.

S3. [medium] scripts/mpi_supervisor.py:246-286 — the bound on gdb, the refused-attach line and the no-gdb line have no test, and all of them can be tested serially.

Mutants we constructed and the test that catches each:

mutant caught by
drop the _collect_native_stacks call new test (len(native) == 2), on a host with mpirun and gdb
drop the prctl call new test only where /proc/sys/kernel/yama/ptrace_scope is 1; nothing on a scope-0 host
drop timeout= from the gdb call nothing
attach serially instead of in threads nothing
the no-gdb branch returns None (main() raises before _kill_the_job) the existing hang tests on a host with mpirun and no gdb; nothing on CI, which now has gdb
apt step fails nothing (the test skips)
upload path or condition wrong nothing (workflow untested; if-no-files-found: ignore hides a wrong path)

The fake-gdb probe reaches every branch of _collect_native_stacks with no MPI. Fix: a level_1 test of _native_frames on a recorded transcript (the artifact from this run has two), and of _collect_native_stacks with fake gdb scripts that hang, refuse and succeed. Assert the bound, one line per rank, and a file per rank.

S4. [medium] scripts/mpi_supervisor.py:263-265,276-277 — one undecodable byte in gdb's output drops every rank's native stack from the report, with no line saying so.

subprocess.run(..., text=True) raises UnicodeDecodeError inside the attach thread. The thread dies, lines lacks that rank, and no .native file is written. Probe (fake gdb printing \377): two thread tracebacks on stderr, ranks with a line: 0 of 2, files=[]. The kill still runs and the exit code is unchanged. Fix: errors="replace" (or capture and write bytes), and have the thread record a line on any exception.

S5. [low] scripts/mpi_supervisor.py:266-267 — on a gdb timeout nothing is written, and the partial output is discarded.

On POSIX TimeoutExpired.stdout carries what gdb printed before the kill. Probe: a gdb that never returns, 2 s budget: gdb took over 2 s, files=[]. The guide (mpi-hang-supervision.md:77) says the whole stack goes to rank_N_pid_P.native. Fix: write exc.stdout and exc.stderr to the file on timeout.

S6. [low] scripts/mpi_supervisor.py:270-271 — a refused attach logs "gdb got no frames, see rank_N_pid_P.native", and the reason is only in the file.

Probe (gdb exits 1 with ptrace: Operation not permitted.): both ranks log gdb got no frames. The test's own message says "a log is all a reader may have". Fix: quote gdb's last stderr line in the log line.

S7. [low] scripts/mpi_supervisor.py:42,44 — import re twice.

S8. [low] docs/developer/guides/mpi-hang-supervision.md:84-85,97-101 — the guide points at a description that is not there, and keeps a claim that no longer holds.

"the handler below allows it with PR_SET_PTRACER": "How the dump is armed" (lines 91-101) does not mention it. That section still says arming "costs a healthy run nothing", but every supervised Python process now drops its Yama ptrace restriction for its whole life. Separately, the _collect_native_stacks docstring (scripts/mpi_supervisor.py:250-251, "only the native frames tell a collective mismatch from a solve that is not converging") and the PR body overstate what one sample shows (S1).

S9. [low] scripts/mpi_supervisor.py:99-100 — PR_SET_PTRACER_ANY is wider than the attach needs.

Yama accepts the declared tracer and any of its descendants. The supervisor writes the module, so it can embed its own pid. prctl(PR_SET_PTRACER, <supervisor pid>) then admits its gdb child and nothing outside its tree. As written, any same-uid process can attach to every supervised rank, on hyperion and the kaiju runner as well as CI.

Notes

N1. The stacks #951 needed already exist. Run 42170374397 reproduced the hang on this PR's merge commit, and its artifact has both ranks' Python and native stacks; it expires 2026-11-11. The hang is not specific to #951. It reproduced on the development push at eddab70 (42095953261), which is this branch's merge base, and on #946's runs. If #951 is rerun anyway, a re-run keeps the original event's GITHUB_SHA and GITHUB_REF (GitHub docs, "Re-running workflows and jobs"). That is the old refs/pull/951/merge commit, so the re-run has the old workflow and the old supervisor. #951 needs a new event (merge development into it, or push).

N2. scripts/mpi_supervisor.py:100 — the prctl argument is right by sign extension, not by type. ctypes passes a bare Python int as a C int: llabs(2**32) returns 0, while llabs(c_longlong(2**32)) returns 4294967296 (probe). So ctypes.c_ulong(-1).value reaches prctl as int -1, and becomes (unsigned long)-1 only because libffi sign-extends it into the 64-bit register. Pass ctypes.c_ulong(-1), the object.

N3. scripts/mpi_supervisor.py:96-102 — the optional prctl call sits before the essential faulthandler.register. An exception outside (OSError, AttributeError) aborts the module. site prints "Error in usercustomize" and continues, SIGUSR1 keeps its default action, and the first dump request kills the rank, so there are no Python stacks either. Move the prctl call after the registration.

N4. build_uw3_and_test.yaml:150 against mpi-hang-supervision.md:87. The guide says $TMPDIR/uw-stacks-* and the workflow uploads /tmp/uw-stacks-*. They agree on the GitHub runner, but if-no-files-found: ignore hides a mismatch anywhere TMPDIR is set. The artifact is 12 directories, one per MPI batch, and 92 of its 96 files are empty .stack files from batches that did not hang. Passing --artifacts "$RUNNER_TEMP/uw-stacks" from test.sh and uploading that path removes the guess; the supervisor could also delete its directory on a clean exit.

N5. scripts/mpi_supervisor.py:280-285 — one gdb per rank, all at once. At np 52 on kaiju that is 52 gdbs loading symbols at once on a node holding 52 ranks. Cap the concurrency, for example at 8.

N6. Pre-existing, flagged under Charter §2.

  • _read_dumps keeps one pid per rank key. A Python child that inherits PMI_RANK writes a second rank_0_pid_*.stack, and the sorted filename decides which pid is diagnosed and now attached.
  • tests/parallel/hang_controls/rank_zero_misses_the_collective.py:15 names test_0056_mpi_hang_supervisor.py. The file is test_0063.

N7. Artifact name on a re-run attempt. We did not verify this. upload-artifact v4 fails on a name that already exists in the run (overwrite: false in this run's log), and its README does not say whether an earlier attempt's artifact counts. overwrite: true removes the question.

N8. The log quotes the 8 innermost frames of the main thread. In both CI attaches the innermost frame was sched_yield directly under the MPI wait, and the new test passed. If an attach lands inside the UCX progress engine, three to five extra frames push the MPI routine out of those 8. A constructed UCX-depth stack logs epoll_wait < ucs_event_set_wait < uct_tcp_iface_progress < ucp_worker_progress < MPIDI_UCX_progress < MPIDI_progress_test < MPIR_Wait_state < MPIR_Wait. The test's log assertion ("barrier" in logged) depends on where the stop lands. Quoting from the first PMPI_/MPIR_ frame outward would make it deterministic.

Attacks that failed:

  • gdb attaches on the GitHub runner without root: both ranks' native stacks arrived in 4.3 s (run 42170374397).
  • Thread 1 selection skips the UCX async thread, which gdb lists first in both .native files.
  • The upload fired on a failed shard: 96 files, 23,597 bytes, at uw-stacks-*/ paths.
  • Exit status: 124 is still returned after the native step. A clean run never reaches _collect_native_stacks, which is only on the silence path.
  • gdb cannot hold up the kill indefinitely. Probe: a gdb that never returns, 2 s budget, both ranks back in 2.0 s, because the attaches run in parallel.
  • A rank left stopped by a killed gdb is still killed: _kill_the_job escalates to SIGKILL.
  • .native files do not reach _read_dumps, which globs *.stack.
  • No gdb on PATH: one line, no exception (probe).
  • "Thread 10 (..." does not match startswith("Thread 1 ").
  • PR_SET_PTRACER is 0x59616d61, and PR_SET_PTRACER_ANY is (unsigned long)-1.
  • [activation.env] sets no PYTHONHOME or PYTHONPATH that would break gdb's embedded Python.

Issue verdicts

Not checked

  • test_0063 launches mpirun, so it did not run here. It ran and passed on CI in run 42170374397.
  • Whether the prctl is what made the CI attach work: the runner's ptrace_scope is not in the log. A one-line cat /proc/sys/kernel/yama/ptrace_scope in the install step would say. The Linux server should report its own value, and run the new test with the prctl line deleted (it must fail where the scope is 1).
  • The upload on a real cap cancellation, after M1's change. It needs a run that crosses the cap.
  • upload-artifact v4 on a re-run attempt with the same name (N7).
  • Whether Ubuntu 24.04's gdb 15.1 queries debuginfod in -batch mode where DEBUGINFOD_URLS is set. It was not set on CI (attach in 4.3 s).

Underworld development team with AI support from Claude Code

BLAS picks its kernels from the CPU, and #963's solve stops finishing only on some
runs, with the same tree, runner image and lockfile. The next hang then says which
host it was on. Also prints ptrace_scope, which the native stacks depend on.

Refs #963

Underworld development team with AI support from Claude Code
The upload ran only on failure(), but a shard at its cap is cancelled, and a hung shard
finishes within a minute of 60: now failure() || cancelled(), with a 70-minute cap.

The supervisor takes two native samples and says whether the frames moved, because
one sample could not tell the first real stacks' solve from a loop. A refused attach
quotes gdb's reason, a hung gdb keeps what it printed, an undecodable byte costs no
rank its stack, and at most 8 gdbs run at once. The log quotes frames from the first
MPI routine. PR_SET_PTRACER names the supervisor, not any process, and comes after the
dump handler is armed.

test_0063: the native path is tested serially with a script standing in for gdb, and
the real test fails rather than skips on CI with no gdb. 10 passed.

CI reports the CPU, the OpenBLAS kernel and the OpenMP and BLAS settings per shard.

Refs #963

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

Review addressed at the new head.

  • M1, fixed. if: failure() || cancelled(), and timeout-minutes: 70 for headroom. The upload on a real cap cancellation has not been seen yet.
  • S1, fixed. Two native samples 5 s apart. The log says frames moved (a rank still working in C), or did not (not proof of a hang). The "stuck, not slow" line stays as the Python reading, and the guide says what it means.
  • S2, fixed. apt-get update first; the real test fails rather than skips when GITHUB_ACTIONS is set and gdb is missing.
  • S3, fixed. _native_frames and _collect_native_stacks are tested serially with a script standing in for gdb: refused, hung, undecodable, moved, no gdb. test_0063: 10 passed. The two workflow rows of your table stay untested off a runner.
  • S4, S5, S6, S7, S8, S9, fixed. errors="replace" and the thread records any exception; a timeout keeps its partial output; a refused attach quotes gdb's last line; duplicate import gone; guide corrected; PR_SET_PTRACER names the supervisor's pid, which on Yama scope 1 still attaches here.
  • N2, N3, N5, N7, N8, done. Pass the c_ulong; prctl after the handler; at most 8 gdbs at once; overwrite: true; the log quotes from the first MPI routine.
  • N1, noted. N4 and N6 are left: uploading a fixed path instead of the glob, deleting clean directories, and _read_dumps' pid choice are separate from this change.
  • Also added, as the hub asked: each shard logs lscpu, the OMP_ and OPENBLAS_ settings, OpenBLAS's chosen kernel and numpy.show_config()'s BLAS lines.

#963 is now reproduced off a runner, by forcing OpenBLAS kernels, so this PR's headline case is decided: that hang is a solve that does not finish, not a collective mismatch. Details are on #963.

Underworld development team with AI support from Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants