Skip to content

feat(ec2): On-Demand Capacity Reservations, with the outcome seedable (#891) - #1032

Merged
scttfrdmn merged 2 commits into
mainfrom
feat/capacity-reservations-891
Sep 17, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
feat/capacity-reservations-891

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

CreateCapacityReservation, DescribeCapacityReservations and CancelCapacityReservation reached
the EC2 dispatcher's default arm and answered InvalidAction, although all three are already
authorizable (authz_reference_gen.go:108, :128, :732) — so a consumer could be granted
permission to make a call that does not exist. A consumer whose probe primitive is an immediate
reservation — reserve, read the outcome, cancel — could not run against substrate at all.

What it answers

A reservation is created active, which is what AWS's examples show and what the User Guide states
("the reserved capacity becomes available for use immediately after you create it"), and is
discoverable by ID, by all twelve documented filters, and by tag through DescribeTags. cr-
becomes the sixteenth EC2 ID prefix CreateTags/DeleteTags/DescribeTags resolve, and
TagSpecifications on create uses ec2CheckTagSpecificationTypes + ec2LaunchTagsForResource
together, so a specification scoped to anything else is refused rather than silently dropped.

Seeding, and why the seed has two halves

The reason a consumer reserves capacity is that capacity is finite, so the observation worth testing
is the one where the request does not succeed — and a capacity failure has two documented
observable shapes
: the call fails with a code from EC2's error tables, or it succeeds and the
reservation reports a non-nominal state (AWS's own words for failed are "A request can fail due
to request parameters that are not valid, capacity constraints, or instance limit constraints").
Which of the two AWS produces for a given cell is undocumented, so POST/DELETE /v1/ec2/capacity-reservation-outcomes seeds one rather than substrate choosing; a seed naming both
is refused.

A seed is scoped to an (instance type, Availability Zone) pair — the pair a consumer treats as one
capacity cell — with either half omittable to mean "every", and the most specific scope carrying a
seed decides
: cell, then type in any zone, then any type in the zone, then wildcard. Type before
zone is substrate's ordering, since a seed naming an instance type is the narrower claim.

Five codes are seedable and a sixth is refused rather than defaulted, because the HTTP class is the
half substrate cannot derive. Five of the thirteen state values are seedable; a seeded state
survives into every later describe, unlike a seeded error, which prevents the create from writing
anything at all.

Decisions recorded rather than guessed

  • EndDateType is inferred, not defaulted. AWS publishes no Default: line and forbids exactly
    two combinations, so an EndDate alone infers limited and no EndDate infers unlimited.
    Defaulting to unlimited would turn a request naming only an EndDate, which nothing forbids,
    into the second refusal.
  • A future-dated reservation is refused, not answered falsely. StartDate and
    CommitmentDuration answer Unsupported/400: eight of the state member's thirteen values exist
    only for a future-dated reservation or a Capacity Block, and answering active to a request for
    capacity two days out would be a false observation with nothing in it to tell a caller the request
    was not modelled.
  • Expiry is derived at observation time from the simulated clock, per endDate's own sentence,
    so it is assertable without wall-clock dependence — and only an active reservation expires,
    since reporting expired for a seeded failed one would lose the outcome the test seeded.
  • An untagged reservation omits tagSet. No sample response exists for any of the four pages, so
    an unwritten member follows the shape its neighbours follow; this needs ec2TagSetXML's
    pointer-to-wrapper shape, because xml:"tagSet>item,omitempty" writes the parent anyway.
  • IncorrectState on a second cancel is substrate's reading. AWS publishes no code for
    cancelling from a non-cancellable state, and IncorrectState is what substrate already answers for
    this shape on a volume and a snapshot.
  • The ID-list/MaxResults combination is refused via ec2RefuseIDsWithMaxResults, the
    service-wide rule seven other paginating EC2 describes already apply, checked before the ID list's
    own syntax.

Provenance

InvalidCapacityReservationId.NotFound and .Malformed are in EC2's client-error table (the casing
is AWS's: Id with a lowercase d). InsufficientInstanceCapacity and RequestLimitExceeded are
in the server table, so they answer a 500-series status although a consumer reads the first as a
capacity signal — answering 400 would let retry logic pass here and fail in production. The exact
numbers are unverified: neither page assigns one, only a class. The same page contradicts itself
once, writing the throttle code as Client.RequestLimitExceeded in prose while listing
RequestLimitExceeded in the server table.

Verification

gofmt/go build/go vet clean, golangci-lint run ./... 0 issues, make test and
GOTOOLCHAIN=go1.26.6 make test pass, coverage 85.1% emulator / 84.6% total (baseline 85.0% /
84.6%), docs-reference/docs-reference-check/docs-versions/authz-reference-check pass, the
Docusaurus build passes, and the e2e suite passes.

Closes #891.

…#891)

CreateCapacityReservation, DescribeCapacityReservations and
CancelCapacityReservation reached the dispatcher's default arm and answered
InvalidAction, so a consumer whose probe primitive is an immediate reservation
— reserve, read the outcome, cancel — could not run against substrate at all.

A reservation is created active, discoverable by ID, by all twelve documented
filters, and by tag through DescribeTags (no tag filter is published for this
operation, and cr- becomes the sixteenth EC2 ID prefix CreateTags/DeleteTags/
DescribeTags resolve).

A capacity failure has two documented observable shapes — a code from EC2's
error tables, or a success whose reservation reports a non-nominal state — and
which one AWS produces for a given cell is undocumented, so
POST/DELETE /v1/ec2/capacity-reservation-outcomes seeds one rather than
substrate choosing. A seed naming both is refused. Seeds are scoped to an
(instance type, Availability Zone) cell with either half omittable, and the
most specific scope carrying a seed decides. Two of the five seedable codes
answer a 500-series status because EC2's errors-overview page puts them in its
server table; the exact number is unverified, since neither page assigns one.

EndDateType is inferred rather than defaulted, expiry is derived at observation
time from the simulated clock, and a future-dated reservation (StartDate or
CommitmentDuration) is refused with Unsupported rather than answered falsely —
eight of the state member's thirteen values belong to a future-dated
reservation or a Capacity Block, neither of which substrate models.

Nothing consumes a reservation, so availableInstanceCount equals
totalInstanceCount for its whole life; ClientToken is accepted and inert.
DescribeCapacityReservations refuses an ID list alongside MaxResults, the
service-wide rule seven other paginating EC2 describes already apply.

Closes #891.
The three prose records overstated the unmodelled part: nothing consumes a
reservation, but a cancel does release its capacity, so availableInstanceCount
equals totalInstanceCount for as long as the reservation holds capacity rather
than for its whole life.
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.81898% with 28 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/ec2_capacity_reservations.go 95.32% 16 Missing ⚠️
emulator/ec2_capacity_reservation_control.go 86.66% 12 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 020b56e into main Sep 17, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/capacity-reservations-891 branch September 17, 2026 16:44
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.

EC2: On-Demand Capacity Reservation API (Create/Cancel/DescribeCapacityReservations)

1 participant