Skip to content

fix(sweep): boot spored on detached sweep members and verify it (#1323, #1313) - #1332

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1323-1313-detached-sweep-spored
Oct 26, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1323-1313-detached-sweep-spored

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

P0 cost safety. Detached (Lambda-orchestrated) sweep members, which are the default for --param-file, launched with no UserData, so spored never ran on them. They had no in-instance TTL, idle, cost or completion enforcement, and only the TTL reaper ended them, in the regions it covers. This PR boots spored on every member and then verifies it (#1313).

Fixes #1323
Fixes #1313

Where the bootstrap is built: the CLI, shipped in the params

The CLI renders each member's user data with buildUserData, the same builder the foreground sweep loop uses. It calls it on the member's buildLaunchConfigFromParams config, then encodeUserDataForOS, and puts the result in the uploaded params under spawn_user_data. When every member's bytes are identical (the usual case) they go under defaults: once; otherwise each row gets its own copy. The Lambda passes the value to RunInstances verbatim.

Why the CLI and not the Lambda:

  • Inputs. The inputs are the CLI's: the local public key, --plugin/--config plugins and --user-data contents.
  • Release version. The stub has to name the release whose signed body it fetches (User data: fetch the bootstrap from S3 behind a small verifying stub, removing the 16 KiB ceiling (follow-up to #1246) #1274), and launcher.CallerVersion is stamped only into the CLI. deploy-sweep-orchestrator.sh builds with a plain go build against a replaced spawn, so PublishedBodyVersion() would return "" there and every member would get the inline body. Rendering in the CLI gives the same result as the foreground path, release stub or dev inline included. Dependency weight was not the deciding factor: go list -deps gives 793 packages for the orchestrator and 801 with pkg/launcher added.
  • Size. The user data is what a foreground member gets, so the 16 KiB limit is the same. Params live in S3, not DynamoDB, so they add no item-size risk.
  • Scheduled sweeps. spawn schedule create seeds the bootstrap the same way. scheduler-handler re-encodes only defaults/params, so the key survives there without a redeploy. The schedule's own sweep_name/max_concurrent/launch_delay are left out of the member configs.
  • Fail closed. The Lambda refuses a member with no bootstrap (it records a failed row and does not launch it). A member launched without one would bill for 5 minutes with no TTL and then be killed by the Detached (Lambda-orchestrated) sweeps never verify spored on their members (#1305 follow-up) #1313 check anyway.
  • File values. A file may not set spawn_user_data (reservedRowKeys), and any value it does carry is dropped before seeding.

Instance profile and PassRole

  • Profile. The CLI ensures spored-instance-profile (SetupSporedIAMRole) for members with no iam_role, as the foreground path does. This runs after the confirmation prompt, so declining the prompt creates nothing. The Lambda's fallback is now that profile instead of the hand-made spawnd-role.
  • PassRole. scripts/setup-sweep-cross-account-role.sh now grants this statement to SpawnSweepCrossAccountRole:
    {"Effect":"Allow","Action":["iam:PassRole"],
     "Resource":["arn:aws:iam::${CURRENT_ACCOUNT_ID}:role/spored-instance-role",
                 "arn:aws:iam::${CURRENT_ACCOUNT_ID}:role/spawnd-role"],
     "Condition":{"StringEquals":{"iam:PassedToService":"ec2.amazonaws.com"}}}
    Simulate it in the member account before relying on it. Allow: iam:PassRole on role/spored-instance-role with iam:PassedToService=ec2.amazonaws.com. Deny: the same role with PassedToService=lambda.amazonaws.com, any role/spawn-instance-*, and role/SpawnSweepCrossAccountRole. Per the PutRolePolicy lesson, do one real put-role-policy on a throwaway role first.
  • Existing permissions. The script already grants ec2:DescribeInstances and ec2:TerminateInstances on *, so Detached (Lambda-orchestrated) sweeps never verify spored on their members (#1305 follow-up) #1313 needs no new EC2 grant.

#1313: verifying spored

countActiveInstances (single-region) and countActiveByRegion (multi-region) already describe every active member on each poll. A member that is still running with no spawn:last-heartbeat past the CLI's budget is terminated. The budget is 5 minutes on Linux and 10 on Windows (sporedVerifyTimeout, #1305), measured from the recorded LaunchedAt. The terminated member is recorded as a failed row (moved from launched to failed, sweep-wide and per region), so it frees its slot. A member whose terminate call fails stays active and is retried on the next poll. The multi-region loop now decides completion with completionStatus too, so a sweep in which no member came up records FAILED.

Gates, each watched failing against a compiling revert

Gate Revert
TestDetachedMemberUserDataIsTheForegroundMembers (cmd): a member's seeded user data equals, byte for byte and decoded, encodeUserDataForOS(buildUserData(...)) for the same member config; member-specific input (completion_file) reaches it no public key passed; row ignored
TestMemberLaunchesWithTheCLIsBootstrap (lambda): RunInstances UserData is the CLI's value verbatim (row overrides defaults); IamInstanceProfile set; fallback is spored-instance-profile UserData dropped; profile dropped; fallback spawnd-role
TestEveryRunInstancesCallUsesTheBuilder: every RunInstances call is fed by buildRunInstancesInput, and there is exactly one input literal hand-built input at one call site
TestDetachedBootstrapIsTheReleaseStubOrDevInline: CallerVersion=0.147.0 gives the stub SPAWN_BS_VERSION='0.147.0'; dev gives the inline body CallerVersion cleared in the seeder
TestMemberWithoutBootstrapIsNotLaunched fail-closed check if false
TestSingleRegion/MultiRegionReapsMembersWithoutSpored: only the no-heartbeat member past budget is terminated; the verified, young and Windows-within-10m members are kept; Failed/Launched and per-region tallies move; active count drops no termination; no recording (each loop); heartbeat ignored; Windows budget = Linux; killed counted active
TestFailedTerminationIsRetriedNotRecorded, TestSporedBudgetsMatchTheCLI, TestBothLoopsDecideCompletionTheSameWay multi-region COMPLETED unconditional
TestSweepCrossAccountRoleMayPassSporedsRole (scripts): PassRole names SporedRoleName read from pkg/aws, has no wildcard, PassedToService=ec2 spored role removed; role/*; PassedToService changed
TestEnsureDetachedInstanceProfile, TestSeedScheduleParams_CarriesTheBootstrap, TestLaunchSweepDetachedSeedsBeforeUpload, TestDetachedBootstrapWrittenOnceAndNeverFromTheFile, TestDetachedBootstrapKeylessWithoutALocalKey ensure never runs; schedule drops key; wiring removed; file value honoured; reserved key removed; keyless errors
TestDetachedSweepSeedsEveryKeyTheLambdaReads now scans all orchestrator sources and resolves a named-constant key Lambda key renamed

Deploy (not done here: no AWS)

  1. Redeploy the orchestrator. It is hand-deployed (no CFN stack) from the infra account (966362334030), us-east-1: AWS_PROFILE=spore-host-infra ./scripts/deploy-sweep-orchestrator.sh. The script builds GOOS=linux GOARCH=amd64, runs update-function-code, re-asserts timeout 900 and memory 512, tags spawn:version, sets log retention, and verifies CodeSha256.
  2. In each member account, re-run SPAWN_MEMBER_ACCOUNT=<id> ./scripts/setup-sweep-cross-account-role.sh. It is an idempotent put-role-policy that adds the PassRole statement above. Do this before or with step 1: without it, every member's RunInstances is refused once the Lambda passes spored-instance-profile.
  3. Older sweeps and schedules carry no bootstrap. After step 1 their remaining members are refused (failed rows, not launched). Re-run or re-create them with this CLI (CHANGELOG, Changed).

Follow-ups filed

Checks

  • make check: all steps pass except step 7, check-build-tags. That step fails on the /private/tmp worktree path and lists only e2e/integration files this PR does not touch. It fails the same way on main.
  • make lint (inside check): 0 issues in all 10 modules.
  • semgrep scan --config=auto --error .: clean.
  • No help text changed (no gen-docs). No exported pkg symbols changed (no api-snapshot).

@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 36 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_sweep_detached_bootstrap.go 71.42% 22 Missing ⚠️
cmd/schedule.go 56.25% 7 Missing ⚠️
cmd/launch_sweep.go 0.00% 5 Missing ⚠️
cmd/launch_config.go 80.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

#1313)

Detached (Lambda-orchestrated) sweep members launched with no UserData, so
spored never ran on them: no in-instance TTL, idle, cost or completion
enforcement, only the TTL reaper.

- The CLI renders each member's user data with buildUserData, the builder
  the foreground sweep path uses, and ships it in the params under
  spawn_user_data (defaults when every member agrees, per row otherwise),
  for both spawn launch --param-file and spawn schedule create. The Lambda
  passes it to RunInstances verbatim and refuses a member without one.
- The CLI ensures spored-instance-profile for members with no iam_role;
  the Lambda's fallback is that profile. The cross-account role may pass
  spored-instance-role (and spawnd-role) to EC2 only.
- The orchestrator terminates a member still running with no
  spawn:last-heartbeat past the CLI's spored budget (5m Linux, 10m
  Windows) and counts it failed, in both polling loops; the multi-region
  loop now decides completion with completionStatus.

Fixes #1323
Fixes #1313
@scttfrdmn
scttfrdmn force-pushed the fix/1323-1313-detached-sweep-spored branch from 58f65c7 to 5a3cb8e Compare October 26, 2026 22:44
@scttfrdmn
scttfrdmn merged commit 6c94040 into main Oct 26, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1323-1313-detached-sweep-spored branch October 26, 2026 23:00
scttfrdmn added a commit that referenced this pull request Oct 27, 2026
….0-era params (#1368) (#1370)

A CLI at v0.146.0 or older uploads only ami, iam_role, instance_type,
key_name, spot and ttl per member, and existing schedules replay those
params on every firing, so neither carries spawn_user_data or spawn_tags.
Since #1332/#1354 the orchestrator refused such members. It now renders
both itself with the shared builders (launcher.BuildUserData, whose stub
fetches the body published for the orchestrator's own release, and
aws.BuildLaunchTags), so those members run spored and carry the full tag
set. Strict params are unchanged; params carrying only one key are refused.

The deploy script now deploys only a clean release tag whose published
bootstrap body matches the compiled one, injects -X main.Version, and
builds the package instead of main.go alone, which no longer compiled.
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