Skip to content

fix(bootstrap): record a failed completion when the bootstrap fails after spored starts (#1484) - #1488

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/1484-bootstrap-failclosed
Nov 2, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/1484-bootstrap-failclosed

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1484

⚠️ The published bootstrap body changes

spawn bootstrap-body sha256: f04b5d9a0a06f39801204a7f0357c5c94a6b8b16298fb2452bc3e1d31edfcc17 (main at 54f9a61) → b447ce0938c5fafd7acc827e0f956bc884ff207e72f0dd0bea7d46c31d56fcbb (24279 → 24421 bytes raw). Deploy the sweep orchestrator from the release that carries this (it embeds the body; deploy checklist). The per-launch prefix changes too (one line in spawn_exit_guard).

before after
release stub, bare launch (gzip) 1805 1840 (+35; budget 3072)
inline bare bootstrap (gzip) 7393 7412 (+19; budget 8448, margin 1024 kept: 1036 spare)

To stay inside the #1422 margin without raising the budget, three heredoc comment lines (data, so shellmin cannot strip them) are no longer written into /etc/profile.d/session-timeout.sh, job-array.sh and spawn-params.sh; their rationale moved to a shell comment. The variables those files set are unchanged.

The gap

After SPAWN_SPORED_UP=1, spawn_exit_guard returned 0 on any exit. The body then runs ~330 lines under set -e (user, key, sudoers, session timeout, array/hostname/sweep setup, MOTD) before launching --command or handing over to the user data after it. A failure there wrote no completion record: --on-complete never fired and the instance billed to its TTL/idle timeout.

Design (mirrors #1485's mpi-bootstrap trap)

  • The prefix guard, once spored is up: [ "$rc" = 0 ] || [ -n "$SPAWN_HANDED_OFF" ] || spawn_boot_failed "$rc"; return 0. It still never retires the instance after spored is up (spored enforces the TTL), and still ignores subshells (BASHPID check first).
  • spawn_boot_failed lives in the body (so release launches don't carry it in user data), defined just before SPAWN_SPORED_UP=1, with SPAWN_HANDED_OFF= reset there. It writes {"status": "failed", "exit_code": <rc>, "source": "bootstrap"} to $SPAWN_CMD_COMPLETION_FILE (mkdir for a custom --completion-file), and logs spawn: bootstrap failed (status N, at line L: <cmd>) after spored started; recording it (#1484) to stderr and /var/log/spawn-command.log (which spored copies to the console on a failed record).
  • Two hand-off points, SPAWN_HANDED_OFF=1: right after ( ... ) & launches --command (the subshell then owns the outcome: success, failure, or a failed gate), and as the body's last statement (storage, container, custom user data, MPI, task runner own theirs). This replaces the issue's "command requested" test: the guard needs no knowledge of whether a command was requested (embedded or tag-delivered sweep command), so tag-delivered sweep commands are covered with no extra describe-tags.

Decisions

  • No --on-complete: current spored semantics are that the completion file is acted on only when OnComplete != "" (agent.go step 1; refreshForEarlyCompletion re-reads tags up to 5 times in case the tag was just not visible yet). I kept that: the record is written, spored does nothing, the TTL or idle timeout (spawn applies a 1h idle default when neither is set) ends the instance, and spawn status --check-complete reports the failure. That is exactly what a failed --command does today, and the command path documents omitting --on-complete as the way to keep a failed instance. Not a spored behaviour change. Escalating to retire-on-failure when no --on-complete is set would contradict that design for this one source; if the owner wants that, it belongs in spored (a source-aware default), as a separate decision.
  • No --command (interactive, or workload via --user-data/container/MPI/task runner): same failed record, same on-complete semantics, no retire. fatalRetireFunc retires only when nothing enforces the TTL; here spored does. The record matters because none of the user data after the body runs once it fails; with --on-complete set (as a user-data or pool workload would), the instance now ends instead of idling.
  • This is a behaviour change only for failed bootstraps: they now write a record that fires --on-complete. Healthy boots write nothing new. CHANGELOG: Fixed (the record) and Changed (the body).

MPI composition (#1485)

  • Failure in the bootstrap window on an MPI member: the bootstrap exits there, the MPI script never runs, one bootstrap record.
  • Failure inside the MPI user data: spawn_mpi_exit writes its mpi-bootstrap record, then calls spawn_exit_guard, which sees SPAWN_HANDED_OFF=1 and writes nothing. No terminate from either (spored up). One record.
  • Not covered (unchanged from fix(mpi): build the hostfile without jq; fail closed on any MPI setup failure (#1483) #1485): on rank 0 with --mpi-command, a rank-0 bootstrap failure before the MPI script writes only rank 0's record; peers wait for one (bounded by TTL/idle), as when rank 0 dies outright.

Gates (pkg/launcher/bootstrap_failclosed_test.go, full inline bootstrap in the boot sandbox, fullBoot gained a bootOpts for stand-ins and appended user data)

  • TestBootstrapFailureAfterSporedWritesAFailedRecord: useradd (9), chown (5), chmod +x spawn-command.sh (6) with --command; useradd (9) and the MOTD chmod (7) without. Each: spored started, script exit = step status, record failed//bootstrap, log names the line, not retired, workload and user data did not run.
  • TestBootstrapFailureAfterTheCommandLaunchedLeavesItsRecord: the MOTD step (after launch) waits for the command's record, then fails: the record stays command/3, no A bootstrap failure after spored starts but before --command launches writes no completion record; the instance bills to TTL #1484 line.
  • TestBootstrapHandsOffAtTheCommandAndAtItsEnd: exactly two SPAWN_HANDED_OFF=1, immediately after ) & and as the body's last statement.
  • TestNoRecordAfterTheBodyHandsOff: healthy boot writes nothing; custom user data ending in false writes nothing; MPI install failure (appended real GenerateMPIUserData) gives exactly one mpi-bootstrap/137 record; bootstrap failure before the MPI script gives exactly one bootstrap/9 record and no MPI step.

Watched failing against compiling reverts:

  • R1 guard back to [ "$SPAWN_SPORED_UP" = 1 ] && return 0: all 5 window cases + "bootstrap fails before the MPI script" fail.
  • R2 drop the hand-off after ) &: the after-launch test (bootstrap record overwrites the command's) and the structure test fail.
  • R3 drop the end-of-body hand-off: custom-user-data and MPI-composition cases (a second, bootstrap, record) and the structure test fail.

AL2: the guard + spawn_boot_failed run under amazonlinux:2 bash 4.2.46 (exit 9 → record + log line), and bash -n of the whole published body passes there.

Live EC2 check (branch-built CLI, before merge)

A dev build inlines the body, so the branch CLI carries this change with no published body. Force a failure in the window by making useradd fail: the bootstrap user name is $USER, normalised, so USER=wheel (an existing group, not a user) should make useradd -m wheel fail with status 9 ("group wheel exists").

  1. USER=wheel spawn launch --command 'echo SHOULD_NOT_RUN' --on-complete terminate --ttl 30m ... (AL2023). Expect: the instance terminates within a few minutes (spored's on-complete, not the TTL); before it does, /tmp/SPAWN_COMPLETE = {"status": "failed", "exit_code": 9, "source": "bootstrap"}; /var/log/spawn-command.log and the console show spawn: bootstrap failed (status 9, at line N: useradd ...) after spored started; recording it (#1484); no SHOULD_NOT_RUN anywhere; spored journal shows "Completion signal detected" and the failed metadata; CloudTrail shows the terminate coming from the instance role via spored (not spawn_fatal_retire: no "FATAL" line).
  2. Same with no --on-complete (--ttl 15m): the record is written, the instance keeps running, spawn status --check-complete reports failed, and the TTL ends it.
  3. Control, normal $USER, --command 'exit 3' --on-complete terminate: record is source: command, exit_code: 3, no A bootstrap failure after spored starts but before --command launches writes no completion record; the instance bills to TTL #1484 line (the hand-off works on EC2).
  4. Optional MPI: USER=wheel with --mpi --count 2 --on-complete terminate: each member writes one bootstrap record and terminates; no MPI setup failed lines.

Afterwards verify no instance from these launches is left running.

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live-verified on EC2 (2026-11-02) with a CLI built from a45d30e6 in account 942542972736, us-east-1, AL2023. The failure was forced with USER=wheel (useradd exits 9 inside the #1484 window).

Cost was under $0.01, and the leak check is clean (the agent's and mine). Follow-up: #1493, where spawn status --check-complete SSHes in as the never-created user after a failure this early.

@scttfrdmn
scttfrdmn merged commit 1e8d127 into main Nov 2, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1484-bootstrap-failclosed branch November 2, 2026 04:44
@scttfrdmn scttfrdmn mentioned this pull request Nov 2, 2026
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.

A bootstrap failure after spored starts but before --command launches writes no completion record; the instance bills to TTL

1 participant