Skip to content

--cost-limit is enforced against a fabricated rate: an $8 cap on g6e.xlarge does not fire until $74 #533

Closed

Description

@scttfrdmn

Summary

--cost-limit is not enforced against the instance's real on-demand rate. It is enforced
against whatever landed in the spawn:price-per-hour tag at launch, and that tag falls back
to libs/pricing's static family-estimate table whenever the AWS Pricing API call fails.

The fallback under-reports every current-generation family, so the cap silently becomes a
much larger cap. Measured on us-west-2 today: a g6e.xlarge launched with
--cost-limit 8 does not terminate until $74.44 of real spend.

And the Pricing API call is expected to fail for a least-privilege caller, because
spawn's own onboarding policy does not grant pricing:GetProducts — so the fallback is
the default path, not the edge case.

This is the same defect as spore-host/truffle#114 ("static fallback returns a plausible wrong
price ($0.20/hr) instead of an error") and #447 (stale hardcoded GPU prices
removed from the slurm path). Both are closed. This path still has it, and unlike those two
it is on the enforcement side, so the failure mode costs money rather than misinforming.

The chain

  1. pkg/aws/client.go:379-387 — at launch, if PricePerHour == 0, try the Pricing API;
    on failure use the static table. The comment already says "Fall back to static table only
    as a last resort", which is the right instinct; the problem is what the last resort returns.

    if launchConfig.PricePerHour == 0 {
        if price := LookupEC2OnDemandPrice(ctx, launchConfig.Region, launchConfig.InstanceType); price > 0 {
            launchConfig.PricePerHour = price
            log.Printf("pricing: %s in %s = $%.4f/hr (from AWS Pricing API)", ...)
        } else {
            // Fall back to static table only as a last resort
            launchConfig.PricePerHour = pricing.GetEC2HourlyRate(launchConfig.Region, launchConfig.InstanceType)
            log.Printf("pricing: %s in %s = $%.4f/hr (from static table — API unavailable)", ...)
        }
    }
  2. pkg/aws/tags.go:247-248 — that value is stamped onto the instance as
    spawn:price-per-hour.

  3. pkg/provider/ec2.go:518-520 — spored reads the tag back into config.PricePerHour.

  4. pkg/agent/agent.go:466 — the cap fires on
    accumulatedComputeCost() >= CostLimit, where accumulatedComputeCost()
    (agent.go:689) is PricePerHour × totalCompute.Hours().

So the cap's units are "tag-dollars", not dollars. cost_limit / tag_rate is the real hour
budget; multiply by the true rate to get the real dollar ceiling.

Why the fallback is wrong for everything current-gen

libs/[email protected] GetEC2HourlyRate (ec2.go:159-178) checks a literal EC2Pricing
map — 15 entries for us-west-2, newest GPU g5.xlarge — then falls through to
estimatePriceByFamily (ec2.go:183-251):

base, ok := basePriceLarge[family]
if !ok { base = 0.10 }
multiplier, ok := sizeMultiplier[size]
if !ok { multiplier = 2.0 }   // default to xlarge
return base * multiplier

basePriceLarge has 22 families, newest GPU p4d. No g6, g6e, p5, p5e, p6, no
c7g/c8g/m8g/r8g, no c7gn. Any of those gets $0.10 × multiplier.

Measured against pricing:GetProducts for us-west-2 Linux/Shared/NA/Used, 2026-08-19:

Instance type GetEC2HourlyRate Real on-demand Error Effect on --cost-limit 8
c6i.large $0.0850 $0.0850 exact — see note $8.00
c8g.8xlarge $1.6000 $1.27616 1.25× over $6.38 (fires early)
g6e.xlarge $0.2000 $1.86100 9.3× under $74.44
p5.48xlarge $9.6000 $55.04000 5.7× under $45.87

Note on c6i.large: that is not a table hit either. c6i.large also reaches
estimatePriceByFamily, where basePriceLarge["c6i"] = 0.085 and sizeMultiplier["large"] = 1.0
happen to give the right answer. The family estimate is right for one older x86 family at one
size, which makes the mechanism look sound when spot-checked with a cheap CPU instance.

Two things make this hard to catch from the outside:

  • The error inverts sign by family. Graviton over-counts (cap fires early — annoying but
    safe); GPU under-counts (cap fires late — the expensive direction). A single spot-check
    cannot tell you which side you are on.
  • The output does not distinguish a quoted price from a fabricated one. spawn status
    shows a cost limit that reads as set. The only signal is the (from static table — API unavailable) line in the launch log, which is a log.Printf on the launching host, not
    part of the instance's recorded state and not surfaced to anyone reading spawn status
    later.

The IAM gap is what makes this the default path

LookupEC2OnDemandPrice (pkg/aws/pricing.go:58) calls pricing:GetProducts. The onboarding
policy spawn onboard attaches (cmd/onboard.go:198-206) grants:

ec2:RunInstances, ec2:DescribeInstances, ec2:DescribeInstanceStatus, ec2:DescribeImages,
ec2:DescribeSubnets, ec2:DescribeSecurityGroups, ec2:DescribeVpcs, ec2:DescribeKeyPairs,
ec2:CreateTags, ec2:TerminateInstances, ec2:StopInstances, ec2:StartInstances,
ec2:DescribeSpotPriceHistory, servicequotas:GetServiceQuota, servicequotas:ListServiceQuotas,
ssm:StartSession, ssm:TerminateSession, ssm:ResumeSession

No pricing:*. ec2:DescribeSpotPriceHistory is granted — the spot price API — but not the
on-demand pricing API that this code path needs. So a caller onboarded by spawn's own tooling
takes the fabricated branch on every launch, and --cost-limit never means what it says.

Whatever the fix is for the rate, pricing:GetProducts should probably be added to that
policy. pricing is a global read-only service; the action carries no resource scoping.

Repro

Any type absent from basePriceLarge will do, and no launch is needed to see the rate:

pricing.GetEC2HourlyRate("us-west-2", "g6e.xlarge")   // 0.20
pricing.GetEC2HourlyRate("us-west-2", "p5.48xlarge")  // 9.60

End to end, with a principal lacking pricing:GetProducts:

spawn launch capcheck --instance-type g6e.xlarge --region us-west-2 --cost-limit 8 --ttl 1h
# launch log: pricing: g6e.xlarge in us-west-2 = $0.2000/hr (from static table — API unavailable)
aws ec2 describe-tags --filters Name=resource-id,Values=<id> \
  --query "Tags[?Key=='spawn:price-per-hour'].Value"
# ["0.200000"]

0.20 × 372.2h = $74.44 before agent.go:466 fires. The --ttl 1h is what actually bounds
that instance — the cost limit contributes nothing.

Suggested fix

Follow truffle#114's resolution: a missing rate is an error, not a family guess. Concretely:

  1. Delete estimatePriceByFamily, or gate it behind an explicit opt-in that is never reachable
    from an enforcement path. A per-vCPU guess is a reasonable thing to show a human next to the
    word "estimate"; it is not a basis for a termination decision.
  2. When LookupEC2OnDemandPrice fails and --cost-limit was requested, fail the launch
    with the IAM action named. Silently downgrading an enforced cap to a decorative one is the
    part that costs money.
  3. When no cap was requested, leave spawn:price-per-hour unset rather than fabricated.
    agent.go:466 already guards on PricePerHour > 0, so an unset tag disables the cap
    cleanly instead of arming a wrong one, and cmd/task.go:142 can report "rate unknown"
    instead of a fiction.
  4. Add pricing:GetProducts to the onboarding policy.
  5. pricing_test.go:69-70 currently asserts the fabrication as intended behaviour
    ({instanceType: "unknown.xlarge", expected: 0.2}). That case should become "returns an
    error / zero", or the test locks the bug in.

The same table also feeds three display surfaces

Not filed as its own issue, so that this one is not held up behind a cosmetic fix — but worth
knowing while you are in this code, because a fix here probably covers all four call sites:

Call site Surface
cmd/launch_single.go:298 --estimate-only's "On-demand:" and "TTL cost:" lines
pkg/cost/cost.go:257 spawn cost compute cost
cmd/service.go:196 spawn service's "Rate:" and "Max cost:" lines
pkg/aws/client.go:385 the spawn:price-per-hour tag → --cost-limit, i.e. this issue

Measured, same account and day:

$ spawn launch estcheck-g6e --instance-type g6e.xlarge --region us-west-2 --ttl 4h --estimate-only
💰 Cost estimate for g6e.xlarge in us-west-2
   On-demand:  $0.2000/hr
   TTL cost:   $0.80 (4 hr)

Real 4-hour TTL cost: $7.44. spawn service prints the same figure under the label
Max cost:, which reads as a bound rather than a guess.

One related dead branch: launch_single.go:299-301 has an honest
"pricing data unavailable" message, but GetEC2HourlyRate never returns 0 — even a string
with no . in it gets 0.10 (ec2.go:185-187), and an unknown region silently uses
us-east-1 rates (ec2.go:166-169) instead of saying so. The one branch that would tell the
truth is unreachable precisely because the fallback guarantees a plausible number.


Verified against spawn 0.100.4 (9abea1a) and libs v0.43.3 (64f254f) on 2026-08-19.
Rates from aws pricing get-products, us-west-2, Linux/Shared/NA/Used.

Activity

  1. scttfrdmn commented on Aug 20, 2026

    @scttfrdmn
    ContributorAuthor

    Filed the deferred display half as #543 — the "not filed as its own issue, so that this one is not held up behind a cosmetic fix" note above, on the theory that a fix here would cover all four call sites. It didn't: this issue's fix landed on the enforcement side (pkg/aws/pricing.go resolvePricePerHour → truffle), and cmd/launch_single.go:298 / cmd/service.go:196 / pkg/cost/cost.go:257 still call libs/pricing.GetEC2HourlyRate directly. #543 adds two call sites this table missed (libs/pricing/estimator.go:67 via EstimateSweepCost, feeding both the sweep --estimate-only rows and the --budget comparison).

    Two things in #543 that change the priority rather than just restating this one:

    • The half-fix inverted the direction of the harm. Estimate and enforcement now disagree by 38× on c8g.metal-48xl, and the wrong one is the one a human reads. Sizing --cost-limit from a $4.00/20h estimate gives a cap that fires at 39 minutes against the true $7.6570/hr. Before the fix that command overspent silently; now it terminates early silently.
    • A second, larger mechanism. Every case measured here missed on basePriceLarge (unknown family → 0.10). metal-48xl also misses sizeMultiplier, which has only "metal": 48.0 — so it takes the 2.0 // default to xlarge branch and a 192-vCPU box is priced as a 4-vCPU one. That term is 48× low on its own and is scale-free: it stays 48× low for any family later added to basePriceLarge.

    Also: this one was not the IAM gap. The principal could read the Price List — the same launch stamped spawn:price-per-hour=7.656960 correctly seconds later. launch_single.go:298 never asks.

  2. scttfrdmn commented on Oct 1, 2026

    @scttfrdmn
    ContributorAuthor

    Verified fixed on main — closing. Recording the evidence, since the fix landed across several changes rather than one commit referencing this issue.

    The report had three parts, and all three are addressed.

    1. The cap is no longer enforced against a fabricated rate

    pkg/aws/pricing.go — spawn no longer looks up or guesses a price itself. resolvePricePerHour asks truffle (the suite's pricing authority), and crucially:

    If truffle cannot determine a price (neither a live Price List lookup nor its own static-table fallback succeeds) and the launch requested a --cost-limit, the launch fails outright: a cost limit that cannot be priced cannot be enforced, and silently leaving it unenforced is worse than refusing to launch.

    So the failure mode this issue describes — a cap quietly becoming a much larger cap — is now a refused launch instead. Wired in at pkg/aws/client.go:471, inside Launch.

    2. A missing price means "no cap", never a guessed one

    pkg/agent/agent.go:477:

    if a.config.CostLimit > 0 && a.config.PricePerHour > 0 {

    With no resolvable price, PricePerHour stays 0 and spored enforces nothing rather than enforcing against fiction. That only holds because of part 1 — the combination of "0 means unenforced" and "a --cost-limit launch refuses to proceed unpriced" is what closes the hole.

    3. pricing:GetProducts is granted, so the fallback is no longer the default path

    This issue's sharpest point was that the Pricing API call was expected to fail for a least-privilege caller, making the bad fallback the normal path. cmd/onboard.go:203 now grants it:

    {"Effect":"Allow","Action":["ec2:DescribeSpotPriceHistory","servicequotas:GetServiceQuota","servicequotas:ListServiceQuotas","pricing:GetProducts"],"Resource":"*"}
    

    Existing onboarded accounts need to re-run spawn onboard to pick it up (noted in the CHANGELOG at the time).

    Related, and still open at the root

    The underlying fabrication in libs/pricing — the thing that made the fallback dangerous rather than merely approximate — is spore-host/libs#29, and it was still live. GetEC2HourlyRate returned float64 with no error channel and invented a price for any family absent from its table, which is every GPU family newer than p4d: measured $0.80 for g7e.4xlarge against a real $3.9982, and $9.60 for p5e.48xlarge, a type AWS publishes no on-demand price for. spore-host/libs#50 removes that.

    spawn's enforcement path no longer touches it either way — it goes through truffle, whose staticOnDemandPricer already did exact-match-or-error (truffle#114). The one place spawn still consumed the fabricated rates is the sweep cost preview (cmd/launch_sweep.go), which is a display and --budget-warning surface rather than an enforcement one; that gets fixed in the follow-up to libs#50.

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