Skip to content

fix: --mpi-command honours a custom --completion-file (#1170) - #1184

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1170-mpi-completion-file
Oct 19, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1170-mpi-completion-file

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

--mpi-command ignored a custom --completion-file. spored watches the path in --completion-file (LaunchConfig.CompletionFile, carried by spawn:completion-file). The MPI script in pkg/userdata/mpi.go wrote all four of its completion records to a hardcoded /tmp/SPAWN_COMPLETE:

  • the peers-file timeout,
  • spawn_mpi_done's local record on rank 0,
  • spawn_mpi_done's ssh write to each peer,
  • the bare readiness-failure record (no --mpi-command).

With any other path, no member fired --on-complete, and the whole cohort billed until its TTL. This is the MPI twin of #1131 (fixed for --command in #1164). The fix uses the same approach.

  • MPIConfig.CompletionFile is new. The CLI passes instanceConfig.CompletionFile in buildJobArrayMemberConfig. Empty means /tmp/SPAWN_COMPLETE, so the default is unchanged.
  • The path is quoted in Go with security.ShellQuote and handed to the template already quoted, so the template never interpolates a raw path.
  • Each local write runs mkdir -p "$(dirname -- <path>)" || true first. Without it, a custom path in a directory that doesn't exist yet would fail the write under set -e, and the leak would come back.
  • Peer write. It was ssh -n … "$ip" "echo '$rec' > /tmp/SPAWN_COMPLETE". It is now printf '%s\n' "$rec" | ssh … "$ip" <cmd>. <cmd> is the fixed command mkdir -p "$(dirname -- 'P')" || true; cat > 'P', quoted once for the peer's shell and once more for rank 0's. The record now goes over stdin, so neither shell parses it again. -n is dropped because stdin is now the record.

Gates (each watched failing against a revert that compiles)

pkg/userdata/mpi_completion_file_test.go:

  • Discovers every write. It finds every echo <record> > <target>, where the record is a literal record with "source": "mpi" or $rec, quoted either way. It also finds every ssh hand-off of $rec, with continuation lines joined first. It fails if it finds no write.
  • Checks the targets. With path /tmp/spawn out/it's $HOME/done, there must be exactly 2 local writes plus 1 peer write with --mpi-command, and 2 plus 0 without. Every local target must be exactly ShellQuote(path). /tmp/SPAWN_COMPLETE must appear nowhere in the script. With no path set, the default is still '/tmp/SPAWN_COMPLETE'.
  • Quoting, executed. The script must pass bash -n. Every discovered local write is then run under bash and must land at exactly <tmp>/new dir/it's $HOME done. The peer write is run with a stub ssh that captures the remote command exactly as ssh would send it. That command is then run the way the peer's shell would run it (bash -c, record on stdin), and the record must land at the same path.
  • End to end. runRank0With runs rank 0's block with stub mpirun, ssh and hostname, and a custom path. Rank 0 and both peers must get the record at the custom path, and none at the default.

cmd/launch_mpi_completion_file_test.go: buildJobArrayMemberConfig with CompletionFile: /data/done must write '/data/done' on members 0 and 1, and never /tmp/SPAWN_COMPLETE.

Reverts tried. All compile (go vet clean) and all fail:

revert fails
generator ignores CompletionFile 3 userdata gates + CLI gate
peer write hardcoded back to "echo '$rec' > /tmp/SPAWN_COMPLETE" 4 userdata gates + CLI gate
ShellQuote dropped 5 userdata tests + CLI gate
CLI passes "" CLI gate (pkg tests pass, as expected)
remote command quoted only once quoting, custom-path end-to-end, and the existing #894 completion tests
only the peers-file-timeout write hardcoded discovery, default and quoting gates + CLI gate

TestMPIWaitsForPeerSSHBeforeMpirun now expects the quoted > '/tmp/SPAWN_COMPLETE'.

Checks

  • GOTOOLCHAIN=go1.26.9 make check: fmt, vet, check-goos, staticcheck, hermetic tests, nested modules and tidy all pass. check-build-tags fails, but its output is identical to unmodified origin/main on this machine (diffed with the worktree path normalised; it's the /private/tmp path issue). So it's local-only.
  • make check-docs: clean, no help text changed.
  • semgrep scan --config=auto --error .: clean.
  • pkg/userdata is not in api/public-surface.txt, so there is nothing to regenerate.

Not covered

  • Not reproduced on an instance, and no AWS calls were made. The remote quoting is proven by running the captured remote command under bash. A real peer runs root's login shell (bash on AL2023), which is assumed, not tested.
  • The MPI script grows by 204 bytes with the default path, measured: 6050 to 6254 for a 4-node --mpi-command render. I did not measure it against the largest real combined bootstrap, which shares the 16 KB user-data cap.

Fixes #1170

The MPI script wrote every completion record, on rank 0 and over ssh on
each peer, to a hardcoded /tmp/SPAWN_COMPLETE while spored watched the
--completion-file path, so with a custom path no member fired
--on-complete and the cohort billed to TTL. MPIConfig.CompletionFile now
carries the path; every write renders it shell-quoted (twice for the
peer's remote shell, with the record piped on stdin) after a mkdir of
its directory. The default is unchanged.

Fixes #1170
@scttfrdmn scttfrdmn added this to the v0.135.2 milestone Oct 19, 2026
@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/userdata/mpi.go 90.90% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 8e8ef44 into main Oct 19, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1170-mpi-completion-file branch October 19, 2026 07:52
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 ignores a custom --completion-file, so --on-complete never fires (sibling of #1131)

1 participant