{"record":{"id":"96155470efed0693","repo":"apache/dolphinscheduler","slug":"10166","errorCode":"10166","errorMessage":"the status of task instance {taskInstanceId} is {taskState},Cannot perform force success operation","messagePattern":"the status of task instance (.+?) is (.+?),Cannot perform force success operation","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java","lineNumber":217,"sourceCode":"\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    }\n\n    @Override\n    public Result taskSavePoint(User loginUser, long projectCode, Integer taskInstanceId) {\n        Result result = new Result();\n\n        Project project = projectDao.queryByCode(projectCode);","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java#L199-L235","documentation":"Status.TASK_INSTANCE_STATE_OPERATION_ERROR, raised by forceTaskSuccess when the task instance's state is neither failure nor kill. Only failed or killed task instances can be force-marked as successful; tasks that are running, success, or pending are rejected with this error carrying the current state in the message.","triggerScenarios":"Calling force-task-success on a task whose state is e.g. RUNNING_EXECUTION, SUCCESS, SUBMITTED_SUCCESS, or PAUSE — anything where isFailure() && isKill() are both false.","commonSituations":"Double-clicking the force-success button after the first click already succeeded; scripting retries against a task that has since resumed/finished; trying to force-succeed a queued task to skip it.","solutions":["Check the task instance's current state first; only call force-success when it is FAILURE or KILL.","If the task already succeeded, no action is needed — refresh the instance list.","For running tasks you want to end, kill the task/workflow first, then force-success.","Make automation idempotent: treat 'state operation error' as 'already handled' rather than retrying."],"exampleFix":"// before\ntaskInstanceApi.forceSuccess(id); // rejects non-failure/kill states\n// after\nTaskInstance t = taskInstanceApi.get(id);\nif (t.getState() == \"FAILURE\" || t.getState() == \"KILL\") {\n    taskInstanceApi.forceSuccess(id);\n}","handlingStrategy":"validation","validationCode":"TaskInstance t = taskInstanceDao.queryOptionalById(id).orElse(null);\nif (t == null || !(t.getState().isFailure() || t.getState().isKill())) {\n    throw new IllegalStateException(\"task state \" + (t == null ? null : t.getState()) + \" is not forceable\");\n}","typeGuard":"boolean canForceSuccess(TaskInstance t) { return t != null && (t.getState().isFailure() || t.getState().isKill()); }","tryCatchPattern":"try {\n    taskInstanceService.forceTaskSuccess(loginUser, projectCode, id);\n} catch (ServiceException e) {\n    if (e.getCode() == 10166) {\n        // task already succeeded/resumed; treat as no-op, refresh state\n    }\n}","preventionTips":["Check task state == FAILURE or KILL before calling","Make retries idempotent (refresh state, treat 10166 as done)","Kill running tasks before force-success","Disable double-click on the UI button"],"tags":["api","task-state","precondition-failed","idempotency"],"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-14T00:17:10.932Z"}