{"record":{"id":"e3529d5f71f32435","repo":"kestra-io/kestra","slug":"no-task-found-to-restart-execution-from","errorCode":null,"errorMessage":"No task found to restart execution from!","messagePattern":"No task found to restart execution from!","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/services/ExecutionService.java","lineNumber":387,"sourceCode":"        if (emitEvent) {\n            eventPublisher.publishEvent(CrudEvent.create(newExecution));\n        }\n        return newExecution;\n    }\n\n    private Set<String> taskRunToRestart(Execution execution, Predicate<TaskRun> predicate) {\n        // Original tasks to be restarted\n        Set<String> finalTaskRunToRestart = this\n            .taskRunWithAncestors(\n                execution,\n                execution.getTaskRunList()\n                    .stream()\n                    .filter(predicate)\n                    .toList()\n            );\n\n        if (finalTaskRunToRestart.isEmpty()) {\n            throw new IllegalArgumentException(\"No task found to restart execution from!\");\n        }\n\n        return finalTaskRunToRestart;\n    }\n\n    public Execution replay(final Execution execution, Flow flow, @Nullable String taskRunId, @Nullable Integer revision, Optional<String> breakpoints) throws Exception {\n        if (taskRunId != null) {\n            // The task run may live in a loop sub-execution (possibly nested); find the right execution to operate on\n            Execution targetExecution = findExecutionWithTaskRun(execution, taskRunId)\n                .map(ExecutionWithTaskRun::execution)\n                .orElse(execution);\n            return replay(targetExecution, flow, taskRunId, revision, breakpoints, false);\n        }\n        return replay(execution, flow, taskRunId, revision, breakpoints, false);\n    }\n\n    public Execution replay(final Execution execution, Flow flow, @Nullable String taskRunId, @Nullable Integer revision, Optional<String> breakpoints, boolean emitEvent) throws Exception {\n        return replay(execution, flow, taskRunId, revision, breakpoints, emitEvent, IdUtils.create());","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/services/ExecutionService.java#L369-L405","documentation":"The `ExecutionService.taskRunToRestart()` method collects all task runs matching a predicate (e.g., `canBeRestarted()` for restart, or matching a specific taskRunId for replay). It then computes the set with ancestors. If this set is empty — meaning no task run matched the predicate — an `IllegalArgumentException` is thrown. This indicates the execution has no restartable tasks, which can happen when all tasks are already in a non-restartable state or when the task list is empty after filtering.","triggerScenarios":"Restarting an execution where all task runs have already been restarted (they are in RESTARTED state, which is not restartable again). Replaying from a `taskRunId` that does not exist in the execution. An execution whose task runs are all in states that `canBeRestarted()` returns false for.","commonSituations":"A user replays from a task run ID that was typed/copied incorrectly. An execution has already been restarted and the user tries to restart it again from the same tasks. The execution has no task runs at all (handled by a separate code path, but edge cases exist).","solutions":["Verify the `taskRunId` exists in the execution before calling replay.","For restart, check that at least one task run is in a restartable state — if the execution was already restarted, it may need a fresh execution instead.","Inspect the execution's task run list and their states to understand which tasks are restartable.","If replaying, use the task run ID from the execution's task run list, not the execution ID."],"exampleFix":"// before\nexecutionService.replay(execution, flow, \"nonexistentTaskRunId\", null, Optional.empty());\n// after\nList<TaskRun> taskRuns = execution.getTaskRunList();\nif (taskRuns == null || taskRuns.stream().noneMatch(tr -> tr.getId().equals(taskRunId))) {\n    throw new IllegalArgumentException(\"TaskRun \" + taskRunId + \" not found in execution \" + execution.getId());\n}\nexecutionService.replay(execution, flow, taskRunId, null, Optional.empty());","handlingStrategy":"validation","validationCode":"// Validate taskRunId exists and has restartable tasks before calling restart/replay\nList<TaskRun> taskRuns = execution.getTaskRunList();\nif (ListUtils.isEmpty(taskRuns)) {\n    throw new IllegalArgumentException(\"Execution has no task runs to restart\");\n}\n// For replay: verify the taskRunId exists\nif (taskRunId != null && taskRuns.stream().noneMatch(tr -> tr.getId().equals(taskRunId))) {\n    throw new IllegalArgumentException(\"TaskRun '\" + taskRunId + \"' not found in execution \" + execution.getId());\n}\n// For restart: verify at least one task run is restartable\nboolean anyRestartable = taskRuns.stream().anyMatch(tr -> tr.getState().canBeRestarted());\nif (!anyRestartable) {\n    throw new IllegalArgumentException(\"No restartable task runs found in execution \" + execution.getId());\n}","typeGuard":null,"tryCatchPattern":"try {\n    Execution restarted = executionService.restart(execution, flow, revision);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"No task found to restart execution from!\")) {\n        log.warn(\"No restartable tasks in execution {}. Consider triggering a new execution instead.\", execution.getId());\n        throw e;\n    }\n    throw e;\n}","preventionTips":["Verify the taskRunId exists in the execution before replaying.","Check that at least one task run is restartable before calling restart.","If the execution was already restarted, a fresh execution may be needed instead.","Inspect the task run list and states to understand what is restartable."],"tags":["execution","restart","replay","taskrun","validation"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}