Skip to content

Tidy job-array output: member hostnames, one connect hint, errexit notice out of command logs (#897) - #903

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/897
Oct 15, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/897

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Three output problems from #897, each with its own root cause.

1. errexit preamble in every command log

Root cause: #707 (PR #721) added two printf lines at the top of the generated /tmp/spawn-command.sh. That warning exists because --command runs under set -e, set -uo pipefail does not clear it, and a script killed by errexit dies before the line that would say why. Because the lines were at the top of the script, they landed in every /var/log/spawn-command.log on every member, including when the command succeeded.

Fix (the safety intent stays): the command script no longer prints anything itself, and the command still runs under set -e. The root-side outcome block (the subshell that records CMD_RC) now appends the notice to the command log only when the command exits non-zero. It goes after the command's output, names the exit code, and keeps the #707 wording ("errexit is ON", "set -uo pipefail does NOT clear it", "set +e") plus the two common causes (SIGPIPE 141 and wait $pid). Root writes it, so the su/tee hazard that TestCommandAnnouncementDoesNotTee guards against does not apply. A one-line note also goes to cloud-init-output.log at boot. That log is not the command log. spored.log was not an option because spored is not running yet at that point in the bootstrap.

2. Hostname stays the EC2 default

Root cause: nothing in the repo ever set the hostname. There is no hostnamectl or /etc/hostname anywhere. So single instances were affected too, not only array and MPI members, even though --name's help says "sets Name tag, DNS, and hostname".

Fix: the Linux bootstrap reads the Name tag and sets the hostname. This happens after the job-array env is read and before --command starts.

  • The name is sanitized to an RFC 1123 label: lowercase [a-z0-9-], at most 63 characters. A name that sanitizes to nothing leaves the default.
  • For job-array members, the index is appended if the name does not already carry it. This covers an --instance-names template without {index}, which would otherwise give every member the same hostname, and Open MPI tells nodes apart by hostname.
  • hostnamectl, falling back to hostname, and /etc/hostname set the name.
  • /etc/cloud/cloud.cfg.d/99-spawn-hostname.cfg sets preserve_hostname: true, so cloud-init does not reset the name on stop/start.
  • /etc/hosts maps the name to the private IP, read from IMDS, so it resolves locally.
  • Every step is best-effort (|| true), because the bootstrap runs under set -e.
  • MPI is unaffected: /tmp/mpi-hostfile is built from peer private IPs (pkg/userdata/mpi.go), not hostnames. mpirun already worked with hostnames (ip-172-...) that did not match the hostfile entries.

3. One raw ssh line per member

Fix: renderJobArrayResult, which plain arrays and --mpi share, now prints one line under Management: • Connect: spawn connect arr-<index> (e.g. spawn connect arr-0). The pattern comes from the same Name template that formatInstanceName uses, so it follows --instance-names. spawn connect resolves members by Name tag (resolveInstance, case-insensitive). If the template has no {index}, every member has the same name, so the hint falls back to spawn connect <instance-id>. The single-instance summary already printed spawn connect <name>, so the two summaries now match.

Tests

Each new gate was run against a revert that compiles and failed:

  • TestSuccessfulCommandLogHasNoShellOptionPreamble runs the generated command script. A successful command's log must be exactly its own output. It fails if the printf preamble is restored.
  • TestFailedCommandLogNamesErrexit runs the real outcome block with the log redirected. With rc=141 the log must carry the spawn launch --command runs under bash -e, invisibly: 'set -uo pipefail' does not clear it, and the script dies before it can report why #707 wording. With rc=0 the log must stay empty. It fails if the notice is dropped or moved outside the failure branch.
  • TestCommandStillRunsUnderErrexit keeps the spawn launch --command runs under bash -e, invisibly: 'set -uo pipefail' does not clear it, and the script dies before it can report why #707 measurement: errexit survives set -uo pipefail.
  • TestBootstrapSetsHostnameFromName / TestBootstrapHostnameIsAValidLabel run the real hostname block under set -e, with aws, hostnamectl and curl stubbed and /etc redirected. Cases: arr-3, sim-0, a single instance, an invalid label, an index-less template, an index already present, no Name tag, and a long name. They fail if hostnamectl is removed or the distinct-hostname rule is disabled.
  • TestBootstrapSetsHostnameBeforeCommandStarts checks ordering: the hostname is set after JOB_ARRAY_INDEX is read and before --command runs.
  • TestJobArraySummaryPrintsOneConnectHint / TestJobArrayConnectHintFollowsTemplate. Both fail when the per-member ssh lines or the same-name hint come back.

make check passes except pkg/taskproto TestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker, which needs a Docker daemon. It fails the same way on unmodified main. Nested modules pass. No public-surface change: BuildLinuxBootstrap's signature is unchanged.

Needs a real launch to confirm (no instances were launched): hostnamectl on AL2023/Ubuntu, preserve_hostname across stop/start, and mpirun hostname printing member names.

Fixes #897

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_jobarray.go 86.66% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

…tice out of command logs (#897)

- --command: the #707 errexit notice no longer opens every
  /var/log/spawn-command.log. The root-side outcome block appends it only
  when the command exits non-zero (with the exit code), and the bootstrap
  notes it once in cloud-init-output.log. The command still runs under set -e.
- Bootstrap sets the OS hostname from the Name tag (sanitized to an RFC 1123
  label, index appended when an --instance-names template collides), maps it
  to the private IP in /etc/hosts, and sets preserve_hostname for cloud-init.
  Nothing set it before, for single instances or array/MPI members, despite
  --name's help. MPI hostfiles still use peer IPs.
- Job-array/MPI summary prints one 'spawn connect <pattern>' hint instead of a
  raw ssh -i line per member.

Fixes #897
@scttfrdmn
scttfrdmn merged commit fb458ad into main Oct 15, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/897 branch October 15, 2026 18:48
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.

Job arrays: per-member output is clunky (errexit preamble in every command log, EC2 hostnames, one raw ssh line per member)

1 participant