Repository navigation
fix(launch): honour AWS_REGION and the instance type when choosing a region (#732) - #744
Merged
Merged
Conversation
scttfrdmn
force-pushed
the
fix/732-region-precedence
branch
from
October 8, 2026 03:23
4e3e27d to
e6a2ec1
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…region
Reported from a demo: with AWS_REGION=us-east-1 set and a configured
default, launches landed in us-west-1 and us-west-2 — neither asked for
— and c8a.large is not offered in us-west-1 at all, so that one died
with EC2's opaque "Unsupported: The requested configuration is currently
not supported".
Two independent causes.
detectBestRegion took instanceType as a parameter and NEVER REFERENCED
IT — the only occurrence of the identifier was the signature, so the
offering check could not happen even in principle. Ranking was measured
TCP latency plus IP geolocation, which also made it unstable: across 21
identical runs from one machine, 20 chose one region and 1 chose
another, because the latency gap between two west-coast endpoints is
smaller than the jitter. Same command, same environment, working region
or broken one by coin flip.
And nothing on this path consulted SPORE_REGION/AWS_REGION or the spore
config, though the root --region flag has always documented that
precedence. `launch` registers its OWN --region, which shadows the root
one and binds a different variable, so the resolved value was never
read. Fixing the resolver alone would have fixed a variable nothing
reads.
Now: --region > SPORE_REGION/AWS_REGION > spore config > auto-detect,
with auto-detect last rather than only. sporeconfig.Resolve already
implements the middle of that chain, so this reuses it.
- Auto-detect filters candidates by DescribeInstanceTypeOfferings, so a
region that cannot run the instance is never a candidate.
- A FAILED offerings call counts as "offered". Throttling, a 5xx, or a
missing ec2:DescribeInstanceTypeOfferings grant say nothing about
availability, and excluding on that basis would silently narrow the
choice — or empty it — for a caller whose only problem is an IAM
policy. Degrading to the old ranking is the safe direction.
- The ranking survives the concurrent filter: results are rebuilt in the
original sorted order, not completion order.
- The chosen region prints WITH its reason ("lowest latency of 3
region(s) offering c8g.xlarge, on your continent").
- If nothing qualifies the launch FAILS and asks for a region, instead
of falling back to us-east-1 — a guess that could itself not offer the
type, turning "could not choose" into a confident wrong choice.
The precedence lives in one resolveLaunchRegion because the
`if region == ""` block it replaces was duplicated at FIVE call sites
(single launch, batch queue, three sweep paths). One of those five also
printed its chosen region before assigning it, so it always announced
the empty string.
Gates confirmed to fail on revert: ignoring env/config (returns
us-west-1 — the exact region from the report), ignoring the instance
type, and excluding a region on an API failure.
The first revert attempt was a build failure rather than a test failure,
which is not a passing gate; redone as a compiling edit.
scttfrdmn
force-pushed
the
fix/732-region-precedence
branch
from
October 8, 2026 03:36
e6a2ec1 to
9fabd9f
Compare
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 #732. The first link in the chain that produced the demo's "5+ minute
hang" — the instance was in a region nobody asked for, which is why its SSH path
was in question at all.
Two independent causes
detectBestRegiontookinstanceTypeand never referenced it. The onlyoccurrence of the identifier was the signature, so the offering check could not
happen even in principle — despite the doc comment claiming it selected a region
"that has the requested instance type available". Ranking was measured TCP
latency plus IP geolocation.
That also made it unstable. Across 21 identical
--estimate-onlyruns fromone machine in one session, 20 chose us-west-1 and one chose us-west-2 — the
demo's observed mix, reproduced. The latency gap between two west-coast endpoints
is smaller than the jitter. And:
So the same command, same environment, no flags, lands in a region where the
launch works or one where it cannot — by coin flip.
Nothing on this path consulted
SPORE_REGION/AWS_REGIONor the sporeconfig, even though the root
--regionflag has always documented thatprecedence.
launchregisters its own--region, which shadows the root oneand binds a different variable — so fixing the resolver alone would have fixed a
variable nothing reads. That is why the flag help is part of this PR.
The fix
--region→SPORE_REGION/AWS_REGION→ spore config → auto-detect, withauto-detect last rather than only.
sporeconfig.Resolvealready implementsthe middle of that chain, so this reuses it rather than re-deriving it.
DescribeInstanceTypeOfferings. A region thatcannot run the instance is never a candidate.
or a missing
ec2:DescribeInstanceTypeOfferingsgrant say nothing aboutavailability, and excluding a region on that basis would silently narrow the
choice — or empty it — for a caller whose only problem is an IAM policy.
Degrading to the old latency-only ranking is the safe direction.
and the slice rebuilt in sorted order, not completion order, which would
otherwise reorder candidates and pick a slower region.
lowest latency of 3 region(s) offering c8g.xlarge, on your continent.falling back to
us-east-1. That default was a guess that could itself notoffer the type, turning "we could not choose" into a confident wrong choice.
One resolver, because the bug was five-way duplicated
The
if region == "" { detectBestRegion(...) }block appeared at five callsites — single launch, batch queue, and three sweep paths. Fixing the precedence
in one would have left four wrong, which is the same shape as the flag shadowing.
It now lives only in
resolveLaunchRegion.While converting them: one of the five printed its chosen region before
assigning it, so it always announced the empty string. Another line that did not
say what it claimed.
Verification
region = "us-west-1", want eu-central-1 from AWS_REGION— andus-west-1is the exact region from the reportfiltered to [us-west-1 us-west-2 us-east-1], want [us-west-2 us-east-1]filtered to [us-west-2], want all three kept — an API failure is not evidence of unavailabilityMy first attempt at the first revert produced a build failure rather than a
test failure. That is not a passing gate — it proves the code references a symbol,
not that a test checks the behaviour — so I redid it as a compiling edit
(
_ = spawnconfig.SharedConfig()), which is when it actually failed.The offerings filter takes an
instanceTypeOffererinterface rather than*aws.Client, specifically so the failure branch — the one with a real judgementcall in it — is testable without AWS.
make check-docscaught the--regionhelp change anddocs-gen/launch.mdisregenerated in this commit.
gofmt,go vet ./...,go test -short ./..., changelog gate,semgrep scan --config=auto --error(0 findings).Chain status
Still open from the same report: #733 (
spawn statusperforms a DNS write),#734 (CPU sentinels), #735 (boot time reported as stopped time), #736 (terminated
instances invisible to lookup), #737 (abort exits 0), #738 (connect quoting).
Why SSH was specifically unreachable in us-west-1 remains unexplained — two
obvious causes are ruled out in #740 — but with this merged, a launch with
AWS_REGIONset no longer goes there to find out.