apache/dolphinscheduler · error · ServiceException

The task instance is not under the project: {projectCode}

Error message

The task instance is not under the project: {projectCode}

What it means

Thrown by TaskInstanceServiceImpl.forceTaskSuccess when the task instance being force-succeeded belongs to a different project than the projectCode supplied in the request. It is a tenant/project scoping guard: DolphinScheduler requires the task instance to reside under the project the caller claims it is in. The raw string message (not a Status enum) means the client passed a mismatched projectCode/taskInstanceId pair.

Source

Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java:204

    /**
     * change one task instance's state from failure to forced success
     *
     * @param loginUser      login user
     * @param projectCode    project code
     * @param taskInstanceId task instance id
     * @return the result code and msg
     */
    @Transactional
    @Override
    public void forceTaskSuccess(User loginUser, long projectCode, Integer taskInstanceId) {
        projectService.checkHasProjectWritePermissionThrowException(loginUser, projectCode);

        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());

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Verify the taskInstanceId actually belongs to the projectCode you pass (query the task instance list scoped to that project first).
  2. Correct the projectCode in your request URL/body to match the project that owns the task.
  3. If automating, resolve the task's project via the API instead of hardcoding the code.
  4. Ensure your user has write permission on the correct project (a wrong project often also fails the earlier permission check).

Example fix

// before
curl -X POST '.../projects/123456789/task-instance/987/force-success'
// after
// look up the task's real project code first, then use it
curl -X POST ".../projects/${TASK_PROJECT_CODE}/task-instance/${TASK_INSTANCE_ID}/force-success"
Defensive patterns

Strategy: validation

Validate before calling

// Java caller: confirm the task belongs to the project before calling
TaskInstanceResponse t = taskInstanceService.queryByInstanceId(id);
if (t == null || !Objects.equals(t.getProjectCode(), projectCode)) {
    throw new IllegalArgumentException("task " + id + " is not in project " + projectCode);
}

Type guard

boolean belongsToProject(TaskInstance t, long projectCode) { return t != null && t.getProjectCode() == projectCode; }

Try / catch

try {
    taskInstanceService.forceTaskSuccess(loginUser, projectCode, id);
} catch (ServiceException e) {
    if (e.getMessage().contains("not under the project")) {
        // re-resolve correct projectCode for this task instance
    }
}

Prevention

When it happens

Trigger: Calling the force-task-success API where task.getProjectCode() != projectCode, i.e. the taskInstanceId resolves to a task under a different project than the projectCode path/body parameter.

Common situations: Using a stale taskInstanceId copied from another project; copy-pasting an example curl with the wrong projectCode; automation that looks up task IDs in a global table instead of per-project; projects renamed/re-created so codes changed.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/219a4f96639be68e. Report an issue: GitHub.