apache/dolphinscheduler · error · ServiceException
10166
10166
Error message
the status of task instance {taskInstanceId} is {taskState},Cannot perform force success operation What it means
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.
Source
Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java:217
TaskInstance task = taskInstanceDao.queryOptionalById(taskInstanceId)
.orElseThrow(() -> new ServiceException(Status.TASK_INSTANCE_NOT_FOUND));
if (task.getProjectCode() != projectCode) {
throw new ServiceException("The task instance is not under the project: " + projectCode);
}
WorkflowInstance workflowInstance = workflowInstanceDao.queryOptionalById(task.getWorkflowInstanceId())
.orElseThrow(
() -> new ServiceException(Status.WORKFLOW_INSTANCE_NOT_EXIST, task.getWorkflowInstanceId()));
if (!workflowInstance.getState().isFinalState()) {
throw new ServiceException("The workflow instance is not finished: " + workflowInstance.getState()
+ " cannot force start task instance");
}
// check whether the task instance state type is failure or cancel
if (!task.getState().isFailure() && !task.getState().isKill()) {
throw new ServiceException(Status.TASK_INSTANCE_STATE_OPERATION_ERROR, taskInstanceId, task.getState());
}
// change the state of the task instance
task.setState(TaskExecutionStatus.FORCED_SUCCESS);
task.setEndTime(new Date());
boolean changed = taskInstanceDao.updateById(task);
if (!changed) {
throw new ServiceException(Status.FORCE_TASK_SUCCESS_ERROR);
}
processService.forceWorkflowInstanceSuccessByTaskInstanceId(task);
log.info("Force success task instance id: {} success", taskInstanceId);
}
@Override
public Result taskSavePoint(User loginUser, long projectCode, Integer taskInstanceId) {
Result result = new Result();
Project project = projectDao.queryByCode(projectCode);View on GitHub (pinned to 02eac45a1b)
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.
Example fix
// before
taskInstanceApi.forceSuccess(id); // rejects non-failure/kill states
// after
TaskInstance t = taskInstanceApi.get(id);
if (t.getState() == "FAILURE" || t.getState() == "KILL") {
taskInstanceApi.forceSuccess(id);
} Defensive patterns
Strategy: validation
Validate before calling
TaskInstance t = taskInstanceDao.queryOptionalById(id).orElse(null);
if (t == null || !(t.getState().isFailure() || t.getState().isKill())) {
throw new IllegalStateException("task state " + (t == null ? null : t.getState()) + " is not forceable");
} Type guard
boolean canForceSuccess(TaskInstance t) { return t != null && (t.getState().isFailure() || t.getState().isKill()); } Try / catch
try {
taskInstanceService.forceTaskSuccess(loginUser, projectCode, id);
} catch (ServiceException e) {
if (e.getCode() == 10166) {
// task already succeeded/resumed; treat as no-op, refresh state
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- The workflow instance is not finished: {workflowInstanceStat
- USER_NO_OPERATION_PERM
- REQUEST_PARAMS_NOT_VALID_ERROR
- ACCESS_TOKEN_NOT_EXIST
- ALERT_GROUP_EXIST
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/96155470efed0693.
Report an issue: GitHub.