Skip to content

fix(tags): budget tags against AWS's 50-tag limit, and stop emitting duplicate keys - #690

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/477-tag-limit
Oct 4, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/477-tag-limit

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #477. Your measurements reproduced, plus a second launch-breaking bug in the same function that needs only two flags.

#477 as filed

Confirmed. A maximal launch (FSx + EFS + both webhooks + job array + sweep + every lifecycle flag):

sweep params tags vs 50
0 46 4 under
10 54 +4
35 79 +29
60 79 +29

My numbers differ slightly from yours (46 vs 51 with Parameters: nil) — I populated the fields that exist on today's LaunchConfig, and a couple you listed have since moved. The conclusion is unchanged and arguably worse: ten sweep parameters is enough. That is an ordinary sweep, not a pathological one, so this is more reachable than "the maximal-config user".

Your diagnosis of why the 35 was a red herring was exactly right, and the budget approach is what I implemented: parameters emitted last, capped against what the launch actually consumed, in sorted order.

The nondeterminism you flagged is fixed and has its own test. It deserved calling out — the old loop ranged over the map directly, so two members of one sweep could record different points in the parameter space, which makes the spawn:param:* record untrustworthy for exactly the use it exists for.

A second bug in the same function

Setting both --spot-webhook-url and --completion-webhook-url fails the launch. Both blocks emit spawn:webhook-correlation and spawn:webhook-timeout, and EC2 rejects the entire call on a repeated key. Verified against real EC2 with a dry-run:

InvalidParameterValue: Duplicate tag key 'spawn:webhook-correlation' specified.

Two flags, no tag arithmetic. I found it reading the key list while reproducing yours, which is a fair argument for printing the whole list in a test rather than just counting it.

Deduped as a pass over the assembled list rather than by threading a helper through all seven sections, so a section added later cannot forget to use it.

What gets dropped, and why that order

Only parameters. The priority is deliberate, because "truncate something" is not a safe default here:

  • spawn:* lifecycle tags are spored's contract. Dropping spawn:ttl to fit under the limit produces an instance with no TTL enforcement — a silent, open-ended bill. That is strictly worse than a launch that fails loudly, so these are never dropped. There is a test asserting it under absurd pressure (80 user tags + 80 params).
  • --tag is an explicit request. Dropping what the user typed to make room for a derived tag is backwards.
  • spawn:param:* is a convenience record whose authoritative copy is the sweep manifest — so, as you said, a truncated tag set beats a launch that cannot start.

Truncation warns on stderr with the count and the reason, rather than happening silently.

Tests

Five, each confirmed to fail against the old code:

  • limit — restoring the fixed 35 cap fails at 10, 35 and 60 params
  • duplicate keys — removing the dedupe pass fails with both webhook keys named
  • determinism — 12 builds must yield an identical, sorted surviving set
  • user tags survive under maximum parameter pressure
  • functional tags never dropped — spawn:ttl, spawn:cost-limit, spawn:on-complete and friends

Gates

gofmt -l empty, go vet ./..., go test -short ./..., make check-docs, changelog gate, semgrep → 0 findings.

Not hardware-verified, and I don't think it needs to be: the tag-count assertions are pure, and the one behaviour only AWS can confirm — that a duplicate key is rejected — I confirmed with a run-instances --dry-run against real EC2 rather than reasoning about it. make smoke-needed flags pkg/aws/ as hardware-sensitive, and a launch smoke before the next tag would cover the composed path.

Thanks for measuring it rather than reasoning about it, and for porting the fix shape from spawn-ts — having the budget/sorted-order design already proven there made this a much shorter job.

…duplicate keys

The parameter loop capped itself at 35 with a comment claiming that
"stays under AWS 50-tag limit", but counted only the sweep parameters
and ignored the ~45 tags the other sections had already appended. AWS
does not truncate — it rejects RunInstances. Measured on a maximal
launch: 46 tags with no parameters, 54 with ten, 79 with sixty.

Parameters are now emitted last, budgeted against actual usage, and
sorted — the old loop ranged over the map directly, so which parameters
survived depended on Go's randomised iteration order and two members of
one sweep could record different points in the space.

Only parameters are droppable: spawn:* tags are spored's contract
(losing spawn:ttl disables TTL enforcement and bills open-endedly),
--tag is explicit, and spawn:param:* has an authoritative copy in the
sweep manifest. Truncation warns on stderr.

Separately, setting both --spot-webhook-url and --completion-webhook-url
emitted spawn:webhook-correlation and spawn:webhook-timeout twice, and
EC2 rejects the whole call on a repeated key — verified against real
EC2. Two flags, no tag arithmetic needed. Tags are now deduped as a pass
over the assembled list so a future section cannot forget to.

Fixes #477
@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.11111% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/aws/tags.go 91.11% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

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.

buildTags can exceed AWS's 50-tag limit and fail RunInstances outright — a fully configured launch is 51 tags with zero sweep params

1 participant