Repository navigation
fix(mpi): wait for peer SSH before mpirun instead of sleeping ten seconds (#752) - #758
Conversation
…onds The generated MPI script already waited — bounded at 600s, with a named SPAWN_COMPLETE failure — for /etc/spawn/job-array-peers.json, then built /tmp/mpi-hostfile. It then ran a bare `sleep 10` before mpirun, with no comment explaining it. The peers file existing means the CONTROLLER resolved every peer's IP. It says nothing about whether a peer's sshd is accepting connections, or whether rank 0's public key has reached that peer's /root/.ssh/authorized_keys — which pkg/mpicohort/assembler.go is what distributes, and which mpirun needs because it SSHes to every host in the hostfile. So the pad was a race, and one that WORSENS with cohort size: a constant wait against a growing number of peers that must all be ready. scripts/hardware-sensitive.txt already records "the 16-node assembly flake" as live-only; this is a candidate cause, still unproven. Replaced with a bounded poll requiring a successful non-interactive SSH to every host in the hostfile. BatchMode=yes is load-bearing: it tests sshd AND authorized_keys together, where `nc -z … 22` would pass while MPI still failed. Capped and named-failing like the peers-file wait above it, so a broken peer yields a cause rather than an opaque mpirun error about an unreachable host. Also replaces the smoke's `sleep 45 # let mpirun finish` with a poll. That constant became a worse bet with this change — rank 0's mpirun no longer starts at a fixed offset, and the needed wait grows with NODES while 45 does not. The comment right below it already recorded that this assertion had mis-reported once on a healthy cluster. Hardware: NODES=4 scripts/hardware-smoke.sh — 4 nodes, 8 ranks, 4/4 assertions passed, clean teardown with no leaked instances, placement groups or security groups. The new mpirun poll found all 4 nodes in 10s where the constant would have spent 45. Two self-inflicted bugs on the way, both worth recording: - My comment inside the template contained BACKTICKS around the old `sleep 10`, which terminate a Go raw string literal. The package stopped compiling with "expected ';', found sleep". Never put backticks in a template comment. - My ordering assertion compared against the first occurrence of "mpirun", which is a mention in the template's own comments at index 66 — not the invocation. It failed against correct code until anchored on "mpirun --mca". Gate verified to fail on revert: restoring the pad trips both the "sleep 10 is still in the rendered script" and "does not use BatchMode=yes" assertions.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Read the 'all peers accepted SSH after Ns' line over SSM while rank 0 is still alive. It does NOT survive teardown: the MPI script's stdout lands in cloud-init-output.log, and only some cloud-init output reaches the serial console — the mpirun result does, these echoes do not. A first attempt to recover it post-mortem from get-console-output returned nothing for all four instances, which is why this is read in-run. A measurement, not an assertion: 0s is a legitimate outcome on a fast cohort. What it tells you is whether a given run exercised the poll or merely found every peer already ready — the difference between proving the fix works and proving it does not regress. The 4-node run that validated #758 could not answer that, and this is why.
Hardware: 4 nodes pass, but one claim is still unmeasuredRun twice, both clean. The smoke's new What this proves, and what it does notProves: ordering is right (the readiness wait reads the hostfile and gates Does not prove: that the readiness poll absorbed a real delay rather than I tried to recover the duration two ways and both failed, which is worth
Rather than keep guessing at the cause, the readiness loop now also writes its I have not spent another run to collect the number. The poll's logic is Also confirmed while checking this
|
The 4-node hardware run reported 'line not found' when looking for the readiness echo in /var/log/cloud-init-output.log — while mpirun's OWN output was present in the same log, and the smoke's node-count assertion passed off it. So stdout from this appended script does not reliably reach that log, and the measurement was unobservable. Rather than guess why, the readiness loop now also writes its elapsed seconds to /var/log/spawn-mpi-peer-wait-seconds, and the smoke reads that file. Presence proves the poll ran; contents give the duration. No behaviour change to the fix itself — this makes the hardware validation able to answer the one question the first run could not: did the poll absorb a real delay, or find every peer already ready?
1782a9a to
dc2bf86
Compare
Both of `spawn logs`' paths are outside Substrate's surface, so the gate gets a deferred entry rather than a Tier 0 test: - the live path is an SSH/SSM tail of /var/log/spawn-command.log on a booted instance (Tier 2, same as connect/status's SSH path); - the terminated path is ec2:GetConsoleOutput, which Substrate does not model at all — there is no reference to the action anywhere in the emulator, so it can only answer with an unimplemented-action error. A stub would not help either: it would return no serial console, which is the entire artifact being read. Verified against real hardware instead (#736/#758): spored's framed tail appeared in the console ~4.5 min after termination and was still readable 12h later. The pure logic is unit-tested — cache path/TTL/pruning and the recently-gone selection in cmd/logs_test.go, the marker framing and extraction in pkg/taskproto/consolemarkers_test.go.
…761) * feat(cmd): spawn logs — a spore's log, including after it terminated You asked whether spawn could fetch the console output itself rather than making the user run get-console-output by hand. This is that, as a command. While the instance is alive it tails the log over SSH-or-SSM — the same path `spawn array logs` uses, reusing runArrayMemberCommand and arrayLogPath, and sharing its --which/--lines flags so the two behave alike. A new top-level verb rather than stretching `array logs`, whose name, --index flag and error messages are all job-array-shaped. Once the instance is gone, tailing is impossible: the log died with it. So it reads back the tail spored wrote to the serial console before terminating (#736). The framing spored writes turns out to be a PARSED DELIMITER, not decoration — so the output is the 50 relevant lines, not the 40 KB of UEFI and cloud-init around them. --console prints the whole dump, for failures that happened before the workload started. An absent log is reported as one of TWO things, because they send the user in opposite directions: - terminated <6 min ago -> "try again shortly" (the capture takes ~4-5 minutes to appear); - older -> "spored only writes this when the workload FAILED". Distinguished by the termination time EC2 embeds in StateTransitionReason. When that is absent the hint is withheld rather than guessed: a confidently wrong "try again shortly" is worse than no hint. I made exactly that mistake while probing #736 — read at three minutes, saw an empty dump, and briefly concluded the whole approach did not work. Cache: ~/.spawn/cache/console, 7 days, pruned on every invocation so it cannot outlive its own policy without a daemon. Seven days rather than matching the existing 6h indexCacheTTL — a diagnostic does not go stale the way a package index does, and 6h would expire it BEFORE ITS SOURCE: measured, AWS served console output for instances DescribeInstances had entirely forgotten more than twelve hours later. An empty dump is never cached, so "no log yet" is not pinned for a week. Supporting pieces: - pkg/aws.GetConsoleOutput, which did not exist. The SDK returns Output BASE64-ENCODED and does not decode it — "the tool decodes the output for you" refers to the AWS CLI. My first draft assumed the CLI's behaviour carried over and would have returned base64 garbage; checked against the SDK's own doc comment. - The console markers move to pkg/taskproto, the package the writer (pkg/agent) and reader (cmd/) already share, since cmd does not import pkg/agent. Duplicated literals are how a reader and writer drift apart silently: the block would still be written and simply never found. - selectRecentlyGone split out of #747's formatRecentlyGone, so this reuses the selection and not just its wording. Gates verified to fail on revert: a 6h TTL (shorter than measured source retention), and pruning disabled. * test(e2e): classify logs in the Tier 0 coverage gate Both of `spawn logs`' paths are outside Substrate's surface, so the gate gets a deferred entry rather than a Tier 0 test: - the live path is an SSH/SSM tail of /var/log/spawn-command.log on a booted instance (Tier 2, same as connect/status's SSH path); - the terminated path is ec2:GetConsoleOutput, which Substrate does not model at all — there is no reference to the action anywhere in the emulator, so it can only answer with an unimplemented-action error. A stub would not help either: it would return no serial console, which is the entire artifact being read. Verified against real hardware instead (#736/#758): spored's framed tail appeared in the console ~4.5 min after termination and was still readable 12h later. The pure logic is unit-tested — cache path/TTL/pruning and the recently-gone selection in cmd/logs_test.go, the marker framing and extraction in pkg/taskproto/consolemarkers_test.go.
Promotes [Unreleased] to [0.126.0] and adds the compare link. MINOR, not PATCH, because this release contains a breaking change to a package other repos compile against: pkg/taskproto's three script generators now take a WrapperOptions struct and return an error (#765/#764). Pre-1.0 the project's rule is that a breaking change bumps MINOR. Also in this release: the cross-repo API surface gate that will report the next such change before it ships (#763/#679), `spawn logs` (#761), the spored console log tail it reads (#759), the MPI peer-SSH readiness poll (#758), and the remaining sleep-audit fixes plus the creation-stamp/orphan reaper work (#752, #755, #756, #757, #762). Release guard passed: both binaries report 0.126.0 for tag v0.126.0.
The last of #752's findings that needed a decision rather than a mechanical fix,
and the only one requiring real multi-node hardware.
Why the pad was wrong
The generated MPI script already waits — bounded at 600s, with a named
SPAWN_COMPLETEfailure — for/etc/spawn/job-array-peers.json, then builds/tmp/mpi-hostfile. It then ran a baresleep 10beforempirun, with nocomment.
The peers file existing means the controller resolved every peer's IP. It
says nothing about whether a peer's
sshdis accepting connections, or whetherrank 0's public key has reached that peer's
/root/.ssh/authorized_keys— whichpkg/mpicohort/assembler.go:168-184is what actually distributes(
rankZeroPubKeyPath→authorizedKeysPath), and whichmpirunneeds, becauseit SSHes to every host in the hostfile.
Nothing else between the hostfile write and
mpirunneeds time, so peer SSHreadiness was the only candidate — which is how this went from "a question for
the maintainer" to determinable from the code.
It is a race that worsens with cohort size: a constant wait against a growing
number of peers that must all be ready.
scripts/hardware-sensitive.txt:15already records "the 16-node assembly flake" as live-only; this is a candidate
cause, still unproven.
The fix
A bounded poll requiring a successful non-interactive SSH to every host in
the hostfile.
BatchMode=yesis load-bearing: it testssshdandauthorized_keystogether, wherenc -z … 22would pass while MPI still failed.Capped at 600s with a
SPAWN_COMPLETEfailure record — the same discipline asthe peers-file wait 30 lines above — so a broken peer produces a named cause
instead of an opaque
mpirunerror about an unreachable host. And a healthycohort starts as soon as its peers are ready rather than always paying ten
seconds.
Also in scope: the smoke's own constant
scripts/hardware-smoke.shslept a flat45s # let mpirun finishbeforegrepping rank 0's log for the per-node lines. This change makes that a worse bet
— rank 0's
mpirunno longer starts at a fixed offset, and the needed wait growswith
NODESwhile 45 does not. The comment immediately below it already recordedthat this assertion had mis-reported once on a healthy cluster, so making it
more time-dependent was the wrong trade.
Now polls until the rank count reaches
NODES, reporting how long it took.Hardware verification
Four nodes so the ten-second pad is no longer plausibly sufficient. The new
mpirunpoll found all four in 10s, where the old constant spent 45 — so thesmoke is now both more reliable and faster.
Cost ≈ $0.10.
pkg/userdata/is in the hardware-sensitive manifest preciselybecause generated shell cannot be proven by text assertions, which is why this
PR waited on a real run.
Two self-inflicted bugs, both worth recording
Backticks inside a Go raw string. My explanatory comment wrote the old pad as
`sleep 10`— and a backtick terminates a Go raw string literal. The packagestopped compiling with
expected ';', found sleep. This is a trap I have hitbefore in this codebase and walked into again; the rule is simply never to put
backticks in a template comment.
My ordering assertion failed against correct code. It compared against the
first occurrence of
"mpirun", which is a mention in the template's owncomments at index 66 — not the invocation. Anchored on
"mpirun --mca".Gate
Restoring the pad trips both assertions:
the bare sleep 10 pad is still in the rendered scriptanddoes not use ssh BatchMode=yes. Verified.gofmt,go vet ./...,go test -short ./...,bash -n,make check-docs,changelog gate,
semgrep(0 findings).One thing I could not confirm
Whether the readiness poll actually waited on this run, or found every peer
ready immediately. The 4-node cohort assembled fast enough that it may have been
~0s — in which case the run proves no regression and correct ordering, but not
that the poll absorbs a real delay. I am reading rank 0's console output for the
all peers accepted SSH after Nsline to find out, and will post it here; thepost-termination console capture takes ~5 minutes to populate (measured while
probing #736).