Skip to content

Signal completion from --mpi-command so --on-complete fires (#894) - #901

Merged
scttfrdmn merged 3 commits into
mainfrom
fix/894
Oct 15, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
fix/894

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Root cause

pkg/userdata/mpi.go ran mpirun as the bare last line of rank 0's appended MPI script. It did not tee to /var/log/spawn-command.log, did not record an exit code, and did not write /tmp/SPAWN_COMPLETE. spored fires --on-complete only when that file appears (pkg/agent checkCompletion), so no member ever acted, rank 0 included. The cohort rode the job out to idle or TTL. The --command path got these steps in #566/#614. The MPI path never did. The non-root ranks had no way to learn the job was over, and spored has no peer-completion channel.

Fix

On rank 0, --mpi-command now follows the --command contract:

  • Runs under set +e. The bootstrap this script is appended to runs under set -e, which is the A task whose command fails writes no completion record at all, so the box rides to TTL instead of self-terminating #566 failure class.
  • Pipes mpirun ... 2>&1 through tee -a /var/log/spawn-command.log, so spawn array logs <name> --index 0 works.
  • Records PIPESTATUS[0] (mpirun's status, not tee's) to /tmp/SPAWN_EXITCODE.
  • spawn_mpi_done writes the record (same JSON shape as --command, "source": "mpi") on every peer over the root SSH mesh mpirun itself depends on. Rank 0's key is already authorized on each peer, and the readiness loop has just proven each one accepts a BatchMode login, so this adds no new channel or IAM grant. Peers are signalled in parallel, waiting on their own PIDs only (not a bare wait, which would also wait on a concurrent --command subshell). Rank 0 writes its own record after the peers, so it cannot start terminating while peers are still unsignalled. Rank 0 skips its own address (hostname -I). Each member's spored then runs its own --on-complete, grace period and pre-stop hook.
  • The peer-SSH readiness timeout on rank 0 goes through the same path (exit code 1), so the reachable members stop instead of riding to TTL. Without --mpi-command that path is unchanged.

The --mpi-command flag help (and the regenerated docs-gen/launch.md) now states this. The rationale lives in a Go comment rather than the template, to keep user-data under the 16 KB cap.

Tests

pkg/userdata/mpi_completion_test.go runs rank 0's block of the rendered script under real bash with set -e, with stand-in mpirun/ssh/hostname/sleep. The ssh stand-in runs each remote command with that host's /tmp redirected, so each peer's files can be checked separately. The assertions come from the issue's Expected section and the --command flag contract:

  • TestMPICommandSignalsCompletion, for success (rc 0) and failure (rc 3): output (stdout and stderr) is in spawn-command.log, SPAWN_EXITCODE holds the rc, rank 0 has a SPAWN_COMPLETE with the right status and exit_code, and so does every peer.
  • TestMPIPeerReadinessFailureSignalsReachablePeers: a peer that never accepts SSH means mpirun does not run, rank 0 records failed/1, the reachable peer gets the failed record, and the cause is in spawn-command.log.

Each test was watched failing against reverts that compile: the original template (all fail), no peer signalling loop, $? instead of PIPESTATUS[0], and no tee.

mpi_peer_readiness_test.go now anchors on the readiness probe ("$PEER_IP" true) rather than the bare BatchMode=yes, which the completion hand-off also contains (CLAUDE.md gate rule 3). It also checks that the no-command failure record is still written.

make check passes except TestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker in pkg/taskproto, which fails identically on clean main (needs a Docker daemon). No public-surface change.

Not verified without AWS

No instances were launched. Not yet confirmed on hardware: peer hostname -I and the peers-file .ip (private IP) matching on a real cohort, and end-to-end cohort self-termination.

Fixes #894

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Rank 0 ran mpirun as the bare last line of the MPI user-data. Its output
reached only cloud-init-output.log, and nothing wrote /tmp/SPAWN_EXITCODE
or /tmp/SPAWN_COMPLETE, so spored's --on-complete never fired on any
member and the cohort rode the job out to idle or TTL.

The fix gives --mpi-command the --command contract on rank 0. Under set +e,
mpirun's output is teed to /var/log/spawn-command.log, and PIPESTATUS[0] is
recorded to /tmp/SPAWN_EXITCODE. Rank 0 then writes the same SPAWN_COMPLETE
record on every peer over the root SSH mesh mpirun already depends on, in
parallel, before writing its own. Each member's spored then runs its own
--on-complete. When rank 0 gives up waiting for peer SSH, it goes through
the same path, so the reachable members stop too.

The tests execute rank 0's block of the rendered script under set -e with
stand-in mpirun/ssh/hostname. They fail against the original template and
against each of three partial reverts: no peer signal, $? for PIPESTATUS,
and no tee.
The fake IMDS server writes its identity document through a JSON encoder
instead of concatenating it into a raw ResponseWriter write, and the MPI
harness runs rank 0's block from a script file rather than bash -c.
@scttfrdmn
scttfrdmn merged commit c3a1ee5 into main Oct 15, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/894 branch October 15, 2026 18:59
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 never signals completion, so --on-complete terminate never fires; and its output isn't where 'spawn array logs' looks

1 participant