Repository: kestra-io/kestra
Issue: CREATED issue is not killable
Labels: bug

Right Now, we have a control on the `RUNNING` [state](https://github.com/kestra-io/kestra/blob/6e6c3334be5405807a547e42b5306a049c35ada9/webserver/src/main/java/io/kestra/webserver/controllers/ExecutionController.java#L822) that prevent killing an execution in `CREATED`. Created must be killable as running on each king of killing (for one, for ids, and for search)   

Issue comments:
In fact only killByQuery (search) filter on running execution on the backend side.

Pull request review comments:

Patch that resolved the issue:
diff --git a/ui/src/utils/state.js b/ui/src/utils/state.js
index eec9d59648..ca85642157 100644
--- a/ui/src/utils/state.js
+++ b/ui/src/utils/state.js
@@ -47,7 +47,7 @@ const STATE = Object.freeze({
         colorClass: "yellow",
         icon: CloseCircle,
         isRunning: true,
-        isKillable: false,
+        isKillable: true,
         isFailed: true,
     },
     KILLED: {
@@ -79,7 +79,7 @@ const STATE = Object.freeze({
         colorClass: "indigo",
         icon: PauseCircle,
         isRunning: true,
-        isKillable: false,
+        isKillable: true,
         isFailed: false,
     }
 });
diff --git a/webserver/src/main/java/io/kestra/webserver/controllers/ExecutionController.java b/webserver/src/main/java/io/kestra/webserver/controllers/ExecutionController.java
index a5e350ea51..2a105e793e 100644
--- a/webserver/src/main/java/io/kestra/webserver/controllers/ExecutionController.java
+++ b/webserver/src/main/java/io/kestra/webserver/controllers/ExecutionController.java
@@ -800,7 +800,7 @@ public MutableHttpResponse<?> killByIds(
     @ExecuteOn(TaskExecutors.IO)
     @Delete(uri = "executions/kill/by-query", produces = MediaType.TEXT_JSON)
     @Operation(tags = {"Executions"}, summary = "Kill executions filter by query parameters")
-    public HttpResponse<BulkResponse> killByQuery(
+    public HttpResponse<?> killByQuery(
         @Parameter(description = "A string filter") @Nullable @QueryValue(value = "q") String query,
         @Parameter(description = "A namespace filter prefix") @Nullable @QueryValue String namespace,
         @Parameter(description = "A flow id filter") @Nullable @QueryValue String flowId,
@@ -808,7 +808,7 @@ public HttpResponse<BulkResponse> killByQuery(
         @Parameter(description = "The end datetime") @Nullable @Format("yyyy-MM-dd'T'HH:mm[:ss][.SSS][XXX]") @QueryValue ZonedDateTime endDate,
         @Parameter(description = "A state filter") @Nullable @QueryValue List<State.Type> state
     ) {
-        Integer count = executionRepository
+        var ids = executionRepository
             .find(
                 query,
                 namespace,
@@ -817,23 +817,11 @@ public HttpResponse<BulkResponse> killByQuery(
                 endDate,
                 state
             )
-            .map(e -> {
-                if (!e.getState().isRunning()) {
-                    throw new IllegalStateException("Execution must be running to be killed, " +
-                        "current state is '" + e.getState().getCurrent() + "' !"
-                    );
-                }
-
-                killQueue.emit(ExecutionKilled
-                    .builder()
-                    .executionId(e.getId())
-                    .build());
-                return 1;
-            })
-            .reduce(Integer::sum)
+            .map(execution -> execution.getId())
+            .toList()
             .blockingGet();
 
-        return HttpResponse.ok(BulkResponse.builder().count(count).build());
+        return killByIds(ids);
     }
 
     private boolean isStopFollow(Flow flow, Execution execution) {


Test patch: