Skip to content

cost: --cost-limit covers storage, not just compute - #640

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/616-cost-limit-covers-storage
Oct 3, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/616-cost-limit-covers-storage

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Refs #616. Per your call: the cap becomes a total, with an explicit override, and no new flags — one number meaning what people already believe it means.

The bug

--cost-limit counted compute-seconds only. That is how #613's launch committed a 1.2 TiB filesystem at ~$174/month under a --cost-limit of 2.50 — roughly 70× the cap — while the cap was respected to the letter the entire time.

Why it has to be enforced in two places

--cost-limit is enforced inside the instance by spored, and spored dies with the instance. So it can never act on a resource that outlives it. That constraint, not taste, produces the split:

where reach
up front CLI, before anything is spent the only guard that can see a filesystem outliving the instance
in flight spored's running tally compute + EBS — the things terminating actually stops

Up front: a launch whose storage alone exceeds the cap is refused, with the real figure:

$ spawn launch dpaths --fsx-create --fsx-lifecycle ephemeral --ttl 90m --cost-limit 2.50
this launch would create storage costing ~$174.00/month, which exceeds --cost-limit 2.50 on its own.

  FSx Lustre: 1200 GiB at 125 MB/s/TiB, lifecycle "ephemeral" — ~$174.00/month

  --cost-limit covers storage as well as compute. Storage outlives the instance,
  so spored — which enforces the cap from inside it — cannot reclaim it against the
  cap. A 'durable' filesystem is never reclaimed automatically; an 'ephemeral' one
  only by the out-of-band reaper, and only in an account it covers ('spawn doctor').

  Raise --cost-limit, shrink the filesystem with --fsx-storage-capacity, or pass
  --allow-cost-limit-overrun if you mean it.

Priced monthly, not TTL-prorated, deliberately: once created, a filesystem bills until something deletes it, and for a durable one nothing does automatically. A month is the floor, not the estimate.

In flight: EBS now counts toward the cap, priced on wall clock rather than compute time — EBS bills while an instance is merely stopped, and the old arithmetic counted none of it.

FSx is deliberately not in the in-flight tally. Terminating doesn't delete a filesystem, so firing the cap on FSx accrual would kill the instance while the thing it reacted to kept billing — an action that looks like enforcement and achieves nothing. That commitment is refused at launch instead; reclaiming what outlives an instance stays the reaper's job (#624/#625).

Behaviour change, stated plainly

A launch that succeeded yesterday under a small cap with --fsx-create is now rejected. That's the bug, not a regression — those launches were silently uncapped — but it will break scripts, and the changelog says so.

Verified against the exact #613 invocation (refused, exit 1) and four cases that must not be refused:

case result
--allow-cost-limit-overrun proceeds
compute-only launch, --cost-limit 0.01 proceeds — no regression for small caps
--cost-limit 300 with the same filesystem proceeds
--cost-limit 180 vs the $174 minimum proceeds — so the error's advice is actionable

A bug I wrote and the test caught

I first priced EBS over compute hours, which undercounts exactly the case that matters: a stopped instance accruing storage. TestAccumulatedCostIncludesEBS asserts the 2h-wall-clock vs 1h-compute distinction explicitly, and I confirmed it fails against the version I nearly shipped:

EBS contribution = 0.5000, want ~1.00 (2h wall clock x $0.50/hr).
If it is ~0.50 this is being priced over compute hours and undercounts a stopped instance.

Two test assertions updated, not deleted

Both encoded the old truth and became false by design:

They assert what didn't change — the cap can't reclaim storage that outlives the instance — which is the part users still need told. "compute only" survives in cost.go and status.go, where it describes compute figures rather than the cap's scope and is still accurate.

Incidentally

The changelog gate from #638 caught me immediately: [Unreleased] already had a ### Changed and I added a second, so TestChangelogHasNoDuplicateGroups failed on my own PR. Consolidated. First time it's earned its keep.

Gates

gofmt · go vet · go build · go test ./... all green · make check-docs clean with docs-gen/launch.md regenerated · staticcheck zero added (by-message diff) · changelog format tests pass.

Suggested bump: MINOR — new --allow-cost-limit-overrun flag, and --cost-limit's meaning changed in a way users will notice.

--cost-limit was compute-only. That is how #613's launch committed a 1.2 TiB
filesystem at ~$174/month under a --cost-limit of 2.50 — roughly 70x the cap — while
the cap was respected to the letter the whole time, because it counted nothing but
compute-seconds.

The cap is now a TOTAL, enforced in the two places it can be. The split is not
cosmetic: --cost-limit is enforced INSIDE the instance by spored, and spored dies with
the instance, so it can never act on a resource that outlives it.

Up front (CLI, reliable): a launch whose storage commitment alone exceeds the cap is
REFUSED, naming the real monthly figure, what is being created, and why the cap cannot
bound it. --allow-cost-limit-overrun is the explicit escape hatch. Priced monthly, not
TTL-prorated, deliberately: once created, a filesystem bills until something deletes
it, and for a durable one nothing does automatically. A month is the floor.

In flight (spored): EBS now counts toward the cap alongside compute, because
terminating actually stops it — spawn's volumes carry DeleteOnTermination. Priced on
WALL CLOCK, not compute time: EBS bills while an instance is merely stopped, and
pricing it over compute hours would undercount exactly the case that matters. I wrote
it the wrong way first; the test that caught it asserts the 2h-wall-clock vs
1h-compute distinction explicitly.

FSx is deliberately NOT in the in-flight tally. Terminating does not delete a
filesystem, so firing the cap on FSx accrual would terminate the instance while the
thing it reacted to kept billing — an action that looks like enforcement and achieves
nothing. That commitment is refused at launch instead, and reclaiming what outlives an
instance stays the reaper's job (#624/#625).

Verified against the exact #613 invocation: now refused with the $174.00/month figure,
exit 1. Four cases confirmed NOT refused: the override flag, a compute-only launch
under a $0.01 cap (no regression), a cap that covers the storage, and a $180 cap
against the $174 minimum — so the error's advice is actionable.

Two test assertions updated rather than deleted, both of which encoded the OLD truth:
the #617 estimate test required 'does NOT cover' and the #615 billable view required
'caps COMPUTE only'. Both became false by design; they now assert what did NOT change
— that the cap cannot RECLAIM storage outliving the instance — and the first also
fails if the obsolete wording returns.

'compute only' survives where it is still accurate (cost.go, status.go), because those
lines describe compute FIGURES, not the cap's scope.

Refs #616
@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.59259% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_cost_limit.go 95.12% 1 Missing and 1 partial ⚠️
cmd/launch_single.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit fff3dfb into main Oct 3, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the feat/616-cost-limit-covers-storage branch October 3, 2026 04:12
@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Ran the two free checks from the consumer side on 0.116.0 — 118 cookbook TaskSpecs, every one with a lifecycle.cost_limit. No recipe is affected, and the arithmetic is worth recording since "the cap is now a total" is the kind of change that sounds like it should break tight caps:

  • The up-front refusal never triggers here — no recipe creates FSx, so there is no storage commitment to price against the cap.
  • The in-flight EBS tally is immaterial at our sizes. Tightest caps are $0.02 at TTL 5m; on c8g.large that is $0.0067 of compute, and an AMI-default root over 5 minutes is ~$0.0002 of gp3 — about 1% of the cap, against 34% already used by compute. The only spec with an explicit resources.disk_gib is 40 GiB at TTL 20m under a $0.06 cap: $0.0532 compute + ~$0.0015 EBS = $0.0547, so it moves from 89% to 91% of its cap in the worst case. Thin, but it does not fire.

So the change is a strict improvement from where I'm standing, and #613's 70×-over-cap case was exactly the hole worth closing.

One loose end: --dry-run's estimate still says compute-only

The pre-flight line a caller reads has not followed the cap:

TTL:          20m   on-complete: terminate
Cost limit:   $0.06 (lifecycle.cost_limit)
Max cost:     ~$0.05 (on-demand rate × TTL; a completed task usually costs far less)

Max cost is rate × TTL and the parenthetical says so, but the cap it sits next to now counts compute + EBS wall-clock. For that spec the real worst case against the cap is ~$0.0547, not $0.05. At these sizes the gap is rounding, but the two numbers are printed adjacent and invite being compared, so the one place a caller can sanity-check headroom before launching is the one place that still uses the old arithmetic. It also hides the direction of travel: a caller with a big disk_gib and a cap set from Max cost would be the first to be surprised, and --dry-run is precisely where they'd look.

Adding the EBS term to Max cost (and naming it, e.g. ~$0.055 = $0.053 compute + $0.002 EBS) would make the dry-run self-consistent with the thing it is previewing. Happy to send that if you want it — it's the same figure the in-flight tally already computes.

For the record, the consumer-side diligence this project owes on any guardrail change ("does the spec still parse, does --dry-run echo the resolved value back") passed on both the tightest-cap spec and the only disk_gib one.

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.

1 participant