Skip to content

pricing: stop fabricating EC2 prices; make the sweep estimator's pricing source injectable - #50

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/29-no-fabricated-prices
Oct 1, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/29-no-fabricated-prices

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #29.

The defect

GetEC2HourlyRate returned a bare float64 and never failed. On a miss it invented a price through three silent substitutions:

pricing/ec2.go (before) behaviour
unknown region silently used us-east-1's prices
type not in table fell through to estimatePriceByFamily
unknown family base = 0.10
unknown size multiplier = 2.0 ("default to xlarge")

Since the table has no GPU family newer than p4d, every current-generation accelerator took that path. Reproduced against libs v0.49.0 before changing anything:

us-east-1  g7e.4xlarge        $0.8000/hr      real $3.9982   5.0x low
us-east-1  p5.4xlarge         $0.8000/hr      real $6.88     8.6x low
us-east-1  g6e.12xlarge       $2.4000/hr      real $10.49    4.4x low
us-east-1  p6-b200.48xlarge   $9.6000/hr      real $113.93  11.9x low
us-east-1  p5e.48xlarge       $9.6000/hr      AWS publishes NO on-demand price
sa-east-1  c5.xlarge          $0.1700/hr      silently us-east-1's price
us-east-1  bogus.xlarge       $0.2000/hr      unknown family x xlarge
us-east-1  t3.unknown         $0.1664/hr      unknown size -> xlarge multiplier

Every one carried err == nil, so nothing downstream could tell a real rate from an invented one — which is what makes this worse than returning no price at all.

After

us-east-1  g7e.4xlarge        ERROR: no static price for "g7e.4xlarge" in "us-east-1" (not in the static table; use truffle for a live price)
sa-east-1  c5.xlarge          ERROR: no static price table for region "sa-east-1" (static table covers 8 regions; use truffle for a live price)
us-east-1  c5.xlarge          $0.1700/hr      <- control: in the table, still works

Changes

pricing/ec2.go — GetEC2HourlyRate(region, instanceType) (float64, error), exact match only. estimatePriceByFamily deleted. EC2Pricing is now documented as a deliberately small offline subset that must not be grown into a pricing database (a hand-maintained price table is stale the day it is written, and invisibly so), naming truffle as the suite's pricing authority and stating outright that no GPU family newer than p4d is covered.

pricing/estimator.go — EstimateSweepCost(params, rate RateResolver). libs cannot import truffle (truffle imports libs), so the caller supplies the pricing authority; nil gives StaticRateResolver, which is the old offline behaviour made honest. CostEstimate gains PricedRows, UnpricedRows ("type@region", deduped and sorted) and Partial(). An unpriceable row is excluded and named, never valued at a guess and never silently at $0 inside a total that reads as complete — and Display()/DisplayCompact() label such a total as a FLOOR.

A mixed sweep is deliberately not an error: it still reports what it knows, provided it also reports what it doesn't.

Tests

  • TestEstimatePriceByFamily deleted — it asserted the fabrication outright ("Unknown family (uses default)" → 0.2 // 0.10 * 2.0), so it was locking in the bug.
  • TestGetEC2HourlyRateErrorsRatherThanGuessing — the regression guard. Each case carries the value the old code actually returned (measured, not assumed) and fails if that value ever comes back.
  • TestEstimateSweepCostUsesInjectedResolver — proves the seam is used rather than the static table being consulted behind the caller's back (the stub returns $10/hr, unlike any table value).
  • TestEstimateSweepCostPartialWhenUnpriceable — mixed sweep: only the priceable row counts toward compute, the unpriceable one is deduplicated and named, Partial() is true, and both display forms disclose the shortfall.
  • Existing TestEstimateSweepCost cases pass nil and are asserted not partial, since every type they use is in the table.

gofmt, go vet ./..., go build ./..., go test ./... all clean.

Consumers

Only EstimateSweepCost called GetEC2HourlyRate in-repo. truffle deliberately avoids it and reads EC2Pricing directly through its own exact-or-error staticOnDemandPricer (truffle#114), so truffle and lagotto are unaffected. spawn's sweep preview is the one live consumer and is updated in a follow-up PR once this is tagged.

Breaking an exported symbol → MINOR per CLAUDE.md (pre-1.0): suggest v0.50.0. The break is the point — it forces callers to confront "I can't price this" instead of receiving a plausible wrong number. Known external consumer: scttfrdmn/cultivar, which reported this.

… pricing source injectable

GetEC2HourlyRate returned a bare float64 and never failed, inventing a price
through three silent substitutions: an unknown region borrowed us-east-1's
prices, an unknown instance type fell through to a per-family-size estimate, and
within that an unknown family used a flat $0.10/vCPU-hr base and an unknown size
the xlarge multiplier.

For modern accelerators the invented number was 4-12x low and carried err == nil,
so nothing downstream could tell it from a real rate: g7e.4xlarge quoted at $0.80
against a real $3.9982, p6-b200.48xlarge at $9.60 against $113.93, and
p5e.48xlarge at $9.60 for a type AWS publishes no on-demand price for.

GetEC2HourlyRate now returns (float64, error) and matches exactly on
(region, instanceType). estimatePriceByFamily is deleted, as are the tests that
asserted its output. EC2Pricing is documented as a deliberately small offline
subset that is not to be grown into a pricing database, with truffle named as the
suite's pricing authority for live rates.

EstimateSweepCost now takes a RateResolver so the caller supplies that authority
(libs cannot import truffle, which imports libs). Rows it cannot price are
recorded in CostEstimate.UnpricedRows, excluded from the totals, and surfaced by
Display/DisplayCompact as a FLOOR rather than folded invisibly into a total that
reads as complete.

Refs #29
@codecov

codecov Bot commented Oct 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 3a41f64 into main Oct 1, 2026
6 checks passed
@scttfrdmn
scttfrdmn deleted the fix/29-no-fabricated-prices branch October 1, 2026 02:25
scttfrdmn added a commit that referenced this pull request Oct 1, 2026
Promote Unreleased to [0.50.0] and update compare links.

MINOR (pre-1.0 breaking, per CLAUDE.md): pricing.GetEC2HourlyRate and
pricing.EstimateSweepCost both changed signature to stop fabricating EC2 prices
(#29, PR #50).
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.

pricing/ec2.go silently fabricates GPU prices (4–12× low) for every modern accelerator family — estimator returns err==nil

1 participant