{"record":{"id":"79359acedc594973","repo":"apache/dolphinscheduler","slug":"the-workflow-instance-is-not-finished-workflowin","errorCode":null,"errorMessage":"The workflow instance is not finished: {workflowInstanceState} cannot force start task instance","messagePattern":"The workflow instance is not finished: (.+?) cannot force start task instance","errorType":"exception","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java","lineNumber":211,"sourceCode":"     * @return the result code and msg\n     */\n    @Transactional\n    @Override\n    public void forceTaskSuccess(User loginUser, long projectCode, Integer taskInstanceId) {\n        projectService.checkHasProjectWritePermissionThrowException(loginUser, projectCode);\n\n        TaskInstance task = taskInstanceDao.queryOptionalById(taskInstanceId)\n                .orElseThrow(() -> new ServiceException(Status.TASK_INSTANCE_NOT_FOUND));\n\n        if (task.getProjectCode() != projectCode) {\n            throw new ServiceException(\"The task instance is not under the project: \" + projectCode);\n        }\n\n        WorkflowInstance workflowInstance = workflowInstanceDao.queryOptionalById(task.getWorkflowInstanceId())\n                .orElseThrow(\n                        () -> new ServiceException(Status.WORKFLOW_INSTANCE_NOT_EXIST, task.getWorkflowInstanceId()));\n        if (!workflowInstance.getState().isFinalState()) {\n            throw new ServiceException(\"The workflow instance is not finished: \" + workflowInstance.getState()\n                    + \" cannot force start task instance\");\n        }\n\n        // check whether the task instance state type is failure or cancel\n        if (!task.getState().isFailure() && !task.getState().isKill()) {\n            throw new ServiceException(Status.TASK_INSTANCE_STATE_OPERATION_ERROR, taskInstanceId, task.getState());\n        }\n\n        // change the state of the task instance\n        task.setState(TaskExecutionStatus.FORCED_SUCCESS);\n        task.setEndTime(new Date());\n        boolean changed = taskInstanceDao.updateById(task);\n        if (!changed) {\n            throw new ServiceException(Status.FORCE_TASK_SUCCESS_ERROR);\n        }\n        processService.forceWorkflowInstanceSuccessByTaskInstanceId(task);\n        log.info(\"Force success task instance id: {} success\", taskInstanceId);\n    }","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java#L193-L229","documentation":"Thrown by TaskInstanceServiceImpl.forceTaskSuccess when the parent workflow instance is still running (its state is not a final state). Force-success is only permitted once the enclosing workflow has finished; otherwise dependent bookkeeping (e.g. forceWorkflowInstanceSuccessByTaskInstanceId) would be inconsistent. The message embeds the current workflow state so you can see why it was rejected.","triggerScenarios":"POSTing force-task-success for a task whose workflow instance state isRunning/isReadyPause/etc. (any non-final state such as RUNNING_EXECUTION, WAITING_THREAD, READY_STOP).","commonSituations":"Users try to 'unstick' a running workflow by force-succeeding one failed task; schedulers retry the call while the workflow is still active; kill is in progress so state is not yet final.","solutions":["Wait until the workflow instance reaches a final state (SUCCESS/FAILURE/STOP/KILL) before calling force-task-success.","If the workflow should be stopped first, stop/kill the workflow instance, then force-success the task.","Poll the workflow instance state endpoint until isFinalState before retrying.","If you really need to modify a running workflow, use the workflow-level stop/pause operations instead."],"exampleFix":"// before\nforceSuccess(taskInstanceId); // workflow still RUNNING -> 301\n// after\nWorkflowInstance wf = getWorkflowInstance(taskInstanceId);\nif (wf.getState().isFinalState()) {\n    forceSuccess(taskInstanceId);\n} else {\n    stopWorkflowInstance(wf.getId());\n}","handlingStrategy":"validation","validationCode":"WorkflowInstance wf = workflowInstanceDao.queryOptionalById(task.getWorkflowInstanceId()).orElse(null);\nif (wf == null || !wf.getState().isFinalState()) {\n    throw new IllegalStateException(\"wait for workflow to finish before force-success\");\n}","typeGuard":"boolean forceSuccessAllowed(WorkflowInstance wf) { return wf != null && wf.getState() != null && wf.getState().isFinalState(); }","tryCatchPattern":"try {\n    taskInstanceService.forceTaskSuccess(loginUser, projectCode, id);\n} catch (ServiceException e) {\n    if (e.getMessage().startsWith(\"The workflow instance is not finished\")) {\n        // schedule retry after workflow reaches final state\n    }\n}","preventionTips":["Poll workflow state until final before force-success","Stop/kill the workflow first if it is stuck","Do not use force-success as a workaround for running workflows"],"tags":["api","workflow-state","precondition-failed","task-instance"],"backgroundTag":"invalid-state-transition","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}