Skip to content

extend: carry the cost limit along with the TTL - #641

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/639-extend-cost-limit
Oct 3, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/639-extend-cost-limit

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Refs #639. Per your call: raise the cap to exactly what the new TTL needs, with --cost-limit to set it explicitly and --keep-cost-limit to opt out.

The bug, and why it's a no-op by construction

spawn extend moved spawn:ttl and spawn:ttl-deadline and nothing else — grep -ci cost cmd/extend.go was 0 — while spored enforces the cost cap independently:

// 3. Check cost limit (fires independently of or alongside TTL — first-to-fire wins)

"First-to-fire wins" is right. The gap was that extend could only move one of the two. And anyone who sized their cap to their TTL — which is what the cost guidance tells you to do — had extend be a no-op by construction: the limit it left alone was always the tighter one.

The reported case: a 60m TTL capped at $0.65 on a $0.63808/hr instance (61 minutes of spend), extended by 45m. TTL moved to 105m, cap stayed, instance still stopped at ~61m — one minute after the original deadline. Nothing in the output mentioned the cap, so it read as "extend didn't work" rather than "a second limit fired."

The fix

   Cost limit:   $0.6500 → $1.1166
                 (raised: $0.6500 capped this instance at 1h1m, so the new deadline was unreachable)

needed = rate × hours from LaunchTime to the new deadline, where rate includes the EBS rate — because the cap counts EBS too (#616) and a compute-only figure would bind early again, which is the same bug one layer down. Both rates come from the instance's own tags (spawn:price-per-hour, spawn:ebs-hourly-cost), so this cannot disagree with what is actually enforced.

Not proportional scaling, which would guess. This computes exactly what the TTL you asked for requires.

It only ever raises. An extension is a decision to allow more spend, not less; silently tightening a cap someone set deliberately would be its own surprise.

Where the answer is unknowable, it says so rather than inventing a number — no spawn:price-per-hour, no launch time → the cap is left alone with the reason printed. Guessing is how #533's cap stopped being enforceable.

--keep-cost-limit still prints that the cap was left alone, because otherwise the user is straight back to an instance dying early for an unstated reason, which is the actual complaint.

Job arrays: not fixed, but no longer silent

The array path writes a relative spawn:ttl rather than a deadline, so the required cap has to be derived from a different anchor — a separate change. It now warns and names the command that does work:

⚠️  3 of 8 instances have a cost limit, which this does NOT change.
   An instance whose cap was sized to its old TTL will still stop before the new one.
   Extend those individually to have the cap raised with the TTL:
     spawn extend <instance-id> 45m

Deliberately scoped out, deliberately not left as a hidden trap.

Tests

Eight cases, pure (no AWS): the reporter's exact numbers ($0.65 / $0.63808/hr / +45m → ~$1.1166, with a reason naming both what was raised and why); EBS raising the required cap; never lowering a cap that already covers the deadline; --cost-limit winning; --keep-cost-limit respected and explained in the output; no cap being a non-event; a missing rate producing an explanation rather than a number; and the tag format matching what launch writes so spored parses it identically.

Gates

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

Note on ordering

This branches off main, so it's independent of #640 (#616, --cost-limit covers storage) — but the two are related: this includes the EBS rate in its arithmetic, which matches what the cap enforces exactly once #640 lands. Before that it just leaves slightly more headroom, which is the safe direction. No merge-order dependency either way.

Suggested bump: MINOR — two new flags on extend, and a cap that now moves when you extend.

'spawn extend' moved spawn:ttl and spawn:ttl-deadline and nothing else — grep -ci cost
cmd/extend.go was 0 — while spored enforces the cost cap INDEPENDENTLY
('first-to-fire wins', pkg/agent/agent.go). So for anyone who sized their cap to their
TTL, which is what the cost guidance tells you to do, extend was a no-op BY
CONSTRUCTION: the limit it left alone was always the tighter one.

The reported case: a 60m TTL capped at $0.65 on a $0.63808/hr instance (61 minutes of
spend), extended by 45m. The TTL moved to 105m, the cap stayed, and the instance still
stopped at ~61m — one minute after the ORIGINAL deadline. Nothing in the output
mentioned the cap, so it read as 'extend didn't work' rather than 'a second limit
fired'. The workaround was writing the tag by hand.

The cap is now raised to exactly what the new deadline requires: rate x hours from
LaunchTime to the new deadline, including the EBS rate because the cap counts EBS too
(#616) and a compute-only figure would bind early again — the same bug one layer down.
Both rates come from the instance's own tags, so this cannot disagree with what is
actually enforced. Not proportional scaling, which would guess.

It only ever RAISES: an extension is a decision to allow more spend, not less, and
silently tightening someone's cap would be its own surprise. --cost-limit sets a value
explicitly; --keep-cost-limit opts out and still prints that the cap was left alone,
because otherwise the user is back to an instance dying early for an unstated reason.

Where the required cap is unknowable — no spawn:price-per-hour, no launch time — it
says so instead of inventing a number. Guessing is how #533's cap stopped being
enforceable.

Output for the reporter's exact case:
   Cost limit:   $0.6500 -> $1.1166
                 (raised: $0.6500 capped this instance at 1h1m, so the new deadline
                  was unreachable)

Job arrays are NOT fixed here and now warn instead, naming the per-instance command:
that path writes a relative spawn:ttl rather than a deadline, so the required cap has
to be derived from a different anchor. Deliberately separate, but not left silent.

Refs #639
@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.73016% with 26 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/extend.go 21.05% 15 Missing ⚠️
cmd/extend_cost_limit.go 75.00% 9 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 64d1894 into main Oct 3, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/639-extend-cost-limit branch October 3, 2026 04:12
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