Skip to content

Record the spot price at launch without re-describing the new instance (#1442) - #1451

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1442-spot-price-record
Oct 31, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1442-spot-price-record

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1442

Root cause

recordLaunchSpotPrice re-describes the instance only when the instance it is handed lacks a pricable PlatformDetails or a placement zone. Every one of the 99 failures in the owner's ~/.spawn/spawn.log is describe instance: ... InvalidInstanceID.NotFound, so that branch ran on every spot launch. RunInstances returns the placement but no platformDetails, so the platform was the missing input. The describe that followed hit EC2's post-launch eventual-consistency window, and nothing retried it.

Fix: remove the re-describe from the launch path

  • Platform. An instance's billing platform is its AMI's. Launch already calls DescribeImages on the AMI for the root device (rootDeviceInfoFromAMI). That call now also returns PlatformDetails/Platform (launchInfoFromAMI), so this adds no API call. DescribeImages has no consistency lag against the new instance.
  • Zone. The zone comes from the RunInstances placement, or from LaunchConfig.AvailabilityZone if the response has none.
  • launchedForSpotPrice fills those inputs in before recordLaunchSpotPrice, so a normal spot launch prices the instance with no describe at all.
  • Fallback. If the AMI lookup failed, the re-describe still runs. It now retries InvalidInstanceID.NotFound only, after 1s, 2s and 4s (7s, inside the existing 10s budget). Any other error stops it at once. CurrentSpotPrice (spawn status on old instances) is unchanged and does not retry.

Gates (each watched failing against a revert that compiles)

  • TestLaunch_SpotPriceRecordedWithoutDescribingTheNewInstance runs a real Client.Launch against a wire fake shaped like real EC2: DescribeImages has platformDetails, RunInstances has placement but no platformDetails, and DescribeInstances always returns NotFound. It asserts that no DescribeInstances comes before the spawn:spot-price-per-hour CreateTags, and that the tag is written.
    • Revert: the call site passes result.Instances[0] raw. Result: FAIL, "described instance i-new before recording its spot price" x4, and no tag was sent. The actions were [GetCallerIdentity DescribeImages RunInstances DescribeInstances x4].
  • TestRecordLaunchSpotPrice_RetriesPostLaunchNotFound makes the first describe return NotFound and expects the price to be recorded after 2 counted describes.
    • Revert: pass nil retry delays. Result: FAIL, describes = 1, want 2, and nothing was tagged.
  • TestRecordLaunchSpotPrice_RetryIsBoundedAndNotFoundOnly checks that a persistent NotFound gets 1 + len(delays) describes and no tag, and that UnauthorizedOperation gets exactly one describe.
  • The retry delays are a package variable. Tests zero it and count the calls, with no wall-clock assertions.

Other post-RunInstances describes in the launch path (checked; none share the pattern)

Checks

make check, make lint (0 issues), semgrep scan --config=auto --error ., and make api-snapshot (no change: every new symbol is unexported).

Not live-verified: that RunInstances never returns platformDetails is inferred from the 99/99 log evidence plus the code path, not observed on the wire. The fix records the price either way.

#1442)

The RunInstances response has no platformDetails, so recordLaunchSpotPrice
re-described the instance just launched and hit EC2's post-launch
InvalidInstanceID.NotFound, never retried. Take the billing platform from the
AMI (the DescribeImages call Launch already makes) and the zone from the
response or request, so no re-describe is needed; when one still is, retry
NotFound only, three times within the 10s budget.

Fixes #1442
@codecov

codecov Bot commented Oct 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.50000% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/aws/spotprice.go 85.18% 4 Missing ⚠️
pkg/aws/ebs.go 70.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 1da812b into main Oct 31, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1442-spot-price-record branch October 31, 2026 00:01
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.

Spot price is almost never recorded at launch: recordLaunchSpotPrice hits InvalidInstanceID.NotFound right after RunInstances and does not retry

1 participant