Skip to content

fix: pkg/snipe reports the actual landed AZ, not the requested placement - #123

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/114-snipe-actual-az
Aug 19, 2026
Merged

fix: pkg/snipe reports the actual landed AZ, not the requested placement#123
scttfrdmn merged 1 commit into
mainfrom
fix/114-snipe-actual-az

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Summary

  • pkg/snipe's Result.AvailabilityZone now reports the AZ the instance actually landed in (spawnaws.LaunchResult.AvailabilityZone, read from the real RunInstances response), instead of the requested placement's AZ from the retry loop's variable.
  • Root cause: launchAcrossPlacements (pkg/snipe/snipe.go) returned p.AZ on success — the loop variable holding the REQUESTED placement — rather than result.AvailabilityZone. These coincide whenever a Placement pins a specific AZ (the request forces the match), which is exactly why every existing test passed: they all pin a Placement. The bug only surfaces when Target.Placements is empty and EC2 chooses the AZ itself — a scenario Target.Placements's own doc comment explicitly describes as supported ("Empty = a single AZ-unpinned attempt per round (EC2 chooses the AZ and its default subnet)").
  • Verified the fix is correct against spawn's actual RunInstances response mapping: spawnaws.newLaunchResult (spawn's pkg/aws/client.go) sets LaunchResult.AvailabilityZone directly from instance.Placement.AvailabilityZone in the API response — so it is genuinely the landed AZ, not an echo of the launch config. No live AWS call was needed to confirm this; the mapping is unambiguous in spawn's source.

Closes #114.

Changes

  • pkg/snipe/snipe.go: launchAcrossPlacements returns result.AvailabilityZone instead of p.AZ.
  • pkg/snipe/snipe_internal_test.go:
    • Added TestSnipe_ReportsActualLandedAZWhenEC2Chooses — the regression guard, with no Placements set and a fake provide that returns a landed AZ the request never named.
    • Updated two existing fakes (TestSnipe_AcquiresAfterCapacityRetries, TestSnipe_SubnetPerPlacement) to populate LaunchResult.AvailabilityZone, mirroring a real RunInstances response — previously harmless since the placement AZ was returned regardless, now load-bearing.
  • CHANGELOG.md: [Unreleased] entry under Fixed.

Note

The same bug pattern exists in the legacy pkg/watcher.Spawner.launchAcrossAZs (pkg/watcher/spawner.go:241, returns the requested AZ a rather than result.AvailabilityZone). Left untouched here — issue #114 scopes to pkg/snipe, and per the [0.52.0] CHANGELOG entry watcher.Snipe/Spawner.Snipe have no current callers in this repo (kept as-is rather than rewired). Filing this note here for visibility; happy to open a follow-up issue if wanted.

Verification

  • Confirmed the new test fails without the fix (git stash the source-only change) and passes with it restored.
  • go build ./..., go vet ./..., go test ./... clean from repo root.
  • go build ./..., go vet ./..., go test ./... clean from lambda/capacity-poller (untouched, confirmed still green).
  • golangci-lint run ./pkg/snipe/... — 0 issues.

Test plan

  • CI green

@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

launchAcrossPlacements returned p.AZ (the REQUESTED placement's AZ from the
loop variable) instead of result.AvailabilityZone (the ACTUAL AZ RunInstances
placed the instance in, per spawnaws.LaunchResult). The two coincide when a
Placement pins a specific AZ, which is why this only surfaced when
Target.Placements is empty and EC2 chooses the AZ itself — the scenario
Target.Placements's own doc explicitly supports.

Verified via spawn/pkg/aws/client.go's newLaunchResult: LaunchResult.
AvailabilityZone is read directly from the RunInstances response's
Placement field, so it is genuinely the landed AZ, not an echo of the
request.

Added a regression test (TestSnipe_ReportsActualLandedAZWhenEC2Chooses)
that fails without the fix and passes with it; updated two existing fakes
whose LaunchResult didn't populate AvailabilityZone (harmless before, since
the placement AZ was returned instead, but now load-bearing).

Fixes #114
@scttfrdmn
scttfrdmn force-pushed the fix/114-snipe-actual-az branch from 5965ce7 to 5a5ad02 Compare August 19, 2026 02:29
@scttfrdmn
scttfrdmn merged commit f364aac into main Aug 19, 2026
6 checks passed
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.

pkg/snipe: Result.AvailabilityZone is the REQUESTED placement AZ, not the ACTUAL landed AZ (empty when EC2 chooses)

1 participant