Skip to content

fix(mpi): rank 0 waits for every member's MPI setup, not just its SSH, before mpirun (#1486) - #1489

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1486-mpi-peer-ready
Nov 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1486-mpi-peer-ready

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1486

The race

Rank 0's pre-mpirun gate (#752) tested only that each member accepted a BatchMode SSH login. Rank 0's cluster key reaches a peer's authorized_keys over SSM from the control plane, independently of (and usually before) the peer's own bootstrap reaching cat > /etc/spawn/mpi-rank. So mpirun could exec the #1480 rank wrapper on a peer that had not written it yet: bash: /etc/spawn/mpi-rank: No such file or directory, exit 127, a failed job on a healthy cohort (0.9 s late on AL2 live, 0.14 s from it on AL2023).

Design: one marker, written last, holding the cohort ID

  • Every member writes /etc/spawn/mpi-node-ready as the last step of its MPI script outside the rank-0 block. That is after the install, EFA, mpi.sh, the key setup, the hostfile and the --mpi-command files (mpi-command, mpi-rank). One marker covers everything a rank reads on that member, including orted from the install and anything a later change adds before it. I chose this over test -f on each file because a per-file list has to be kept in sync by hand.
  • Rank 0's probe is now grep -qxF <job array ID> /etc/spawn/mpi-node-ready, over the same BatchMode SSH, so it still proves sshd and authorized_keys too. It checks for the ID rather than doing a bare test -f because an image of a member carries its parent cohort's marker, mpi-rank and mpi-command, and the SSM key can arrive before this script's rm -f of the marker (or spored's ami create: per-instance spored/plugin state (plugins.json, job-array env, peer files) is still baked into images #1241 sweep) runs. The marker is also added to instancestate.Paths, which TestEveryWrittenStatePathIsCovered requires.
  • Rank 0 probes itself too. It has already written its own marker by then.
  • The wait keeps its 600 s bound and its exit 1, which spawn_mpi_exit records as mpi-bootstrap on every reachable member (fix(mpi): build the hostfile without jq; fail closed on any MPI setup failure (#1483) #1485). The messages now read all peers ready after Ns and N peer(s) not ready (no SSH, or MPI setup unfinished) after Ns. scripts/hardware-smoke.sh's echo was updated to match. It reads the seconds file, not the line.

Gates

TestMPIRankZeroWaitsForEveryMemberToFinishItsMPISetup runs rank 0's whole rendered script in the sandbox. It counts logins and never measures time:

  • The sandbox ssh stub now runs each peer's own rendered MPI script (its rank, same cohort, relocated under hosts/<ip>/) at a chosen login. The peer accepts SSH from login 1, but its files appear only at login 3.
  • The mpirun stand-in now runs the program it was given once per hostfile line, on that member's files. A missing mpi-rank fails with bash's own 127, as on EC2.
  • The test asserts: exactly one mpirun, every rank's command ran on its own member, exactly 3 probes of the late peer, and a completed record.
  • It has three subtests: plain, a peer carrying a parent cohort's marker and mpi-rank, and the same run in amazonlinux:2 (bash 4.2, real AL2 coreutils/awk/grep; skips without docker/image). All three ran here.

TestMPINodeReadyMarkerFollowsEveryFileARankReads works from discovery, not a list. It takes the program on the rendered mpirun line (bash /etc/spawn/mpi-rank), then, transitively, each file that a here-doc body this script writes refers to and that the script also writes. Today that discovers {/etc/spawn/mpi-rank, /etc/spawn/mpi-command}. It requires each to be written before the marker, the marker to be followed only by the rank-0 block (which ends the script), and rank 0's probe to grep this cohort's ID in that file. It covers plain, --efa and --skip-mpi-install.

Every existing sandbox test now also runs real peer scripts and real rank wrappers, and all of them pass.

Watched failing against compiling reverts (template-only edits, go vet clean)

  1. Probe back to "$PEER_IP" true: the race test fails on the peer with bash: …/hosts/10.0.0.3/etc/spawn/mpi-rank: No such file or directory, gives no hosts/10.0.0.3/tmp/rank-ran, probed 10.0.0.3 0 times, want 3, and a failed record (the live --mpi-command: rank 0 can start mpirun before a peer has written /etc/spawn/mpi-rank (exit 127); the SSH readiness gate doesn't cover it #1486 failure, reproduced).
  2. Probe as test -f (ignores the ID): the stale-marker subtest fails with probed 10.0.0.3 1 times, want 3 and the late peer's rank never ran.
  3. Marker written before the --mpi-command files: the static test fails with /etc/spawn/mpi-rank … is written after /etc/spawn/mpi-node-ready, the same for mpi-command, and a step follows … outside the rank-0 block ("mkdir -p /etc/spawn").

Sizes

Measured with the live #1486 shape (job array ID l1485-al2-20261101-e57d9546, --mpi-command, ready gate):

  • MPI user data: 8487 → 8797 raw, 3765 → 3887 gzip (+122).
  • With --efa: 3961 → 4083 gzip.

The published bootstrap body does not change.

Checks

  • make check passed (run from /private/tmp).
  • make lint: 0 issues in all 10 modules.
  • semgrep scan --config=auto --error .: 0 findings.
  • go test ./pkg/userdata ./pkg/instancestate ./cmd passed, including the AL2 container runs.

Live check before merge (branch-built CLI)

  • Race: a 2–3 node --mpi-command run on stock AL2 (the --mpi-command: rank 0 can start mpirun before a peer has written /etc/spawn/mpi-rank (exit 127); the SSH readiness gate doesn't cover it #1486 repro) and on AL2023. Expect spawn: all peers ready after Ns in rank 0's cloud-init-output.log, and /etc/spawn/mpi-node-ready on every member holding the job array ID. On each peer, its mtime should be at or after its mpi-rank, and rank 0's mpirun should start after the last peer's marker. Both members should end completed and terminate. Repeat a few times, since the race was intermittent; more peers or --efa widen the window.
  • Failure path: optionally, make a peer slow (e.g. --mpi-command with a peer that cannot install) and confirm rank 0 fails closed at 600 s with not ready (no SSH, or MPI setup unfinished) and an mpi-bootstrap record on every member, then terminates.

@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 a local merge of #1489 (e4132a9c) and #1492 (ff9a9639), in account 942542972736, us-east-1, on c7g.medium:

Base Open MPI Clusters Result
AL2 4.0.1 3× 2-node + 1× 3-node PASS: all completed/mpi, 0 No such file
AL2023 4.1.2 1× 2-node PASS
Ubuntu 24.04 4.1.6 (/usr/bin/mpirun) 1× 2-node PASS: apt 6+9 s, 0 lock retries; key-owner holds the instance ID
Ubuntu 22.04 4.1.2 1× 2-node PASS: apt 7 s, 0 retries

The 3-node AL2 run caught #1486 live. Rank 0's SSH probe of rank 2 was accepted at 04:58:46, but rank 2's mpi-rank and marker are stamped 04:58:47.476. The old SSH-only gate would have started mpirun about 1 s early. The new gate logged all peers ready after 5s, and mpirun started after the last marker. Every marker holds the cohort ID, and its mtime equals its mpi-rank mtime.

Ubuntu confirmed #1490, which is wider than filed: there's no ec2-metadata and no aws CLI. Evidence is on #1490.

Cost was about $0.05 for 24 instances. The leak check is clean, and I confirmed it independently.

…, before mpirun (#1486)

Rank 0's #752 gate tested only that each member accepted a BatchMode SSH
login. The cluster key reaches a peer over SSM before the peer's own
bootstrap writes /etc/spawn/mpi-rank, so mpirun could exec it on a peer
that did not have it yet (exit 127; 0.9 s late on AL2 live).

Every member now writes /etc/spawn/mpi-node-ready, holding the job array
ID, as the last step of its MPI setup, and rank 0's probe greps for this
cohort's ID over the same SSH login. The 600 s bound and the
mpi-bootstrap failure record are unchanged.

The sandbox now runs each peer's own rendered script at a chosen login
and an mpirun stand-in that runs each rank's program on that member's
files, so the race is reproduced by count, not time.

Fixes #1486
@scttfrdmn
scttfrdmn force-pushed the fix/1486-mpi-peer-ready branch from e4132a9 to fbc800b Compare November 2, 2026 05:09
@scttfrdmn
scttfrdmn merged commit e1ecc2f into main Nov 2, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1486-mpi-peer-ready branch November 2, 2026 05:32
@scttfrdmn scttfrdmn mentioned this pull request Nov 2, 2026
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.

--mpi-command: rank 0 can start mpirun before a peer has written /etc/spawn/mpi-rank (exit 127); the SSH readiness gate doesn't cover it

1 participant