From a4d3b5bad6797af7bfd663cd2474a6eb7f423a7a Mon Sep 17 00:00:00 2001
From: allegroai <>
Date: Tue, 27 Aug 2024 22:52:31 +0300
Subject: [PATCH] Fix only set Task started status on node rank 0

---
 clearml_agent/commands/worker.py | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/clearml_agent/commands/worker.py b/clearml_agent/commands/worker.py
index 35f7f36..0a6fe93 100644
--- a/clearml_agent/commands/worker.py
+++ b/clearml_agent/commands/worker.py
@@ -940,12 +940,14 @@ class Worker(ServiceCommandSection):
             print("Warning: failed obtaining/setting hostname for task '{}': {}".format(task_id, ex))
 
         # set task status to in_progress so we know it was popped from the queue
-        # noinspection PyBroadException
-        try:
-            task_session.send_api(tasks_api.StartedRequest(task=task_id, status_message="launch by agent", force=True))
-        except Exception:
-            print("Warning: Could not set status=in_progress task id '{}', skipping".format(task_id))
-            return
+        if not self._get_node_rank():
+            # noinspection PyBroadException
+            try:
+                task_session.send_api(tasks_api.StartedRequest(task=task_id, status_message="launch by agent", force=True))
+            except Exception:
+                print("Warning: Could not set status=in_progress task id '{}', skipping".format(task_id))
+                return
+
         # setup console log
         temp_stdout_name = safe_mkstemp(
             suffix=".txt", prefix=".clearml_agent_out.", name_only=True, dir=(ENV_TEMP_STDOUT_FILE_DIR.get() or None)
@@ -1336,12 +1338,13 @@ class Worker(ServiceCommandSection):
 
                         # set task status to in_progress so we know it was popped from the queue
                         # next api version we will set the status when pulling from the queue
-                        # noinspection PyBroadException
-                        try:
-                            self._session.send_api(
-                                tasks_api.StartedRequest(task=task_id, status_message="pulled by agent", force=True))
-                        except Exception:
-                            print("Warning: Could not set status=in_progress task id '{}', retrying in a bit".format(task_id))
+                        if not self._get_node_rank():
+                            # noinspection PyBroadException
+                            try:
+                                self._session.send_api(
+                                    tasks_api.StartedRequest(task=task_id, status_message="pulled by agent", force=True))
+                            except Exception:
+                                print("Warning: Could not set status=in_progress task id '{}', retrying in a bit".format(task_id))
 
                         # check if we need to impersonate
                         task_session = None