Repository: kestra-io/kestra
Issue: Subflow task logs are not shown
Labels: bug
backend

### Expected Behavior

_No response_

### Actual Behaviour

See https://demo.kestra.io/ui/executions/io.kestra.bmu/call-simple-subflow/2euoLKmgwfLH0lAlHu9uU/logs where there is no logs boxes due to Subflow tasks not producing any attempt making it a edge case

### Steps To Reproduce

_No response_

### Environment Information

- Kestra Version: 0.12.0-SNAPSHOT
- Operating System (OS / Docker / Kubernetes):
- Java Version (If not docker):


### Example flow

```
id: call-simple-subflow
namespace: io.kestra.bmu
tasks:
  - id: subflow
    type: io.kestra.core.tasks.flows.Flow
    flowId: simple-subflow
    namespace: io.kestra.bmu
```

```
id: simple-subflow
namespace: io.kestra.bmu
tasks:
  - id: hello
    type: io.kestra.core.tasks.log.Log
    message: Kestra team wishes you a great day! 👋
```

Issue comments:

Pull request review comments:
Would be more readable if expand on multiple line

Patch that resolved the issue:
diff --git a/core/src/main/java/io/kestra/core/runners/ExecutorService.java b/core/src/main/java/io/kestra/core/runners/ExecutorService.java
index 63717e1143..de656bbf80 100644
--- a/core/src/main/java/io/kestra/core/runners/ExecutorService.java
+++ b/core/src/main/java/io/kestra/core/runners/ExecutorService.java
@@ -6,6 +6,7 @@
 import io.kestra.core.models.executions.Execution;
 import io.kestra.core.models.executions.NextTaskRun;
 import io.kestra.core.models.executions.TaskRun;
+import io.kestra.core.models.executions.TaskRunAttempt;
 import io.kestra.core.models.flows.Flow;
 import io.kestra.core.models.flows.State;
 import io.kestra.core.models.tasks.FlowableTask;
@@ -598,7 +599,11 @@ private Executor handleFlowTask(final Executor executor) {
                     }
                 } catch (Exception e) {
                     workerTaskResults.add(WorkerTaskResult.builder()
-                        .taskRun(workerTask.getTaskRun().withState(State.Type.FAILED))
+                        .taskRun(workerTask.getTaskRun().withState(State.Type.FAILED)
+                            .withAttempts(Collections.singletonList(
+                                TaskRunAttempt.builder().state(new State().withState(State.Type.FAILED)).build()
+                            ))
+                        )
                         .build()
                     );
                     executor.withException(e, "handleFlowTask");
diff --git a/core/src/main/java/io/kestra/core/tasks/flows/Flow.java b/core/src/main/java/io/kestra/core/tasks/flows/Flow.java
index 182cf36d9e..a5e5eed0f3 100644
--- a/core/src/main/java/io/kestra/core/tasks/flows/Flow.java
+++ b/core/src/main/java/io/kestra/core/tasks/flows/Flow.java
@@ -8,6 +8,7 @@
 import io.kestra.core.models.executions.Execution;
 import io.kestra.core.models.executions.ExecutionTrigger;
 import io.kestra.core.models.executions.TaskRun;
+import io.kestra.core.models.executions.TaskRunAttempt;
 import io.kestra.core.models.flows.FlowWithException;
 import io.kestra.core.models.flows.State;
 import io.kestra.core.models.tasks.RunnableTask;
@@ -19,11 +20,7 @@
 
 import javax.annotation.Nullable;
 import javax.validation.constraints.NotNull;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
 
 @SuperBuilder
 @ToString
@@ -188,9 +185,10 @@ public WorkerTaskResult createWorkerTaskResult(
             try {
                 builder.outputs(runContext.render(workerTaskExecution.getTask().getOutputs()));
             } catch (Exception e) {
-                runContext.logger().warn("Failed to extract ouputs with error: '" + e.getMessage() + "'", e);
+                runContext.logger().warn("Failed to extract outputs with error: '" + e.getMessage() + "'", e);
                 taskRun = taskRun
                     .withState(State.Type.FAILED)
+                    .withAttempts(Collections.singletonList(TaskRunAttempt.builder().state(new State().withState(State.Type.FAILED)).build()))
                     .withOutputs(builder.build().toMap());
 
                 return WorkerTaskResult.builder()
@@ -212,7 +210,9 @@ public WorkerTaskResult createWorkerTaskResult(
         }
 
         return WorkerTaskResult.builder()
-            .taskRun(taskRun)
+            .taskRun(taskRun.withAttempts(
+                Collections.singletonList(TaskRunAttempt.builder().state(new State().withState(taskRun.getState().getCurrent())).build())
+            ))
             .build();
     }
 


Test patch:
diff --git a/core/src/test/java/io/kestra/core/tasks/flows/FlowCaseTest.java b/core/src/test/java/io/kestra/core/tasks/flows/FlowCaseTest.java
index 5805453b3e..79deee8031 100644
--- a/core/src/test/java/io/kestra/core/tasks/flows/FlowCaseTest.java
+++ b/core/src/test/java/io/kestra/core/tasks/flows/FlowCaseTest.java
@@ -64,6 +64,8 @@ void run(String input, State.Type fromState, State.Type triggerState,  int count
         countDownLatch.await(1, TimeUnit.MINUTES);
 
         assertThat(execution.getTaskRunList(), hasSize(1));
+        assertThat(execution.getTaskRunList().get(0).getAttempts(), hasSize(1));
+        assertThat(execution.getTaskRunList().get(0).getAttempts().get(0).getState().getCurrent(), is(fromState));
         assertThat(execution.getState().getCurrent(), is(fromState));
 
         if (outputs != null) {