Skip to content

fix(sweep): a detached sweep launched zero instances and reported success (#749) - #751

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/749-detached-sweep-launches-nothing
Oct 8, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/749-detached-sweep-launches-nothing

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #749.

The defect

The orchestrator Lambda never sees a LaunchConfig — it reads param keys out of
the uploaded params.json and builds RunInstances from them. Diffing the two
sides:

keys
orchestrator reads ami iam_role instance_type key_name spot ttl
CLI seeded cost_limit iam_role idle_timeout instance_type region ttl volume_size

ami missing was fatal: every RunInstances was rejected with
MissingParameter: The request must contain the parameter ImageId. key_name
and spot were silently dropped. Detached is the default for parameter
sweeps, so the default path created nothing for the entire life of the feature,
while the Lambda logged All instances launched and completed and the CLI
printed Parameter sweep queued successfully and exited 0.

It is #697's class again, on exactly the path #697 explicitly scoped itself out
of. The codebase even documents the symptom's cause — "only the foreground path
detects an AMI per config" appears as a reason to prefer --no-detach for
heterogeneous sweeps. What nobody noticed is that it meant the detached path
resolved no AMI at all.

The fix, in four parts

1. Seed the keys, resolving the AMI per row. Not one sweep-wide default:
GetRecommendedAMI keys off architecture and GPU, so a single default would
force one row's AMI onto all of them and an arm64 AMI on an x86 row does not
boot (#372). Memoized by (region, arch, gpu) like the foreground path, so 50
rows over three families make three SSM lookups.

A resolve failure is fatal, not a warning — continuing would upload a row
with no ami, which is the bug. An unset flag leaves the key absent rather
than writing "": RunInstances rejects an empty KeyName outright, and the
Lambda has its own iam_role fallback that an empty string would defeat.
Precedence is unchanged — a row's own key > the CLI flag > the file's defaults.

2. The gate is mechanical. TestDetachedSweepSeedsEveryKeyTheLambdaReads
greps the Lambda source for getStringParam/getBoolParam and requires each key
to be declared, with a guard that fails if the regex matches nothing (a silently
vacuous gate being the obvious failure mode). A hand-maintained list is exactly
what failed here, so the list is checked against reality rather than trusted.

It immediately caught an error in my own list: I had included region, but
the Lambda takes the region from the sweep record (state.Region), not from
the params. The list now documents that the contract is "what the Lambda reads",
not "what matters" — conflating those is how a list stops being trustworthy.

3. Stop reporting success after total failure. completionStatus() returns
FAILED when zero of N launched. This is the worst of the four: a cost-control
tool reporting a launch that did not happen, the same class as #737's declined
terminate exiting 0. state.Failed was already being counted — the completion
branch simply never consulted it.

A partial failure deliberately stays COMPLETED: the sweep did run, the
per-row ErrorMessages are in the record, and a third status value would send
cancel, resume and six workflow adapters — all of which branch on
Status == "COMPLETED" — down a default path. FAILED is an existing value, so
nothing gets a novel one to mishandle.

4. Stop promising what the CLI cannot verify. "The sweep is now running in
Lambda. You can disconnect safely" was unsupportable — the CLI's only evidence is
that the Lambda was invoked. It now says that plainly and points at
spawn status --sweep-id.

Verification

revert fails
ami undeclared in the key list the orchestrator reads [ami], which detachedParamKeys does not declare
seeder never writes ami Defaults["ami"] = <nil>, want ami-explicit
status always COMPLETED completionStatus(launched=0, failed=2) = "COMPLETED", want "FAILED" — a sweep that launched nothing is not completed

Also asserted: precedence in both directions, that an unset flag writes no empty
value, that a row with no instance type is an error rather than an unresolved
row, and that completionStatus only ever returns values that already exist.

gofmt, go vet ./..., go test -short ./..., the nested-module suite,
make check-docs, changelog gate, semgrep scan --config=auto --error
(0 findings).

Hardware: running scripts/hardware-test-detached-sweep.sh (added in #750)
against this build and the currently-deployed Lambda — the CLI half is what makes
rows launch, so that is provable before any redeploy. Result to follow in a
comment.

Needs a deploy

Part 3 lives in the Lambda, so the honest-status half only takes effect after
scripts/deploy-sweep-orchestrator.sh runs. Parts 1, 2 and 4 are CLI-side and
ship with the binary. The deploy needs approval separately — flagging it rather
than bundling it, since the CLI fix is what unblocks #725's verification and it
stands alone.

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Hardware verified — and this also closes out #725

Ran scripts/hardware-test-detached-sweep.sh (from #750's branch) against this
build and the currently-deployed Lambda, so the CLI half is proven on its own
before any redeploy:

=== Launching a 2-row DETACHED sweep (t4g.small, ttl=20m)
  ✅ sweep dispatched: sweep-20261007-394000

=== Waiting for the orchestrator to launch the rows (up to 5 min)
  ✅ both rows launched by the orchestrator

=== #725: the lifecycle tags that make a row reapable
  --- i-0b07c2ae0c1ed7c9b
       Name                 sweep-0
       spawn:managed        true
       spawn:sweep-id       sweep-20261007-394000
       spawn:sweep-index    0
       spawn:ttl-deadline   2026-10-08T04:58:00Z
  ✅ spawn:managed=true — the rail the reaper's terminate is conditioned on
  ✅ spawn:ttl-deadline=2026-10-08T04:58:00Z
  ✅ the reaper is permitted to terminate it
  (same for i-01a1b8c9cb18ee517 / sweep-1)

=== Result: 8 passed, 0 failed

Three things this establishes:

  1. Rows launch. The same test against the unfixed CLI reported only 0 row(s) appeared after 5 min with MissingParameter: ImageId for every row, twice.
  2. A detached sweep (the DEFAULT) launches instances with no spored and no spawn:managed tag — so neither spored nor the reaper can ever stop them #725 is now verifiable, and verified. Its tag fix (fix(sweep-orchestrator): make detached sweep rows reapable (#725) #726) merged in
    September and has been unobservable ever since, because the default path
    created nothing to tag. Both rows carry spawn:managed=true and
    spawn:ttl-deadline, from the Lambda, on real hardware.
  3. The tags actually unlock the terminate. Simulated ec2:TerminateInstances
    for the reaper's cross-account role against each real instance ARN with the
    real tag value: allowed for both. A tag that doesn't authorise anything would
    have looked identical in a describe-tags dump.

Note spawn:ttl-deadline is ~20 minutes out, matching --ttl 20m — so the
deadline is derived from the sweep's TTL rather than fabricated, which is what
#726's changelog claimed and nothing had confirmed.

Cost: two t4g.small for ~4 minutes, terminated explicitly by the script,
then an independent describe-instances across the entire target account
returned 0 non-terminated instances. Nothing leaked.

Still outstanding: part 3 (the FAILED status) is Lambda-side and needs
scripts/deploy-sweep-orchestrator.sh.

…cess

The CLI never seeded `ami` into the params the orchestrator Lambda
reads, so every RunInstances was rejected with `MissingParameter: The
request must contain the parameter ImageId`; the Lambda then logged "All
instances launched and completed" and the CLI printed "Parameter sweep
queued successfully" and exited 0. Detached is the DEFAULT for parameter
sweeps, so the default path created nothing for the whole life of the
feature.

The Lambda never sees a LaunchConfig: it reads six param keys and builds
RunInstances from them. Diffing the two sides:

  orchestrator reads:  ami iam_role instance_type key_name spot ttl
  CLI seeded:          cost_limit iam_role idle_timeout instance_type
                       region ttl volume_size

`ami` missing was fatal; `key_name` and `spot` were silently dropped. It
is #697's class again, on the path #697 explicitly scoped itself out of.

AMI resolution is PER ROW, not one sweep-wide default: GetRecommendedAMI
keys off architecture and GPU, so a heterogeneous sweep (#372) would
otherwise get one row's AMI forced onto all of them, and an arm64 AMI on
an x86 row does not boot. Memoized by (region, arch, gpu) like the
foreground path. A resolve failure is FATAL rather than a warning —
continuing would upload a row with no ami, which is the bug.

Precedence is unchanged: a row's own key > the CLI flag > the file's
defaults. An unset flag leaves the key ABSENT rather than writing an
empty string; RunInstances rejects an empty KeyName outright and the
Lambda has its own iam_role fallback that "" would defeat.

Lambda: completionStatus() now returns FAILED when zero of N launched.
This was the worst of the four problems — a cost-control tool reporting
a launch that did not happen, the same class as #737's declined
terminate exiting 0. state.Failed was already counted; the completion
branch simply never consulted it. A PARTIAL failure stays COMPLETED on
purpose: the sweep did run, per-row ErrorMessages are recorded, and a
third status value would send `cancel`, `resume` and six workflow
adapters down a default branch. FAILED is an existing value.

CLI: "The sweep is now running in Lambda. You can disconnect safely" was
a claim the CLI cannot support — its evidence is that the Lambda was
invoked. Now says so and points at `spawn status --sweep-id`.

The gate is mechanical: TestDetachedSweepSeedsEveryKeyTheLambdaReads
greps the Lambda source for getStringParam/getBoolParam and requires
each key to be declared, because a hand-maintained list is exactly what
failed. It immediately caught `region` in my own list — the Lambda takes
the region from the sweep record, not the params — so the list now
documents that the contract is "what the Lambda reads", not "what
matters".

Gates confirmed to fail on revert: ami undeclared, the seeder not
writing ami, and the status always COMPLETED.
@scttfrdmn
scttfrdmn force-pushed the fix/749-detached-sweep-launches-nothing branch from e7d55c4 to 36ce38a Compare October 8, 2026 04:46
The changelog gate caught this correctly — I committed the fix with no
entry at all. Then the entry collided with the existing `### Fixed`
group, which is the mechanical duplicate-group conflict; consolidated
with `make changelog-fix` rather than hand-merged.
@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 41.53846% with 38 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_sweep_detached_keys.go 47.36% 24 Missing and 6 partials ⚠️
cmd/launch_sweep.go 0.00% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit cadc5e3 into main Oct 8, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/749-detached-sweep-launches-nothing branch October 8, 2026 04:57
scttfrdmn added a commit that referenced this pull request Oct 9, 2026
The script's header still said THIS TEST FAILS on #749. It no longer does:
8/8 against spawn v0.126.0 and the orchestrator Lambda deployed 2026-10-08,
the first run in which #725's assertions were observable at all.

Replaces the stale claim with what a future reader actually needs: that two
things must be true at once and only one of them is in the repo. The CLI
must seed the params (#751, in v0.126.0) AND the deployed orchestrator must
carry the tag fix (#726). A Lambda does not upgrade with the CLI (#654), so
a regression here is as likely to be a stale deploy as a code bug — the
header now says to check the deployed LastModified against
'git log -- lambda/sweep-orchestrator/' first.

No behaviour change; comments only. bash -n clean.
scttfrdmn added a commit that referenced this pull request Oct 9, 2026
)

The script's header still said THIS TEST FAILS on #749. It no longer does:
8/8 against spawn v0.126.0 and the orchestrator Lambda deployed 2026-10-08,
the first run in which #725's assertions were observable at all.

Replaces the stale claim with what a future reader actually needs: that two
things must be true at once and only one of them is in the repo. The CLI
must seed the params (#751, in v0.126.0) AND the deployed orchestrator must
carry the tag fix (#726). A Lambda does not upgrade with the CLI (#654), so
a regression here is as likely to be a stale deploy as a code bug — the
header now says to check the deployed LastModified against
'git log -- lambda/sweep-orchestrator/' first.

No behaviour change; comments only. bash -n clean.
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 detached parameter sweep launches ZERO instances and reports success (MissingParameter: ImageId)

1 participant