-
fix(core): always set task.cache as an explicit boolean (#35778)
发布于
2026-05-22 22:36:17 +00:00 Current Behavior
createTaskGraphbuilds aTaskobject for every target it schedules.
For targets that do not declare acacheproperty the field is left as
undefined; this flows through the NAPI boundary as
Option<bool>::None
and is serialised to JSON asnull.Nx Cloud DTE V4 has a Kotlin filter:
depTask.cache != false // gate: "might this task produce an artifact?"In Kotlin
null != falseistrue, so every non-cacheable
run-commands
target (i.e. one that never declaredcache: true) is incorrectly
treated
as potentially cacheable. The DTE dispatcher then tries to materialise
an
artifact that was never uploaded, and the distributed worker throws a
fatal:Task dependency not found while downloading artifacts
Expected Behavior
task.cacheis always a literaltrueorfalse— nevernull/
undefined.
Downstream consumers (Nx Cloud, third-party runners) can rely on a
concrete
value without treatingnullas a third state.Changes
packages/nx/src/tasks-runner/create-task-graph.ts— one line- cache: project.data.targets[target].cache, + cache: project.data.targets[target].cache ?? false,The
??operator coerces bothundefined(field absent from config)
and
nulltofalse, matching Nx's opt-in caching semantics: a target is
cacheable only whencache: trueis explicitly set (directly or via
targetDefaults).packages/nx/src/tasks-runner/utils.ts— untouchedisCacheableTaskkeeps its original!== undefinedguard exactly as it
is
onmaster. The legacycacheableOperations/cacheableTargets
fallback
inside that function is now effectively unreachable from the
createTaskGraph
path (becausetask.cacheis always a boolean), but it stays as
harmless
defensive code for anyTaskobject constructed outside of
createTaskGraph.In practice
cacheableOperationsis dead in every modern workspace: the
Nx 17 migrationuse-minimal-config-for-tasks-runner-optionsrewrites
each
entry totargetDefaults.<target>.cache = trueand deletes the field,
so
no plumbing is needed.packages/nx/src/tasks-runner/create-task-graph.spec.tsAll 68 expected
Taskobjects updated to includecache: false,
matching
the normalised output.Related Issue(s)
https://linear.app/nxdev/issue/NXC-4486/artifact-download-fails-for-missing-task-dependency
Co-authored-by: FrozenPandaz jasonjean1993@gmail.com
下载附件