Skip to content

fix(bootstrap): make --command wait for storage and MPI setup - #678

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/668-664-command-readiness
Oct 4, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/668-664-command-readiness

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #668. Fixes #664.

Done together as one mechanism, as you suggested: one readiness barrier, two producers.

Confirmed as reported

--command is launched from linuxBootstrapBody, which BuildLinuxBootstrap concatenates at :178 — and StorageScript is appended at :203, after. So the workload really does run before its mounts exist, which is your df: /efs: No such file or directory. #166 fixed this ordering for --user-data (appended at :223, after storage); --command lives inside the static body and could not be moved the same way.

#664 is the same shape one step further out: the MPI script is appended to the whole finished bootstrap by buildJobArrayMemberConfig, so the workload starts before mpirun has a hostfile or a peer.

I went with your sentinel suggestion rather than reordering. Reordering would have moved the storage script above the body it depends on (LOCAL_USERNAME, REGION, INSTANCE_ID) and changed which set -e/set +e region it runs under — a bigger behavioural change than the bug.

How it works

The bootstrap writes /run/spawn/required-gates near the top, each producer writes ok or failed:<reason> to its own sentinel, and --command waits for all of them before starting. /run is tmpfs, so gates are per-boot by construction.

Gates are declared at build time, which is forced rather than chosen: the list is read when the workload begins waiting, so a gate appended at the end of the script text would be announced after the wait had already been skipped. That is why MPIReadyGate is declared by buildUserData even though the MPI script that signals it is appended later.

Three decisions worth your eye

The storage gate verifies the mount instead of trusting an exit code. I started with STORAGE_RC=$? and then checked what the storage script actually ends with — usually echo "... " >> /etc/fstab, which returns 0 whether or not anything mounted. There is no status worth reading, so the gate greps /proc/mounts for the mount points the launch declared. Only EFS and FSx are required; attached EBS volumes mount with nofail by design and must not strand a workload that never referenced them.

The wait is inside the backgrounded subshell. Waiting outside it would block cloud-init, so spored would never start and TTL/idle/cost enforcement would stay unarmed for up to 600s on every launch — the spored#65 failure, and strictly worse than the bug being fixed. There is a test asserting the wait's offset falls between the ( and the ) &.

The MPI gate fires before the rank-0 mpirun, not after. That mpirun is the job and can run for hours; gating on its completion would make --command wait out the entire run, which is indistinguishable from a hang. It fires once the hostfile is built, and reports failed for an empty hostfile — no peers resolved means a cluster of one, which should not read as ready.

Failure behaviour, per your last paragraph

An unmet prerequisite now fails loudly in /var/log/spawn-command.log (not just cloud-init-output.log), says the command never started — "failed" alone reads as a workload that ran and failed, sending you to debug the wrong thing — and writes a failed SPAWN_COMPLETE so --on-complete still fires rather than the instance billing to TTL doing nothing.

It fails rather than proceeding, deliberately: a workload started without its mounts does not fail cleanly, it writes to the wrong place or produces silently wrong output.

The risk I was most careful about

A gate declared with no producer would stall every launch for 600s and then fail one that works today. So gates are declared only where a producer is certain, and readyGatesForLaunch is a tiny pure function with a test pinning both directions. I checked spawn array retry specifically — it is plain-array only ("MPI is all-or-nothing"), so a persisted base user-data can never carry an MPI gate into a retry that won't signal it.

TestMPIGateDeclaredAndSignalled is the interlock: it asserts both packages agree on the same path, since two tests that each pass alone would not catch a rename on one side.

Verification

Every new gate confirmed to fail when its half is reverted — I did this in two passes, removing the declaration side and then the body's wait loop, because the tests split across those:

  • declaration removed → TestCommandWaitsForStorage, TestMPIGateIsDeclared fail
  • body wait loop removed → TestGateWaitIsInsideTheBackgroundedSubshell ("no wait loop found"), TestGateFailureIsReportedInCommandLog, TestGateTimeoutMatchesConstant fail

Also avoided a known trap: the mount-point list is interpolated into a shell for loop, and security.ShellEscape is strconv.Quote — Go escaping inside double quotes, where $VAR and $(...) still expand. That is #660, still open. This uses real single-quote escaping, with a test for $HOME, $(id), backticks and embedded quotes.

Gates clean locally before pushing: gofmt -l empty, go vet ./..., go test -short ./... (0 failures), make check-docs, changelog gate, semgrep scan --config=auto --error . → 0 findings.

Not verified on hardware, and this is the one where that matters most — it is generated shell, and the tests assert the text of the script, not its behaviour under cloud-init. The ordering and quoting are checkable statically; "the gate actually releases when the EFS mount lands" is not. A single --efs-id + --command "df -h /efs" launch on the smallest instance would confirm the whole path for cents, and a 2-node MPI run would confirm #664. Happy to run the EFS one if you want it before the release tag.

--command is launched from linuxBootstrapBody, concatenated BEFORE the
storage script and before anything a caller appends later, so the
workload ran without its mounts (df: /efs: No such file or directory)
and MPI members started before mpirun had a hostfile or a peer.

Adds a readiness barrier: the bootstrap declares the gates, each
producer signals its own, and --command waits before starting. The
storage gate verifies /proc/mounts rather than trusting an exit code,
since the storage script ends in `echo >> /etc/fstab` and always
succeeds. Failures surface in /var/log/spawn-command.log and write a
failed completion record so --on-complete still fires.

The wait is inside the backgrounded subshell (waiting outside blocks
cloud-init and leaves spored unarmed — spored#65), and the MPI gate
fires before the rank-0 mpirun rather than after it.

Fixes #668
Fixes #664
@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.90909% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_config.go 30.76% 9 Missing ⚠️
cmd/launch_single.go 0.00% 4 Missing ⚠️
cmd/launch_batchqueue.go 0.00% 1 Missing ⚠️
cmd/launch_sweep.go 0.00% 1 Missing ⚠️
cmd/resume.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

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

Labels

None yet

Projects

None yet

1 participant