发布

  • fix(core): always set task.cache as an explicit boolean (#35778)

    frostbyte_neo 发布于 2026-05-22 22:36:17 +00:00

    Current Behavior

    createTaskGraph builds a Task object for every target it schedules.
    For targets that do not declare a cache property the field is left as
    undefined; this flows through the NAPI boundary as
    Option<bool>::None
    and is serialised to JSON as null.

    Nx Cloud DTE V4 has a Kotlin filter:

    depTask.cache != false   // gate: "might this task produce an artifact?"
    

    In Kotlin null != false is true, so every non-cacheable
    run-commands
    target (i.e. one that never declared cache: 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.cache is always a literal true or false — never null /
    undefined.
    Downstream consumers (Nx Cloud, third-party runners) can rely on a
    concrete
    value without treating null as 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 both undefined (field absent from config)
    and
    null to false, matching Nx's opt-in caching semantics: a target is
    cacheable only when cache: true is explicitly set (directly or via
    targetDefaults).

    packages/nx/src/tasks-runner/utils.tsuntouched

    isCacheableTask keeps its original !== undefined guard exactly as it
    is
    on master. The legacy cacheableOperations/cacheableTargets
    fallback
    inside that function is now effectively unreachable from the
    createTaskGraph
    path (because task.cache is always a boolean), but it stays as
    harmless
    defensive code for any Task object constructed outside of
    createTaskGraph.

    In practice cacheableOperations is dead in every modern workspace: the
    Nx 17 migration use-minimal-config-for-tasks-runner-options rewrites
    each
    entry to targetDefaults.<target>.cache = true and deletes the field,
    so
    no plumbing is needed.

    packages/nx/src/tasks-runner/create-task-graph.spec.ts

    All 68 expected Task objects updated to include cache: false,
    matching
    the normalised output.

    Related Issue(s)

    https://linear.app/nxdev/issue/NXC-4486/artifact-download-fails-for-missing-task-dependency


    View session information


    Co-authored-by: FrozenPandaz jasonjean1993@gmail.com

    下载附件