Repository navigation
Description
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
-
pkg/aws/client.go:379-387— at launch, ifPricePerHour == 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)", ...) } }
-
pkg/aws/tags.go:247-248— that value is stamped onto the instance as
spawn:price-per-hour. -
pkg/provider/ec2.go:518-520—sporedreads the tag back intoconfig.PricePerHour. -
pkg/agent/agent.go:466— the cap fires on
accumulatedComputeCost() >= CostLimit, whereaccumulatedComputeCost()
(agent.go:689) isPricePerHour × 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 * multiplierbasePriceLarge 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 alog.Printfon the launching host, not
part of the instance's recorded state and not surfaced to anyone readingspawn 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.60End 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:
- 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. - When
LookupEC2OnDemandPricefails and--cost-limitwas requested, fail the launch
with the IAM action named. Silently downgrading an enforced cap to a decorative one is the
part that costs money. - When no cap was requested, leave
spawn:price-per-hourunset rather than fabricated.
agent.go:466already guards onPricePerHour > 0, so an unset tag disables the cap
cleanly instead of arming a wrong one, andcmd/task.go:142can report "rate unknown"
instead of a fiction. - Add
pricing:GetProductsto the onboarding policy. pricing_test.go:69-70currently 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
fix: delegate on-demand pricing to truffle instead of fabricating a r…
fix: delegate on-demand pricing to truffle instead of fabricating a r…
scttfrdmn commentedon Aug 20, 2026
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.goresolvePricePerHour→ truffle), andcmd/launch_single.go:298/cmd/service.go:196/pkg/cost/cost.go:257still calllibs/pricing.GetEC2HourlyRatedirectly. #543 adds two call sites this table missed (libs/pricing/estimator.go:67viaEstimateSweepCost, feeding both the sweep--estimate-onlyrows and the--budgetcomparison).Two things in #543 that change the priority rather than just restating this one:
c8g.metal-48xl, and the wrong one is the one a human reads. Sizing--cost-limitfrom 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.basePriceLarge(unknown family → 0.10).metal-48xlalso missessizeMultiplier, which has only"metal": 48.0— so it takes the2.0 // default to xlargebranch 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 tobasePriceLarge.Also: this one was not the IAM gap. The principal could read the Price List — the same launch stamped
spawn:price-per-hour=7.656960correctly seconds later.launch_single.go:298never asks.fix: display-side pricing (--estimate-only, service dry-run, cost) no…
fix: display-side pricing (--estimate-only, service dry-run, cost) no…
fix: TaskSpec no longer silently narrower than launch (#556)
fix: TaskSpec no longer silently narrower than launch (#556) (#558)
scttfrdmn commentedon Oct 1, 2026
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.resolvePricePerHourasks truffle (the suite's pricing authority), and crucially: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, insideLaunch.2. A missing price means "no cap", never a guessed one
pkg/agent/agent.go:477:With no resolvable price,
PricePerHourstays0and spored enforces nothing rather than enforcing against fiction. That only holds because of part 1 — the combination of "0 means unenforced" and "a--cost-limitlaunch refuses to proceed unpriced" is what closes the hole.3.
pricing:GetProductsis granted, so the fallback is no longer the default pathThis 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:203now grants it:Existing onboarded accounts need to re-run
spawn onboardto 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.GetEC2HourlyRatereturnedfloat64with no error channel and invented a price for any family absent from its table, which is every GPU family newer thanp4d: measured$0.80forg7e.4xlargeagainst a real$3.9982, and$9.60forp5e.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
staticOnDemandPriceralready 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.feat(status): list every billable resource, not just the instance
feat(status): list every billable resource, not just the instance
feat(status): list every billable resource, not just the instance (#634)
fix(extend): carry the cost limit along with the TTL (#641)
Withdraw --proximity-from and --cost-tier (#864)
Withdraw --proximity-from and --cost-tier (#864) (#871)