Repository navigation
fix(cleanup): make --mine mean "not someone else's", and correct two placement-group bugs (#708, #713) - #714
Merged
Merged
Conversation
…placement-group bugs (#708, #713) --- #708 --mine filtered on spawn:iam-user, a tag pkg/aws/tags.go writes only to instances and volumes. Shared infrastructure — security groups, IAM roles and instance profiles, key pairs, log groups, tables — never carries it, and a missing tag reads as "", which never equals a caller ARN. So for those classes the filter did not narrow the result, it EMPTIED it: $ spawn orphans --region us-east-1 No orphaned spawn-managed resources in us-east-1. $ spawn orphans --region us-east-1 --all 27 resource(s) "Nothing to clean" is a believed answer, and it was wrong for as long as those resources existed — the oldest dates from 2026-07-19. The rule is now "not someone else's" rather than "provably mine". Untagged is treated as shared rather than foreign for two reasons: it is the only choice that helps the resources ALREADY out there, since stamping the tag on new resources would leave today's orphans invisible forever; and "mine" is a dubious notion for a security group deliberately shared and reused by name across runs and principals, which is exactly what #685's MPI group is. It also matches what the two separately scanned classes already do — neither addresses nor placement groups apply the filter, because neither carries the tag. orphans now reports how many resources the scope excluded, so "nothing here" can never again be the whole output when it is not the whole story. --- #713, found by running cleanup --dry-run against a real account Two bugs, both mine, and the first corrects a claim I made in #706. I asserted there that the Resource Groups Tagging API does not return placement groups, and built a dedicated scan on that premise. It is false — RGT returns them keyed by group ID. The probe I relied on returned empty because the account had zero placement groups at the time, so it could not distinguish an unsupported type from an absent one. I noted that ambiguity and then asserted the strong version anyway; that is the actual mistake. So every managed group was reported twice — once by id with no state, once by name with one. And the id-keyed copy could not be deleted: EC2's DeletePlacementGroup takes a NAME, so pg-… fails InvalidPlacementGroup.Unknown, which the ignoreNotFound I added then swallowed as SUCCESS. A cleanup in v0.121.0 can report removing a placement group it never touched. A tolerant error check turned a real failure into a clean bill of health, which is the worse half. RGT's placement-group rows are now dropped in favour of the dedicated scan, which supplies both things RGT lacks: the name needed to delete and whether the group still has members. Narrowly scoped to that one type, with a test asserting nothing else is suppressed — hiding a type with no replacement scan would be #708 again. Second: fixing #708 unmasked an over-eager IAM classification. spored-instance-role and spored-instance-profile are created once and reused by every launch, but the only signal IsLikelyOrphan has for IAM is !hasRunningInstance — so an idle account made them orphans and `cleanup --yes` would have deleted spawn's own identity. The broken scope had been hiding them from cleanup entirely, so one bug was concealing the other. Now excluded from both the orphan check and cleanup's removable set, and reported with the reason; per-run spawn-instance-<hash> profiles stay reclaimable, with a test for that direction too. Verified on live data: placement-group rows 6 → 3, total orphans 27 → 25. Every gate confirmed to fail when its fix is reverted.
The MPI leg creates a managed security group and a per-AZ placement group, and teardown terminated the instances and left both behind on every run. Three of each accumulated over one session — a smoke whose purpose is catching leaks was a source of them. Found by 'spawn orphans' once #708 made the default scope work, which is a pointed way to learn it: ec2 placement-group spawn-mpi-smoke22812-us-east-1a empty ec2 placement-group spawn-mpi-smoke85337-us-east-1a empty ec2 placement-group spawn-mpi-smoke87201-us-east-1a empty Teardown now removes both, retrying the placement-group delete for exactly the reason spawn itself has to (#685): TerminateInstances is asynchronous and EC2 refuses to delete a group that still has members. The post-run leak check also asked only about INSTANCES, so it printed 'no instances left behind' over that pile every time. It now checks placement groups and security groups too, and names 'spawn orphans' in the failure so the next step is obvious.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #708. Closes #713.
Option (b) from #708, as decided. The second half is a correction to something I shipped in v0.121.0 — detail below, because one of the bugs was being hidden by the other.
#708 —
--minewas a blackhole, not a filterspawn:iam-useris written by the instance tag builder. Shared infrastructure never carries it, and a missing tag reads as"", which never equals a caller ARN. So for those classes the filter did not narrow — it emptied:The rule is now "not someone else's", not "provably mine". Untagged is treated as shared rather than foreign for two reasons: it is the only choice that helps the resources already out there — stamping the tag on new ones would leave today's orphans invisible forever — and "mine" is a dubious notion for a security group deliberately shared and reused by name across runs, which is exactly what #685's MPI group is. It also matches what
scanAddressesandscanPlacementGroupsalready do, neither of which applies the filter because neither resource carries the tag.orphansnow also prints how many resources the scope excluded, so "nothing here" can never again be the whole output when it is not the whole story.Verified live: 0 → 25 reported by default.
#713 — and then the dry run showed me two bugs I had shipped
Running
spawn cleanup --dry-runagainst a real account to check the above:I was wrong that RGT does not return placement groups
I claimed in #706 — in the PR, the commit, and the v0.121.0 changelog — that the Resource Groups Tagging API does not return placement groups, and built a dedicated scan on that premise. It returns them keyed by group ID:
The probe I relied on returned empty because the account had zero placement groups at the time, so it could not distinguish an unsupported type from an absent one. I noted that ambiguity and asserted the strong version anyway. That is the mistake — the code was a reasonable response to a premise I should not have adopted.
Two consequences. Every group was reported twice (six rows, three groups). And the id-keyed copy cannot be deleted:
DeletePlacementGrouptakes a name, sopg-…failsInvalidPlacementGroup.Unknown— which theignoreNotFoundI added then treats as success. Acleanupin v0.121.0 can report removing a placement group it never touched. The tolerant error check turning a real failure into a clean bill of health is the worse half of this.RGT's placement-group rows are now dropped in favour of the dedicated scan, which supplies both things RGT lacks: the name needed to delete, and whether the group still has members. Scoped to that one type, with a test asserting nothing else is suppressed — hiding a type with no replacement scan would be #708 all over again.
Fixing #708 unmasked an over-eager IAM classification
spored-instance-roleandspored-instance-profileare created once and reused by every launch.IsLikelyOrphan's only signal for IAM is!hasRunningInstance, so an idle account made them orphans — andcleanup --yeswould have deleted spawn's own identity.Latent, not new: the broken scope had been hiding them from cleanup entirely, so one bug was concealing the other. The same change that surfaced 27 genuine orphans also made these two deletable. They are now excluded from both the orphan check and cleanup's removable set, reported with the reason instead.
Per-run
spawn-instance-<hash>profiles must stay reclaimable — there are 12 in the dev account — so there is a test in that direction too, because a guard that over-reached would strand them forever.Verified
Every gate confirmed to fail when its fix is reverted — including the direction tests (another principal's resource still excluded; per-run IAM still reclaimable), since an over-correction here is as bad as the original.
One consequence worth naming
This makes
spawn cleanupmeaningfully more dangerous than it was, because it now works. In an idle account a dry run offers 44 resources where it previously offered the handful that carried the instance tag. The confirmation prompt and--dry-runwere nice-to-haves while the scope was broken; they are now the only thing between a user and 44 deletions. I have not changed those defaults, but it is worth a look.