Skip to content

fix(mpi): build the hostfile without jq; fail closed on any MPI setup failure (#1483) - #1485

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1483-mpi-jq-failclosed
Nov 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1483-mpi-jq-failclosed

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1483

What

  1. No jq. The MPI hostfile is now built with awk from the peers file, the JSON that spawn writes itself (provider.MarshalPeers). It takes each "ip" member in file order and works on the indented or the compact form. No dependency is added. Stock AL2 lacks jq, and the old line died with 127 on every AL2 member.
  2. Fail closed. An EXIT trap is set at the top of the MPI user data, before install. If the script exits non-zero before a completion record is written, the trap writes {"status": "failed", "exit_code": <status>, "source": "mpi-bootstrap"} to the completion file. That covers install, EFA, key setup, the peers-file wait, the hostfile, the --mpi-command files and the peer-SSH wait.
    • On rank 0 with --mpi-command, the record goes through spawn_mpi_done, so every peer in the hostfile gets it too. Any other member writes its own.
    • A clean exit writes nothing. A peer waits for rank 0's record, and without --mpi-command the --command workload writes its own.
    • The peers-file and peer-SSH timeouts now just exit 1 and the trap writes the record, so their source changes from mpi to mpi-bootstrap. mpi now means only mpirun's result.
    • The trap acts only in its own shell (BASHPID), then chains to the bootstrap's spawn_exit_guard, which it replaces as the EXIT trap.
    • /tmp/mpi-hostfile is removed at the start. An image of a rank-0 instance can carry the parent cohort's hostfile, and until ssh-keygen runs it also carries the parent's private key. Without the removal, an early failure could signal the parent cohort's members.

The published bootstrap body does not change. The MPI user data grows by 289 to 449 gzipped bytes, depending on the member; numbers below.

Gates (each watched failing against a compiling revert)

  • TestMPIUserDataToolsExistOnEveryBase parses every rendered shape (rank, command, install, EFA, gate, ppn) with mvdan/sh. It discovers every command, including those in script here-docs such as the rank wrapper, and drops builtins (from compgen) and the script's own functions. Each tool left must be a base tool of AL2/AL2023 or installed first.
    • Revert to the jq line: the MPI user data runs "jq", which is not a base tool....
    • TestMPIToolScanFindsJq proves the scan sees the old line.
  • TestMPIFailureWritesAFailedCompletion runs the whole rendered script in a sandbox. Paths are relocated, PATH holds only base tools plus stand-ins, and there is no jq. It forces each step to fail on rank 0 and rank 1 (install, peers file, hostfile, mpirun setup, key, peer readiness) and asserts a failed record with the step's exit code. When rank 0 fails after the hostfile, it also asserts the record reaches the peers.
    • Remove trap spawn_mpi_exit EXIT: all 11 cases fail (no SPAWN_COMPLETE after a failed MPI step).
    • Drop the trap's spawn_mpi_done routing: rank0/mpirun setup fails (never signalled peer).
  • TestMPISuccessWritesNoBootstrapRecord runs a healthy cohort with no jq on PATH and checks the hostfile, the gate and that no stray record is written.
    • Revert to jq: it exits 127 with an empty hostfile. With the trap in place, a reverted jq line now writes a failed mpi-bootstrap record, which is the fail-closed half covering the original bug.
  • TestMPIUserDataOnAL2Container runs the healthy cases and the hostfile and mpirun-setup failures in amazonlinux:2 under bash 4.2.46, and asserts that bash version. It skips unless docker and the image are present locally; it never pulls.
    • Both reverts fail it.
  • TestMPIHostfileReadsMarshalPeers is a contract test, not a revert gate. It ties the awk step to provider.MarshalPeers, in indented, compact and empty form.
  • The existing runRank0 tests (--mpi-command never signals completion, so --on-complete terminate never fires; and its output isn't where 'spawn array logs' looks #894/--mpi-command ignores a custom --completion-file, so --on-complete never fires (sibling of #1131) #1170) now run the whole script through the same sandbox instead of the rank-0 tail.

Sizes (gzip, MPI user data alone)

member before after
rank 0, --mpi-command, gate 3452 3741
rank 1, --mpi-command 3359 3656
rank 0, no command 2206 2556

The inline (dev) bare bootstrap is 7393 gzipped, against a budget of 8448.

Not covered / follow-ups

  • The non-MPI bootstrap has the same class of gap: a failure after spored starts but before the --command subshell launches writes no record. I filed it as A bootstrap failure after spored starts but before --command launches writes no completion record; the instance bills to TTL #1484 with a local repro. It isn't fixed here because detecting "the command was not launched" needs a marker in the published body. The gap also precedes this MPI trap on MPI members.
  • If the rank 0 instance itself dies, its peers still wait out their TTL or idle timeout.
  • The fragment installs only with yum. That is fine on AL2023, where yum is dnf. On Ubuntu without --skip-mpi-install it fails, now closed, with a failed record.

Live AL2 EC2 verification with a branch-built CLI is still to do.

… failure (#1483)

The MPI user data built its hostfile with jq, which stock AL2 lacks, so
every AL2 member died there (127) and, with no completion record, the
cohort billed to its TTL. Build it with awk from the peers file, and add
an EXIT trap that writes a failed SPAWN_COMPLETE (source mpi-bootstrap)
on any exit before a record, handing it to the peers from rank 0.
@scttfrdmn scttfrdmn added this to the v0.155.0 milestone Nov 2, 2026
@scttfrdmn scttfrdmn added bug Something isn't working area:mpi MPI / EFA / placement groups / HPC labels Nov 2, 2026
@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live-verified on EC2 (2026-11-02) with a CLI built from fed2b307 in account 942542972736, us-east-1, on 2× c7g.medium:

  • Stock AL2 (Open MPI 4.0.1), no harness: no jq; the awk hostfile is correct; rank-0/rank-1 both ran; SPAWN_COMPLETE completed/mpi on both nodes; terminated via on-complete.
  • Ubuntu 24.04, no apt path: fails closed. spawn: MPI setup failed (status 127 … yum install), and SPAWN_COMPLETE failed/mpi-bootstrap on both members. Terminated about 2.0 min after launch, against a 1 h TTL.
  • AL2023 (4.1.2): passes.

The first AL2 run failed on an unrelated race introduced by #1480: a peer's /etc/spawn/mpi-rank wasn't written yet. That's #1486. Even then this PR's fail-closed recorded failed/127 on both nodes and terminated them. Cost was about $0.05, and the leak check is clean.

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

Labels

area:mpi MPI / EFA / placement groups / HPC bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--mpi on an AL2 --ami dies at the jq hostfile step (jq not installed); no SPAWN_COMPLETE, so the cohort bills until TTL

1 participant