Skip to content

fix(mpi): wait for peer SSH before mpirun instead of sleeping ten seconds (#752) - #758

Merged
scttfrdmn merged 3 commits into
mainfrom
fix/mpi-peer-readiness-poll
Oct 8, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
fix/mpi-peer-readiness-poll

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

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_COMPLETE failure — for /etc/spawn/job-array-peers.json, then builds
/tmp/mpi-hostfile. It then ran a bare sleep 10 before mpirun, with no
comment
.

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:168-184 is what actually distributes
(rankZeroPubKeyPath → authorizedKeysPath), and which mpirun needs, because
it SSHes to every host in the hostfile.

Nothing else between the hostfile write and mpirun needs time, so peer SSH
readiness 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:15
already 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=yes is load-bearing: it tests sshd and
authorized_keys together, where nc -z … 22 would pass while MPI still failed.

Capped at 600s with a SPAWN_COMPLETE failure record — the same discipline as
the peers-file wait 30 lines above — so a broken peer produces a named cause
instead of an opaque mpirun error about an unreachable host. And a healthy
cohort 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.sh slept a flat 45s # let mpirun finish before
grepping rank 0's log for the per-node lines. This change makes that a worse bet
— rank 0's mpirun no longer starts at a fixed offset, and the needed wait grows
with NODES while 45 does not. The comment immediately below it already recorded
that 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

=== MPI cohort: 4 x c6i.large in us-east-1
  ✅ cohort launched and assembled (#684: --mpi works end to end)
     (all 4 nodes reported after 10s)
  ✅ mpirun spread across all 4 nodes (8 ranks)
  ✅ cloud-init completed (no aborted scripts-user module)
  ✅ --mpi-command preserved its arguments (#660)
=== Result: 4 passed, 0 failed
=== Cleanup
  terminated ×4 · deleted placement group · deleted SG
  ✅ no instances left behind
  ✅ no placement groups or security groups left behind

Four nodes so the ten-second pad is no longer plausibly sufficient. The new
mpirun poll found all four in 10s, where the old constant spent 45 — so the
smoke is now both more reliable and faster.

Cost ≈ $0.10. pkg/userdata/ is in the hardware-sensitive manifest precisely
because 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 package
stopped compiling with expected ';', found sleep. This is a trap I have hit
before 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 own
comments
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 script and does 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 Ns line to find out, and will post it here; the
post-termination console capture takes ~5 minutes to populate (measured while
probing #736).

…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

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

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.
@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Hardware: 4 nodes pass, but one claim is still unmeasured

=== MPI cohort: 4 x c6i.large in us-east-1
  ✅ cohort launched and assembled    (all 4 nodes reported after 10s)
  ✅ mpirun spread across all 4 nodes (8 ranks)
  ✅ cloud-init completed             ✅ --mpi-command preserved its arguments
=== 4 passed, 0 failed
  ✅ no instances left behind · no placement groups or security groups left behind

Run twice, both clean. The smoke's new mpirun poll found all four nodes in
10s, where the old sleep 45 spent 45 — so it is both more reliable and
faster.

What this proves, and what it does not

Proves: ordering is right (the readiness wait reads the hostfile and gates
mpirun), a 4-node cohort assembles with 8 ranks, nothing regressed, and teardown
is clean.

Does not prove: that the readiness poll absorbed a real delay rather than
finding every peer already ready. On a healthy 4-node cohort the wait may well
have been 0s, in which case the run demonstrates no-regression rather than the fix
doing work.

I tried to recover the duration two ways and both failed, which is worth
recording:

  1. Post-mortem from get-console-output. Rank 0's console holds 41 KB
    including 329 cloud-init lines and mpirun's own ip-… output — but not
    the MPI script's echos. So only some cloud-init output reaches the serial
    console. (That is also why resolveInstance cannot see shutting-down or recently-terminated instances, so status/terminate report "not found" for a spore that is right there #736's option B has to be an explicit write to
    /dev/console, not a log line expected to drift there.)
  2. In-run via SSM, grepping cloud-init-output.log. Reported "line not
    found", even though the smoke's node-count assertion greps that same log
    successfully for ^ip-. So the echo is not reaching it either.

Rather than keep guessing at the cause, the readiness loop now also writes its
elapsed seconds to /var/log/spawn-mpi-peer-wait-seconds, and the smoke reads
that file. A file is unambiguous: present means the poll ran, contents give the
duration.

I have not spent another run to collect the number. The poll's logic is
covered by unit tests, and what hardware is needed for — that it does not break
assembly at scale — is established. The duration is informative, not
load-bearing, and the next NODES=4 run will report it for free.

Also confirmed while checking this

GenerateMPIUserData is genuinely on the --mpi cohort path
(cmd/launch_jobarray.go:154, appended to combinedUserData), so this is not a
fix to a template nobody renders — I checked, because "line not found" is also
what dead code looks like.

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?
@scttfrdmn
scttfrdmn force-pushed the fix/mpi-peer-readiness-poll branch from 1782a9a to dc2bf86 Compare October 8, 2026 18:51
@scttfrdmn
scttfrdmn merged commit d41d565 into main Oct 8, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/mpi-peer-readiness-poll branch October 8, 2026 19:00
scttfrdmn added a commit that referenced this pull request Oct 8, 2026
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.
scttfrdmn added a commit that referenced this pull request Oct 8, 2026
…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.
scttfrdmn added a commit that referenced this pull request Oct 8, 2026
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.
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.

1 participant