Skip to content

fix(sweep): carry every RunInstances setting to detached sweep members, refuse the rest (#1353) - #1367

Merged
scttfrdmn merged 3 commits into
mainfrom
fix/1353-detached-member-settings
Oct 27, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
fix/1353-detached-member-settings

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1353

A detached (Lambda-orchestrated) sweep member was launched with only the instance type, AMI, key, profile, user data and tags. Every other RunInstances setting a foreground member honours was dropped on the way.

How it works now

  • One composition. The part of Client.Launch that turns a LaunchConfig into RunInstances fields is now applyLaunchSettings (pkg/aws/launch_settings.go). It covers block devices, CPU options, network interfaces, placement, hibernation, Spot, capacity reservation and IMDS. Client.Launch calls it, and so does the orchestrator, through aws.LaunchSettings.Apply. Multi-card EFA stays in Launch, because it needs AWS calls and an Elastic IP.
  • CLI. seedDetachedBootstrap resolves each member's aws.LaunchSettings with Client.ResolveLaunchSettings. That makes the same lookups Launch makes: the AMI root device and its snapshot minimum, and the type's memory for a hibernating root. The result ships per row as spawn_launch_settings. The key is reserved, so a param file cannot set it.
  • Versioned, fail-loud schema (when present). LaunchSettings carries schema (LaunchSettingsSchema = 1). DecodeLaunchSettings refuses a missing schema, any other schema, and any unknown field, nested ones included (DisallowUnknownFields). For params that carry spawn_launch_settings, the orchestrator refuses a member whose settings it cannot fully apply. It names the member, and the refusal is not a capacity error. A hibernating Spot member, which would need a persistent request, is refused in Apply as well as by the CLI's existing guard.
  • Refusals at --detach. detachedSettingsGuard runs before anything is uploaded. Each error names the setting and a remedy.
  • With settings present, Spot comes in through them, as a one-time request with SpotOptions.MaxPrice.

Compatibility with older CLIs and existing schedules

spawn-sweep-orchestrator is shared, hosted infra, so after redeploy it serves older CLIs too.

Deploy order: deploy the orchestrator before, or together with, the CLI release. An orchestrator older than this one ignores spawn_launch_settings, so a new CLI in front of it loses the settings silently. This orchestrator handles both old and new params (subject to #1368). Note that the deployed v0.146.0 orchestrator also ignores spawn_user_data and spawn_tags.

Settings table: what a foreground member honours vs a detached member

Foreground member = buildLaunchConfigFromParams(base CLI config, defaults, row) + defaultSweepMember → Client.Launch. "Before" is origin/main; "after" is this PR.

Setting (LaunchConfig field / flag / row key) Foreground Detached before Detached after
volume_size / --volume-size (RootVolumeSizeGiB) + AMI-snapshot minimum + AMI root device name (#25/#284) yes dropped (AMI default root) carried (root_volume_gib, root_device_name)
--security-group (SecurityGroupIDs) yes dropped (default SG) carried
--subnet (SubnetID) yes dropped carried
az / --az (AvailabilityZone) yes dropped carried
public-IP network interface (#308) yes (always) dropped carried
spot (Spot) yes bare MarketType: spot carried (one-time SpotOptions)
spot_max_price (SpotMaxPrice) yes dropped carried
hibernate, hibernate_on_idle, --on-idle hibernate, on_complete: hibernate (Hibernate, HibernateOnIdle): HibernationOptions + RAM-sized encrypted root yes dropped (tag only) carried
--efa single interface (EFAEnabled) yes dropped carried
--efa-interfaces > 1 (EFAInterfaces; needs EIP association/release) yes dropped refused
--placement-group (PlacementGroup) yes dropped carried
--reservation-id (ReservationID) yes dropped carried
--capacity-block (CapacityBlock) yes dropped carried
--nested-virtualization (NestedVirtualization) yes dropped carried
--attach-volume (AttachVolumes: block devices from snapshots) yes (attached, not mounted on either sweep path) dropped carried (see note 1)
EBSEncrypted, IMDSv2Enforced, IMDSv2HopLimit (compliance; not set on sweep paths today) yes if set dropped carried
EBSKMSKeyID customer-managed key (not set on sweep paths today) yes if set dropped refused (the orchestrator role has no KMS grant)
--vpc without --subnet (VPCID) ignored (#1366) dropped refused ("pass --subnet")
--fsx-create (+ lifecycle/ttl/capacity/bucket) ignored (#1366) dropped refused
--fsx-recall ignored (#1366) dropped refused
hibernation with an instance-type pattern (a|b, c5.*) n/a (patterns are detached-only) n/a refused (root size depends on the type)
InstanceType, AMI, KeyName, IamInstanceProfile, UserData yes carried (own param keys) unchanged
CustomUserData, JobArrayCommand, CompletionFile, TargetOS (user-data side) yes carried (spawn_user_data, #1323/#1327) unchanged
every tag-side field (ttl, idle, cost limit, on_complete, DNS, pre-stop, webhooks, EFS/FSx-id mounts, notify, DCV/web app, price, sweep/job-array identity, --tag, ...) yes carried (spawn_tags, #1330) unchanged (tags/team are #1356's)
ClientToken, PlacementGroupPrefix, DNSFunctionARN, FSxPending* not set on a sweep member — — (*FSxPending is set only by the refused --fsx-create)

Note 1: Client.Launch also copies each snapshot's custom tags onto its volume after launch, best effort (#161). The orchestrator does not do that copy. The volumes still get the member's tags through TagSpecifications.

The full per-field classification, with a reason for every field not carried, is detachedDispositions in cmd/launch_sweep_detached_settings_test.go.

Gates (each watched failing against a compiling revert)

  1. Each setting reaches the orchestrator's RunInstances, from the params the CLI uploaded.
    • pkg/aws TestDetachedMemberRunInstancesIsTheForegroundMembers: every LaunchConfig field is discovered by reflection and set alone over 5 bases (plain, spot, imdsv2, reservation, encrypted). Wherever a field changes Client.Launch's composition, the detached path (settings → JSON → strict decode → Apply) must produce an identical request. It must also refuse rather than fall back when the foreground would make a persistent Spot request. Reverts: dropping SubnetID from LaunchSettings.config() failed on all bases, and dropping SpotMaxPrice from NewLaunchSettings failed on the spot base.
    • cmd TestDetachedMemberSettingsAreTheForegroundMembers: what seedDetachedBootstrap ships per row, decoded as the orchestrator decodes it, equals the settings of the config the foreground loop builds for that member. Covered: CLI flags (subnet, SG, placement, EFA, nested virt, reservation, attach volume) and row keys (volume_size, az, spot, spot_max_price, hibernate). Revert: not writing the key fails with "member 0 carries no spawn_launch_settings".
    • Lambda TestMemberLaunchesWithTheCLIsSettings: buildRunInstancesInput applies the shipped settings. Revert: skipping Apply fails on Placement, NetworkInterfaces, InstanceMarketOptions, BlockDeviceMappings and CpuOptions.
  2. A refused setting errors at --detach. TestDetachedSweepRefusesWhatTheOrchestratorCannotLaunch: seedDetachedBootstrap, which runs before upload in both launchSweepDetached and spawn schedule, errors for each of the 6 cases, names the setting and its remedy, and ships no settings. Revert: disabling the --fsx-create case failed here and in the discovery gate.
  3. Discovery gate catches a new uncarried field.
    • TestDetachedSweepCarriesOrRefusesEveryLaunchSetting (cmd): every LaunchConfig field needs a disposition, and each claim is checked mechanically. "settings" must change aws.LaunchSettings, "tags" must change BuildLaunchTags, "refused" must be refused, and a field carried some other way, or not at all, must change none of them. Revert: adding EnclaveEnabled bool to LaunchConfig failed with "has no detached-sweep disposition".
    • The same new field wired into applyLaunchSettings (EnclaveOptions) but not carried in LaunchSettings failed the pkg/aws gate on every base.
  4. Legacy params member launches with the old behaviour. Lambda TestLegacyParamsMemberLaunchesAsBefore: no settings key, spot true and false. A bare MarketType: spot with no SpotOptions, and no block devices, NICs, placement, hibernation, CPU or IMDS options. Reverts: restoring the refusal failed it, and dropping the bare-spot handling failed it.
  5. Schedule-replayed legacy params member launches. Lambda TestScheduleReplayedLegacyParamsMemberLaunches: stored params go through yaml decode as scheduler-handler's downloadParams does, then sweep.EncodeParams as prepareSweep does, then the orchestrator's JSON decode and mergeParams, then buildRunInstancesInput. Same two reverts, and both failed it.
  6. An old-schema orchestrator faced with an unknown field fails loudly. TestDecodeLaunchSettingsRefusesWhatItCannotApply (unknown field, unknown nested field, newer schema, no schema) and Lambda TestMemberWithoutApplicableSettingsIsNotLaunched. Revert: removing DisallowUnknownFields (and the schema check) failed both, and the Lambda one launched on the unknown field. After the legacy rework this was re-run, along with the "other schema" and "not an object" cases. The pkg/aws equivalence and cmd discovery gates are unchanged.

The existing TestDetachedSweepSeedsEveryKeyTheLambdaReads now matches getRawParam too, and holds spawn_launch_settings on both sides. spot stays on its key list, read on the legacy path.

IAM

None needed. The member-account role (scripts/setup-sweep-cross-account-role.sh) already grants ec2:RunInstances on Resource: "*", which covers the subnet, security-group, network-interface, placement-group, capacity-reservation and snapshot resources. The orchestrator makes no new API calls. Encryption uses only the AWS-managed aws/ebs key, because a customer-managed key is refused. The CLI-side lookups (DescribeImages, DescribeInstanceTypes) are ones the foreground path already makes. make cli-iam-actions reports no change, and the iamcoverage gate passes.

Live deploys needed (not done here)

Checks

make check passed. make lint: 0 issues in all 10 modules. semgrep scan --config=auto --error . is clean (two test decodes moved from interface{} to map[string]interface{}). make api-snapshot was regenerated: additions only (LaunchSettings, LaunchSettingsVolume, LaunchSettingsSchema, NewLaunchSettings, DecodeLaunchSettings, (*Client).ResolveLaunchSettings). make cli-iam-actions: no change.

Not verified on AWS: no live sweep was run.

Follow-ups filed: #1368 (the redeployed orchestrator refuses v0.146.0-CLI sweeps and schedules through the #1323/#1330 checks), #1366 (foreground sweeps silently drop --fsx-create, --fsx-recall and --vpc without --subnet).

@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.87179% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/aws/launch_settings.go 94.30% 7 Missing ⚠️
cmd/launch_sweep_detached_bootstrap.go 85.71% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

…s, refuse the rest (#1353)

Detached members were launched with only the instance type, AMI, key,
profile, user data and tags. The CLI now resolves each member's
RunInstances-side settings (aws.LaunchSettings, versioned, strictly
decoded) and the orchestrator applies them with the composition
Client.Launch uses. Settings the orchestrator cannot honour are refused
at --detach. Discovery gates hold every LaunchConfig field to carried or
refused.
…ings) as before (#1353)

The orchestrator is shared, hosted infra: after redeploy it serves older
CLIs and schedules whose params were captured by one. Params without
spawn_launch_settings take the pre-#1353 path (bare spot), logged once
per sweep; params with settings stay strict.
@scttfrdmn
scttfrdmn force-pushed the fix/1353-detached-member-settings branch from 3e0ae31 to e41f94c Compare October 27, 2026 05:54
@scttfrdmn
scttfrdmn merged commit e523d50 into main Oct 27, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1353-detached-member-settings branch October 27, 2026 06:16
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