Skip to content

Purchase a Capacity Block for ML (PurchaseCapacityBlock) — the paid reservation write op #217

Closed

Description

@scttfrdmn

Summary

Reserving (purchasing) an EC2 Capacity Block for ML is not implemented anywhere in spore.host. Per the maintainer decision, the purchase — a paid write operation — belongs in spawn (not truffle, which stays read-only; see truffle#66 and the discovery issue truffle#67).

This is the middle step of the three-part Capacity Block flow:

  1. Find offerings → truffle#67 (DescribeCapacityBlockOfferings, read-only).
  2. Purchase the chosen offering → this issue (PurchaseCapacityBlock, spawn).
  3. Launch into the reservation → spawn#216 (RunInstances + CapacityReservationSpecification / MarketType=capacity-block).

What's needed

A new spawn command to purchase a Capacity Block from an offering id (as surfaced by truffle#67):

⛔ Cost-safety — HARD REQUIREMENTS (not optional)

A Capacity Block is a large, upfront, NON-REFUNDABLE charge (the full block duration is billed at purchase — thousands to tens of thousands of dollars). This is the single most expensive action in the entire toolset. The following are mandatory, non-negotiable acceptance criteria — the PR does not merge without them:

1. Typed-confirmation gate (REQUIRED)

A y/n prompt is NOT sufficient. The user MUST type an explicit confirmation string that cannot be hit by accident or muscle-memory. Concretely:

  • Print the full purchase details (instance type, count, AZ, start/end, duration, total upfront non-refundable price, purchasing account/identity).
  • Then require the user to type a specific phrase to proceed — e.g. the exact total price (Type the total price to confirm: 12480.00) or a phrase like purchase <offering-id> / I UNDERSTAND THIS IS NON-REFUNDABLE. Anything other than an exact match aborts with no purchase.
  • This is stdin-typed input read at purchase time — NOT a flag, NOT a pre-answerable prompt. (A pre-supplied --yes must NOT bypass the typed gate; see automation below.)
  • Refuse to proceed on a non-interactive/non-TTY stdin unless the explicit automation escape hatch below is present — never auto-confirm a five-figure spend because stdin happened to be a pipe.

2. Dry-run mode (REQUIRED)

  • A --dry-run flag that performs the full flow — resolve/validate the offering, compute and display the total price and all purchase details — but calls no write API and exits without purchasing.
  • Recommended: make the dry-run output identical to the confirmation screen, so a user can preview exactly what they'll be asked to confirm.

3. Re-validate immediately before purchase (REQUIRED)

Offering availability and price can change between discovery and purchase. Immediately before calling PurchaseCapacityBlock, re-DescribeCapacityBlockOfferings (or validate the id) and abort if the price/terms moved from what the user is confirming — never purchase at a price the user didn't see and type.

Strongly recommended (decide during implementation)

  • Automation escape hatch: if a non-interactive purchase is ever needed (CI/scripted), gate it behind an explicit, loud, separate flag (e.g. --confirm-price <exact-amount>) that must match the re-validated price exactly — so even automation cannot buy at an unexpected price. Default behavior with no TTY = refuse.
  • Authorization gating: consider the spore.host signing-key / authorization model used for other destructive ops; surface the purchasing account in the confirmation.
  • Audit: log the purchase (offering id, resulting reservation id, price, identity, timestamp) via the existing audit logger — both the attempt and the outcome.

This is the inverse of the project's "everything dies / never leak" cost discipline: here the risk is an intended but very large, irreversible spend, so the guardrail is an unmissable, typed, re-validated confirmation — not reaping.

Out of scope

  • Discovery (truffle#67) and launch-into-reservation (spawn#216) are separate.
  • PurchaseCapacityBlockExtension (extending an existing block) could be a follow-up.
  • truffle stays read-only — do NOT add a purchase path there.

Tests / docs

  • Unit test the argv/PurchaseCapacityBlockInput construction.
  • Unit test the typed-confirmation gate: a wrong/empty/y input ABORTS without calling the purchase API; only the exact required phrase proceeds; non-TTY stdin refuses by default.
  • Unit test --dry-run: shows price + details, issues zero write calls.
  • No real purchase in tests — substrate can't model a billed purchase, and CI must never issue a real PurchaseCapacityBlock.
  • Any live validation is inherently expensive and non-refundable — gate behind explicit human action, never automated. Document this loudly in README + CHANGELOG.

Refs

truffle#67 (offerings discovery — provides the offering id), spawn#216 (launch into the resulting reservation), truffle#66 (why purchase is here, not in read-only truffle).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions