Skip to content

fix(sweep): honour CLI flags instead of dropping 83 of 127 (#697) - #724

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/697-sweep-honours-cli-flags
Oct 8, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/697-sweep-honours-cli-flags

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #697. 84 flags now honoured, up from 44; known gaps 58 → 18 — measured by the coverage manifest, not asserted.

The inversion

The dispatch built a two-field LaunchConfig and buildLaunchConfigFromParams merged rows onto an empty struct, so every other CLI flag was dropped by default. A flag worked only if someone had hand-written a shim — which is why this class was reported and patched six times (#525, #539 twice, #549, #667, #673/#674/#675). The architecture guaranteed a seventh.

The dispatch now calls buildLaunchConfig — the same function the single-instance path uses — and each row merges onto that. Default inverts from "drop everything unless someone wrote a shim" to "honour every flag unless the row overrides it". Row keys still win, preserving #539's precedence.

Both flagged risks were milder than feared, and I checked

buildLaunchConfig's validation applying to sweeps — all of its validations are mutual-exclusion guards that fire only when the user passed the relevant flags. Applying them to sweeps is strictly an improvement: --fsx-create without --fsx-s3-bucket was previously accepted and ignored.

The empty-field branches — firstConfig.KeyName == "" and firstConfig.IamInstanceProfile == "" are fallbacks ("fill in if absent"), not conditionals where empty means something else. Populating a field just means the fallback runs less, which is the intent.

One bug the inversion could easily have introduced

config := base copies the struct, so without an explicit deep copy every row would share the base's Tags map and its SecurityGroupIDs/AttachVolumes slices. One row adding a tag would add it to all of them — and rows launch concurrently, so it would also be a data race.

There's a gate for it, verified by removing the deep copy:

rows share the Tags map — a tag set on one row appears on every other, and rows launch concurrently so this is also a race
rows share the SecurityGroupIDs slice: row b now has "sg-mutated"
rows share the AttachVolumes slice: row b now mounts "/mutated"
a row mutated the BASE config's Tags map, so the leak outlives the sweep

The 18 remaining gaps are a different defect

I found these by flipping all 58 gaps to honoured and letting the gate name the ones still unreachable — the gate doing the classification rather than me guessing. Twelve came back:

--tag, --team, --spot-max-price, --fsx-throughput, --fsx-skip-validate, --allow-cidr, --allow-cost-limit-overrun, --strata-*, --wait-for-running, --wait-for-ssh

All are applied imperatively later in launchSingleInstance (or launch_cost_limit.go / launch_batchqueue.go), which the sweep dispatch returns before reaching. Nothing about them flows through a config, so the inversion could not have fixed them. The manifest now records that distinction instead of lumping them in with the config-carried ones — it's a smaller and structurally different problem.

I also widened the gate's notion of "the sweep path" to include launch_config.go, since the sweep now consumes its output. Before the inversion, that would have been wrong.

On the hardware smoke

make smoke-needed reports no hardware-sensitive paths changed — and I think it's under-inclusive here, so I'm flagging rather than relying on it.

The config construction itself is pure data transformation and fully unit-tested. The risk is downstream: a sweep with --efs-id will now actually attempt an EFS mount on every row, which has never happened before. That makes previously-dead code paths live on the sweep path, and whether they work is a property of a running instance.

So I'd like to run one before this ships: 2 rows, smallest viable instance, tight TTL, with --efs-id to exercise exactly the newly-live storage path, leak-checked afterwards. That's a few cents. Not adding the sweep files to the manifest, because this is a one-time transition risk rather than a standing property of those files.

Full suite green including go test -tags e2e_tier0 — the runner I missed on #722 and won't miss again.

The sweep dispatch built a two-field LaunchConfig and buildLaunchConfigFromParams
merged rows onto an EMPTY struct, so every other CLI flag was dropped by default.
A flag worked only if someone had hand-written a shim, which is why the same class
was reported and patched six times (#525, #539 twice, #549, #667, #673/#674/#675)
— the architecture guaranteed there would be a seventh.

Not cosmetic: a sweep could not mount ANY storage (--efs-id, all eleven --fsx-*,
--attach-volume), every row landed in the VPC default security group even after
#667 fixed single launches, and --pre-stop was dropped — the hook that syncs
results before termination, so losing it loses output.

The fix inverts the default. The dispatch now calls buildLaunchConfig, the same
function the single-instance path uses, and each row merges onto that. "Honour
every flag unless the row overrides it" instead of "drop everything unless someone
wrote a shim". Row keys still win, preserving #539's precedence.

Measured rather than asserted, using the coverage manifest: 84 flags honoured, up
from 44; known gaps 58 -> 18.

The two risks the issue flagged both turned out milder than feared, and I checked
rather than assuming:

  - buildLaunchConfig's validations are mutual-exclusion guards that only fire
    when the user passed the relevant flags. Applying them to sweeps is strictly
    an improvement: --fsx-create without --fsx-s3-bucket was previously
    accepted-and-ignored.
  - The empty-field branches (firstConfig.KeyName == "",
    firstConfig.IamInstanceProfile == "") are FALLBACKS — "fill in if absent" —
    so populating a field just means the fallback runs less, which is the intent.

One bug the inversion could easily have introduced, and a gate for it: `config :=
base` copies the struct, so without an explicit deep copy every row would share
the base's Tags map, SecurityGroupIDs and AttachVolumes slices. One row adding a
tag would add it to all of them, and rows launch CONCURRENTLY, so it would also be
a race. Verified by removing the deep copy and watching the gate catch all four
aliases including the leak back onto the base config.

The 18 remaining gaps are a structurally different defect and the manifest now
says so rather than lumping them together: --tag, --team, --spot-max-price,
--fsx-throughput, --allow-cidr, --strata-* and the --wait-for-* pair are applied
IMPERATIVELY later in launchSingleInstance, which the sweep dispatch returns
before reaching. Nothing about them flows through a config, so the inversion could
not have fixed them. Found by flipping all 58 to honoured and letting the gate
name the ones that were still unreachable — which is the gate doing the
classification instead of me guessing at it.

Also widened the gate's notion of the sweep path to include launch_config.go,
since the sweep now consumes its output. Before the inversion that would have been
wrong.
@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 48.38710% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_sweep.go 0.00% 8 Missing ⚠️
cmd/launch_single.go 0.00% 7 Missing ⚠️
cmd/resume.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

… path

The sweep leg is what the inversion needed: a sweep with --efs-id now actually
attempts a mount on every row, which has never happened on this path before, and
only an instance can tell you whether it works.

It also found three things, two of them bugs in the leg itself:

  - --tag does not reach a sweep row (one of #697's 18 remaining gaps), so the
    first version filtered on a tag the rows never received and reported "found
    0" while rows were running. The leg's own discovery key was a flag it exists
    to test the absence of. Rows are now found by the Name prefix spawn assigns.
  - `mount | grep -c` finishes in milliseconds, so the rows self-terminated
    before the SSM checks ran — the identical trap the storage leg documents ten
    lines above, which I wrote this leg without applying. The command now ends in
    `sleep 900`.
  - Cleanup and the leak check both needed the two-filter treatment, or the leg
    would leak its own rows while printing "no instances left behind" — the same
    false pass this check already produced once for placement groups.

And the finding that matters, now scoped into the changelog rather than left
implied: #697's fix covers the FOREGROUND path only. Detached is the DEFAULT
(launchParameterSweep auto-enables it), and a detached sweep is launched by the
spawn-sweep-orchestrator Lambda, which builds RunInstances from four param keys
and never sees a LaunchConfig. On that path the drop is closer to 123 of 127 —
and those rows get no UserData (no spored) and no spawn:managed tag (no reaper),
so nothing can stop them. Filed as #725.

Also seeded region/instance_type into paramFormat.Defaults from the CLI, because
pkg/sweep/detached.go's cost estimator reads the param file directly and never
sees a config: `--instance-type t4g.small` with rows that omit it still failed
"param set 0: no instance_type specified". That is a seventh instance of this
class and the first one a unit test could not have found, since the estimator
only runs on a real launch.
@scttfrdmn
scttfrdmn merged commit 601efba into main Oct 8, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/697-sweep-honours-cli-flags branch October 8, 2026 01:44
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.

The sweep path drops 83 of 127 launch flags by construction — parent of #525/#539/#549/#667/#673/#674/#675

1 participant