From 62dd92a22d627407c8ebeb62a53c69e845d12cd8 Mon Sep 17 00:00:00 2001
From: allegroai <>
Date: Wed, 31 Jul 2024 17:25:12 +0300
Subject: [PATCH] Fix when abort callback is set, set task status to stopped
 only if running locally, otherwise leave it for the Agent to set it.

---
 clearml/task.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clearml/task.py b/clearml/task.py
index 76b98630..d63a2c78 100644
--- a/clearml/task.py
+++ b/clearml/task.py
@@ -4148,7 +4148,10 @@ class Task(_Task):
             )
         )
         self.flush(wait_for_uploads=True)
-        self.stopped(status_reason='USER ABORTED')
+
+        # if running remotely, we want the daemon to kill us
+        if self.running_locally():
+            self.stopped(status_reason='USER ABORTED')
 
         if self._dev_worker:
             self._dev_worker.unregister()