Repository navigation
Description
Summary
TaskHasher deliberately hashes the un-interpolated script: source so that referencing a resource directive does not invalidate the cache — the comment says so outright (TaskHasher.groovy:60-63):
add source code of
script:orexec:block
- this allows task script to reference directives like
task.cpuswithout invalidating the cache
It then folds in the fully evaluated value of every task.ext.* the script references, which puts task.cpus straight back into the key. The two halves of the same hash disagree about whether resource allocation counts.
Mechanism
TaskHasher.compute() TaskHasher.groovy:90-93
└─ def vars = getTaskGlobalVars(); keys.add(vars.entrySet())
└─ getTaskGlobalVars() :159-164
├─ task.getGlobalVars(binding)
└─ getTaskExtensionDirectiveVars() :166-178
for( key : task.getVariableNames() )
if( !key.startsWith('task.ext.') ) continue
final value = taskConfig.eval(key.substring(5))
result.put(key, value) // ← the EVALUATED value
└─ TaskConfig.eval() TaskConfig.groovy:153-155
└─ LazyMap.getValue() → resolve() :827-830
// runs the closure against the task context
The nf-core idiom that trips it is common. nf-core/rnaseq, conf/modules/trimgalore.config:
ext.args = {
def preset_args_map = ["--fastqc_args": "'-t ${task.cpus}'"]
...
}resolve() evaluates that, so the string folded into the hash is --fastqc_args '-t 8' on one compute environment and --fastqc_args '-t 3' on another.
Evidence
Two runs of nf-core/rnaseq pinned to the same commit, same container, same inputs, on compute environments that allocate different CPUs. The lineage TaskRun records for the same task (TRIMGALORE, same sample) differ in exactly one hash-relevant field:
globalVars, run A (task.cpus=3)
{ "task.ext.args": "--fastqc_args '-t 3'", "task.ext.prefix": "H1_REP1_trimmed" }
globalVars, run B (task.cpus=8)
{ "task.ext.args": "--fastqc_args '-t 8'", "task.ext.prefix": "H1_REP1_trimmed" }
codeChecksum identical ← the un-interpolated source
container identical
input identical
script differs ← the RENDERED command; not a hash input, by design
--fastqc_args '-t 8' versus '-t 3' changes a thread count. trim_galore produces the same result either way, so by the hash's own definition of a match — same script, same inputs, same container — this is a false invalidation.
Impact
Harmless for -resume: the same run has the same compute environment and therefore the same task.cpus. It becomes systematic for a cache shared across compute environments, of the kind the SPIs in #7638 enable.
It also cascades. The invalidated process re-executes and its outputs are not byte-reproducible (trim_galore gzips, and gzip embeds mtime), so a content-derived identity sees new inputs downstream and those tasks miss too — even where their own script and CPU count match. In the run above, a downstream SALMON_QUANT with an identical script and identical task.cpus on both sides still missed.
The cascade is not inherent, which is what makes the cost worth quoting: BEDTOOLS_GENOMECOV also re-executed, but its output is deterministic, so both of its consumers (UCSC_BEDCLIP, UCSC_BEDGRAPHTOBIGWIG, 7 tasks each) hit anyway. One hash term in one upstream process accounted for roughly 250 task re-executions out of ~300.
Possible fixes
-
Normalize resource directives during the
ext.*evaluation. Evaluate against a context whosecpus,memory,time,diskandacceleratorresolve to a sentinel. Removes the compute-environment dependency and leaves every otherextinput intact. Smallest change, contained ingetTaskExtensionDirectiveVars(). -
Fold the unevaluated expression instead of its value, symmetric with how
task.sourceis already treated. More consistent with the stated intent, but a closure that readsparamsormetawould then collide across genuinely different configurations, so those inputs would have to be folded separately — more design work.
Happy to prepare a PR for (1) if that direction looks right.
Activity
bentsherman commentedon Sep 22, 2026
I don't see the issue here. If the user puts something into
extthen they accept that it will contribute to the task hashjorgee commentedon Sep 22, 2026
Ok, fine with me. The fix seems quite complicated. I wanted to raise it; I got it when re-executing the same pipeline with optimized values in the platform. It changed the CPUs and memory, and some
nf-core/rnaseqtasks were not cached because theext.argscontained CPU values.awgymer commentedon Nov 23, 2026
Given this is a somewhat common idiom in nf-core I am wondering if there is some way a user could give a set of keys not to include in the hash? Or a cache setting that allows the user to simply not include
extat all?bentsherman commentedon Nov 23, 2026
I think it's better to maintain a simple contract when it comes to the task hash. If you supply a directive like
task.cpusthrough an input, whether a process input orext, then you accept that it will affect the task hash. If you want to avoid that then you should not supply directives as inputs in the first place