Repository navigation
Description
Found while cleaning up after real-hardware verification of #659/#668. Two related defects in the --mpi setup path, both "leave no trace" violations.
1. Managed MPI security groups and placement groups are never reaped
A single region of the dev account had accumulated 19 spawn-mpi-* security groups and 9 placement groups, all orphaned:
spawn-mpi-e2e-mpi-982369000 spawn-mpi-e2e-mpi-852789000
spawn-mpi-e2e-mpi-622276000 spawn-mpi-e2e-mpi-325891000
spawn-mpi-e2e-mpi-936579000 spawn-mpi-e2e-mpi-973261000
spawn-mpi-e2e-mpi-351237000 spawn-mpi-e2e-mpi-149201000
spawn-mpi-e2e-mpi-17169000 spawn-mpi-e2e-mpi-955058000
spawn-mpi-e2e-mpi-9217000 spawn-mpi-mpi-fixed
spawn-mpi-mpi-final spawn-mpi- ← see (2)
… plus 5 from this session
Most predate this session — the e2e-mpi-* ones are from CI e2e runs — so nothing has ever cleaned them up. All 19 deleted without error once no instance referenced them, confirming they were pure orphans.
Neither is billable, which is why this went unnoticed, but both are real:
- Security groups have a hard per-VPC quota (default 2500, but the rules quota and per-ENI limits bite sooner). An account running MPI e2e tests on a schedule accumulates these indefinitely until a launch starts failing for a reason that looks nothing like the cause.
spawn reaperreaps instances. Nothing reaps the scaffolding spawn creates around them. This is exactly the "who reaps the reapers" gap already noted for lambdas, roles, rules, alarms and the auto-createdspawn-results-*buckets.
The placement-group cleanup that does exist (cleanupAbandonedPGs) is best-effort and deferred, and it loses the race on every failed cohort:
⚠️ could not delete abandoned placement group spawn-mpi-verifydrain-us-east-1a:
InvalidPlacementGroup.InUse
It ran while instances were still shutting down. Termination is asynchronous, so a single immediate attempt will essentially always fail. It needs a short retry/backoff, or to be handed to the reaper.
Suggested shape: tag both resource kinds (spawn:managed=true, spawn:purpose=mpi-cluster — the SG already carries these) and have the reaper sweep tagged SGs and PGs with no referencing instance, on the same pass that reaps instances. That reuses the existing authority rather than adding a second cleanup path.
2. --mpi without --job-array-name creates a security group, then fails validation
$ spawn launch verify --instance-type c5n.9xlarge --count 2 --mpi --efa …
✅ Setting up IAM role (580ms)
{"operation":"create_security_group","instance_id":"spawn-mpi-","result":"success",
"additional_data":{"security_group_id":"sg-05f971c6dd1d26daf"}}
--mpi requires --job-array-name
Two problems in four lines:
- An AWS resource is created before the arguments are validated. The launch then aborts and leaves the group behind. Argument validation must happen before anything is created — spawn gets this right elsewhere (
--mpion a non-cluster-capable instance type is refused up front, before spending, with a helpful message). - The group is named
spawn-mpi-— the empty job-array name interpolated into the template. Every such launch reuses that single group across unrelated clusters, so onespawn-mpi-group becomes a shared, self-referential all-traffic group for any future MPI launch that also skips the name. After --mpi --efa: auto MPI security group is TCP-only, so EFA cannot pass traffic; and it silently overwrites --security-group-ids #659 that group allows all protocols between its members, which makes accidental sharing worse than it was.
A name that is structurally impossible to collide on, or refusing the empty case, fixes (2); moving validation ahead of resource creation fixes (1).
Context
Both found while verifying #659 and #668 on real c5n.9xlarge and c6i.large launches. Related: #683 (the failed-cohort drain never terminated anything) and #684 (--mpi has never worked end-to-end, so these groups were all created for launches that could not have succeeded).
Activity
fix(mpi): retry the placement-group delete after a cohort drain (#685)
fix(mpi): delete a placement group in the region it was created in (#685
feat(cleanup): discover and reap orphaned placement groups (#685)
fix(mpi): stop leaking security groups and placement groups on a reje…
feat(launch): warn when an instance is too small to enforce its own T…
scttfrdmn commentedon Oct 5, 2026
#706 is merged. Four distinct defects turned out to be behind this, three of which I only found while fixing the first — recording the split so what remains is clear.
Merged
1. Ordering.
validateMPIFlagsran ~286 lines afterensureSecurityGroup, so a launch that was about to be refused created a managed group first. The leftover was namedspawn-mpi-— the prefix with an empty suffix — so every rejected attempt shared one group, which since #659 allows all protocols between its members. Validation needing no AWS call now runs before the first AWS mutation, andCreateOrGetMPISecurityGrouprefuses a suffix-less name outright so the shared-group case is unreachable from anywhere, not just the CLI.2. The placement-group delete lost a race, every time.
TerminateInstancesis asynchronous and EC2 refuses to delete a group with members, so the delete issued right after a drain reportedInvalidPlacementGroup.InUseand moved on. Now retried for up to 60s — short deliberately, because an empty placement group is free, so the only cost of giving up is quota pressure; blocking a CLI exit for minutes over a free resource is the worse trade. On giving up it prints the exactaws ec2 delete-placement-groupcommand.3. The delete ignored the region entirely. Found while fixing (2) and strictly worse than it:
CreatePlacementGrouppinned the client to the launch region,DeletePlacementGrouptook no region and used the default one. A--regioncohort created its group in one region and tried to delete it in another —InvalidPlacementGroup.Unknown, which is not retryable, so the group was abandoned on the first attempt however long the retry waited. The retry in (2) could never have saved those. A same-named group genuinely present in the default region would have been deleted instead. The region is now a required parameter, and a gate rejects any regional EC2 call inpkg/awsbuilt on the default-region config, since that shape is the bug rather than this one instance of it.4. Nothing could see the orphans. spawn tags every placement group
spawn:managed=true, but the Resource Groups Tagging API — whichDiscoverManagedResourcesis built on — does not return placement groups at all. Sospawn orphans,spawn cleanupandspawn resourceswere all blind to them: nine orphans in one region of one account, findable only withaws ec2 describe-placement-groups. They are now scanned separately, like Elastic IPs.Worth stating one judgement in (4): orphan-ness is per group, not per region. An MPI cohort creates one group per AZ it tries, so a cohort that fell back from one AZ to another leaves the abandoned AZ's group genuinely empty while its own instances are running. The region-wide rule used for the shared security group and key pair would have hidden exactly the leak this exists to find.
Still open — and one is a different issue
The MPI security group. Unchanged, and still deliberately durable: it is keyed on
spawn-mpi-<job-array-name>and reused by name across runs, which is whyCreateOrGetMPISecurityGroupis a get-or-create and why #659's rule backfill exists. "Delete it when the cohort finishes" would therefore be wrong — it would force a recreate on every repeat run of the same named array. That makes it reaper territory, and it still needs the two calls I asked for before: whether the sweep lives in the reaper Lambda (a deploy, and the last two reaper deploys each caused an incident) and what age threshold is right.A separate blocker I hit while verifying (4):
spawn orphansreports nothing by default, in an account holding 21 orphans.--minefilters onspawn:iam-user, which spawn never writes to shared infrastructure, so a missing tag does not narrow the result — it empties it. Filed as #708. Until that is resolved, (4) only pays off with--all, which undercuts the fix: the placement-group sweep sidesteps it by not applying the filter at all, but that inconsistency is itself part of what #708 has to settle.Leaving this open on the security-group half.
feat(launch): warn when an instance is too small to enforce its own T…
feat(launch): warn when an instance is too small to enforce its own T…
chore(release): v0.121.0
fix(smoke): clean up the MPI security group and placement group (#713)
fix(cleanup): make --mine mean "not someone else's", and correct two …
feat(reaper): reclaim orphaned security groups and placement groups (#…
feat(reaper): reclaim orphaned security groups and placement groups (#…
feat(reaper): stage #685's net-resource reclamation behind its own sw…
feat(reaper): stage #685's net-resource reclamation behind its own sw…
fix(lambda): cleanup goroutines could never run, so placement groups …
fix: write the creation stamp, and let the reaper collect untagged or…
Make four gates discover their sets instead of listing them
Make four gates discover their sets instead of listing them (#847)
Gate the reaper's YAML IAM copies against pkg/reaperiam; fix the SAM …
Gate the reaper's YAML IAM copies against pkg/reaperiam; fix the SAM …
Gate the reaper's YAML IAM copies against pkg/reaperiam; fix the SAM …
Gate the reaper's YAML IAM copies against pkg/reaperiam; fix the SAM …