Skip to content

feat: ext.costLimit — a per-task spend cap - #101

Merged
scttfrdmn merged 2 commits into
mainfrom
feat/100-cost-limit
Oct 4, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
feat/100-cost-limit

Conversation

@scttfrdmn

Copy link
Copy Markdown
Collaborator

Fixes #100.

TTL was the only ceiling on a task, so a fan-out of N tasks had a worst case of N × ext.ttl × the instance rate with no second belt. spored enforces TTL and cost independently — first to fire wins — so this is a genuine second limit, not a refinement of the first.

The failure it actually catches is the expensive one: a task that hangs rather than fails produces no exit status for Nextflow to retry or abort on, so it bills until the TTL expires.

process ALIGN {
    ext.ttl = '2h'
    ext.costLimit = '0.50'   // USD; stops the instance even if the TTL hasn't fired
}

Two robustness choices

costLimit arrives as a String, because every ext directive does — so it's parsed rather than assumed numeric:

  • A non-numeric value degrades to "bounded by TTL only" with a warning rather than aborting the pipeline. A typo in nextflow.config shouldn't kill a run that's otherwise fine.
  • A non-positive value is treated as unset. A zero cap would mean "terminate immediately", which is never what someone typing 0 intends.

Context

Found in a cross-adapter audit prompted by snakemake-executor-plugin-spawn#12: no adapter emitted lifecycle.cost_limit, so this was a uniform gap across every workflow integration rather than an nf-spawn oversight. Also filed as miniwdl-spawn#12, cwl-spawn#12, airflow-spawn#12, pegasus-spawn#5 — the first three are already merged.

Verification

105 tests pass (built with JAVA_HOME=/opt/homebrew/opt/openjdk@17 per the repo's requirement). Negative check confirmed: disabling the emission fails the two new specs.

Note two existing buildTaskSpec tests call it positionally, so the new parameter shifted their arguments. I updated them rather than appending the parameter last — keeping it grouped with ttl, where it belongs semantically.

TTL was the only ceiling on a task, so a fan-out of N tasks had a worst case of
N x ext.ttl x the instance rate with no second belt. spored enforces TTL and
cost INDEPENDENTLY and the first to fire wins, so this is a genuine second limit
rather than a refinement of the first.

The failure it catches is the expensive one: a task that HANGS rather than fails
produces no exit status for Nextflow to retry or abort on, so it bills until the
TTL expires.

Found in a cross-adapter audit prompted by snakemake-executor-plugin-spawn#12 —
NO adapter emitted lifecycle.cost_limit, so this was a uniform gap across every
workflow integration rather than an nf-spawn oversight.

buildLifecycle emits cost_limit only when set and positive. costLimit arrives as
a String because every ext directive does, so it is parsed rather than assumed
numeric, and a non-numeric value degrades to 'bounded by TTL only' with a
warning instead of aborting the pipeline: a typo in nextflow.config should not
kill a run that is otherwise fine. Non-positive is treated as unset — a zero cap
would mean 'terminate immediately', never what someone typing 0 intends.

105 tests pass. Two existing buildTaskSpec tests call it positionally, so the new
parameter shifted their arguments; updated rather than appended-last, keeping the
signature grouped with ttl where it belongs. Negative check confirmed: disabling
the emission fails the two new specs.

Fixes #100
The directives table is where someone looks for 'what can I set per process',
so a knob that only exists in the CHANGELOG is effectively undiscoverable. The
entry states the property that makes it worth setting: spored enforces it
INDEPENDENTLY of the TTL, so it catches a task that hangs rather than fails.
@scttfrdmn
scttfrdmn merged commit 3e82a6c into main Oct 4, 2026
4 checks passed
@scttfrdmn
scttfrdmn deleted the feat/100-cost-limit branch October 4, 2026 02:46
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.

No lifecycle.cost_limit: TTL is the only ceiling on a job, so a hung job bills to the full TTL

1 participant