diff --git a/packages/nx/src/native/tasks/hash_planner.rs b/packages/nx/src/native/tasks/hash_planner.rs index a85398a3911..90d37815399 100644 --- a/packages/nx/src/native/tasks/hash_planner.rs +++ b/packages/nx/src/native/tasks/hash_planner.rs @@ -1678,7 +1678,9 @@ fn drop_ultracache_duplicates(pool: &InstructionPool, ids: &mut Vec) { /// fileset that reads from a directory containing, or sitting inside, an /// output an upstream task declares. An output inside a project nested below /// the glob's own is not read by it, so it does not count. Any other -/// disk-backed fileset hashes up front like a tracked one. +/// disk-backed fileset hashes up front like a tracked one. A task that hashes +/// its absolute cwd also waits: under distribution it runs on an agent whose +/// cwd differs from the coordinator's. fn deferred_tasks( plans: &HashMap>, pool: &InstructionPool, @@ -1691,7 +1693,9 @@ fn deferred_tasks( let mut disk_roots: Vec<(String, Vec)> = Vec::new(); for id in ids.iter() { match &*pool.get(*id) { - HashInstruction::TaskOutput(_, _) => return true, + HashInstruction::TaskOutput(_, _) | HashInstruction::Cwd(CwdMode::Absolute) => { + return true; + } HashInstruction::IgnoredFileSet { globs, project_roots, @@ -2787,6 +2791,38 @@ mod tests { ); } + #[test] + fn defers_a_task_that_hashes_its_absolute_cwd() { + let pool = InstructionPool::new(); + let plans: HashMap> = [ + ("app:absolute", CwdMode::Absolute), + ("app:relative", CwdMode::Relative), + ] + .into_iter() + .map(|(id, mode)| { + ( + id.to_string(), + vec![pool.intern(HashInstruction::Cwd(mode))], + ) + }) + .collect(); + let task_graph = TaskGraph { + roots: vec![], + tasks: ["app:absolute", "app:relative"] + .into_iter() + .map(|id| { + let (project, target) = id.split_once(':').unwrap(); + (id.to_string(), Task::new(project, target)) + }) + .collect(), + dependencies: HashMap::new(), + continuous_dependencies: HashMap::new(), + }; + + let deferred = deferred_tasks(&plans, &pool, &task_graph); + assert_eq!(deferred, HashSet::from(["app:absolute".to_string()])); + } + #[test] fn does_not_defer_for_an_output_in_a_nested_project_the_glob_skips() { let pool = InstructionPool::new(); diff --git a/packages/nx/src/native/tasks/task_hasher.rs b/packages/nx/src/native/tasks/task_hasher.rs index cd1ae2eb5c1..555412e33a1 100644 --- a/packages/nx/src/native/tasks/task_hasher.rs +++ b/packages/nx/src/native/tasks/task_hasher.rs @@ -595,9 +595,9 @@ impl TaskHasher { /// Like `hash_plans`, but only for the plans the planner did not defer /// (`HashPlans::deferred`: a task that reads another task's outputs, or a /// disk-backed fileset whose directory contains, or sits inside, an - /// upstream task's output). The rest are left out and hash once those - /// tasks have run; their ids are absent from the result and need no entry - /// in `per_task_envs`. + /// upstream task's output, or one that hashes its absolute cwd). The rest + /// are left out and hash where they run; their ids are absent from the + /// result and need no entry in `per_task_envs`. #[napi(ts_return_type = "Record")] pub fn hash_plans_upfront( &self, @@ -618,7 +618,7 @@ impl TaskHasher { let partition_duration = function_start.elapsed(); let (upfront_count, total_count) = (plans.len(), hash_plans.plans.len()); trace!( - "hash_plans_upfront: {} of {} plans hash up front, {} wait for other tasks' outputs (partition: {:?})", + "hash_plans_upfront: {} of {} plans hash up front, {} deferred (partition: {:?})", upfront_count, total_count, total_count - upfront_count, diff --git a/packages/nx/src/native/tasks/types.rs b/packages/nx/src/native/tasks/types.rs index 02b2ba9f894..eddc5a4da6c 100644 --- a/packages/nx/src/native/tasks/types.rs +++ b/packages/nx/src/native/tasks/types.rs @@ -373,9 +373,10 @@ impl InstructionPool { pub struct HashPlans { pub pool: Arc, pub plans: HashMap>, - /// Tasks the up-front batch leaves out: the directory a disk-backed - /// fileset of theirs reads from contains, or sits inside, an output a - /// task they depend on declares. + /// Tasks the up-front batch leaves out: they read a dependent task's + /// outputs, the directory a disk-backed fileset of theirs reads from + /// contains, or sits inside, an output a task they depend on declares, or + /// they hash their absolute cwd. pub deferred: std::collections::HashSet, }