发布

  • fix(core): preserve hydrateFileMap back-compat for cached nx-cloud workers (#35502)

    frostbyte_neo 发布于 2026-04-29 22:30:37 +00:00

    Current Behavior

    nx@23.0.0-beta.2 Nx Cloud V4 distributed-agent workers crash on every
    task with:

    Failed to get external value
      at new NativeTaskHasherImpl (.../native-task-hasher-impl.js:25:23)
      at new InProcessTaskHasher (.../task-hasher.js:68:27)
      at createTaskHasher (.../create-task-hasher.js:13:16)
      at createOrchestrator (.../init-tasks-runner.js:86:60)
      at runDiscreteTasks (.../init-tasks-runner.js:114:32)
      at executeAndStoreTask (.../discrete-task-worker.js:1:832861)
    

    #34425 ("remove redundant allWorkspaceFiles from the project graph
    pipeline") changed two helpers in
    packages/nx/src/project-graph/build-project-graph.ts:

    • hydrateFileMap(fileMap, allWorkspaceFiles, rustReferences)
      hydrateFileMap(fileMap, rustReferences)
    • getFileMap() no longer returns allWorkspaceFiles

    Cached Nx Cloud V4 workers (e.g.
    .nx/cache/cloud/2604.29.7/lib/core/runners/distributed-agent/v4/discrete-task-worker.js)
    require('nx/src/project-graph/build-project-graph') directly and still
    call the 3-arg form:

    hydrateFileMap(
      { projectFileMap, nonProjectFiles },
      allWorkspaceFiles,    // lands in rustReferences slot on beta.2
      rustReferences        // silently dropped
    );
    

    The FileData[] array poisons storedRustReferences. Later
    createTaskHasher reads .projectFiles / .allWorkspaceFiles off the
    array (both undefined), passes them to new TaskHasher(...), and
    napi-rs throws "Failed to get external value" trying to coerce
    undefined into &External<Arc<…>>.

    Expected Behavior

    hydrateFileMap accepts both the new 2-arg shape and the legacy 3-arg
    shape, detected by Array.isArray() on the 2nd argument. getFileMap()
    re-exposes allWorkspaceFiles: [] so cached workers that destructure it
    (for telemetry / v4log) see the property instead of undefined. Both
    surfaces are flagged @deprecated so we can remove them in a later
    major once cached V4 workers age out.

    A regression test pins both arities — verified red on the pre-fix code
    and green with the fix.

    Related Issue(s)

    下载附件