apache/dolphinscheduler · error · ServiceException
TASK_INSTANCE_NOT_FOUND
TASK_INSTANCE_NOT_FOUND
Error message
TASK_INSTANCE_NOT_FOUND
What it means
queryLog first verifies the task instance exists and has a host; if not, it throws Status.TASK_INSTANCE_NOT_FOUND. A second throw occurs when the instance exists but its task definition belongs to a different project code than the one in the request, preventing cross-project log reads.
Source
Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/LoggerServiceImpl.java:138
/**
* query log
*
* @param loginUser login user
* @param projectCode project code
* @param taskInstId task instance id
* @param skipLineNum skip line number
* @param limit limit
* @return log string data
*/
@Override
@SuppressWarnings("unchecked")
public String queryLog(User loginUser, long projectCode, int taskInstId, int skipLineNum, int limit) {
// check user access for project
projectService.checkProjectAndAuthThrowException(loginUser, projectCode, VIEW_LOG);
// check whether the task instance can be found
TaskInstance task = taskInstanceDao.queryById(taskInstId);
if (task == null || StringUtils.isBlank(task.getHost())) {
throw new ServiceException(Status.TASK_INSTANCE_NOT_FOUND);
}
TaskDefinition taskDefinition = taskDefinitionDao.queryByCode(task.getTaskCode());
if (taskDefinition != null && projectCode != taskDefinition.getProjectCode()) {
throw new ServiceException(Status.TASK_INSTANCE_NOT_FOUND, taskInstId);
}
return queryLog(task, skipLineNum, limit);
}
/**
* get log bytes
*
* @param loginUser login user
* @param projectCode project code
* @param taskInstId task instance id
* @return log byte array
*/
@OverrideView on GitHub (pinned to 02eac45a1b)
Solutions
- Verify taskInstId exists and its host is set before querying.
- Check the task definition of that instance and pass its actual projectCode in the URL.
- Refresh the page/link so the UI resolves the current project code for the task.
- If the instance was purged, re-run the task to obtain logs.
Example fix
// before: mismatched project code GET /projects/1111/log/detail?taskInstId=55 (task 55 belongs to project 2222) // after GET /projects/2222/log/detail?taskInstId=55
Defensive patterns
Strategy: try-catch
Validate before calling
TaskInstance task = taskInstanceDao.queryById(taskInstId); if (task == null || StringUtils.isBlank(task.getHost())) throw new ServiceException(Status.TASK_INSTANCE_NOT_FOUND); TaskDefinition def = taskDefinitionDao.queryByCode(task.getTaskCode()); if (def == null || projectCode != def.getProjectCode()) throw new ServiceException(Status.TASK_INSTANCE_NOT_FOUND, taskInstId);
Type guard
boolean canViewLog(long projectCode, int taskInstId) {
TaskInstance t = taskInstanceDao.queryById(taskInstId);
return t != null && StringUtils.isNotBlank(t.getHost())
&& taskDefinitionDao.queryByCode(t.getTaskCode()) != null
&& taskDefinitionDao.queryByCode(t.getTaskCode()).getProjectCode() == projectCode;
} Try / catch
try {
String log = loggerService.queryLog(loginUser, projectCode, taskInstId, skip, limit);
} catch (ServiceException e) {
if (e.getCode() == Status.TASK_INSTANCE_NOT_FOUND.getCode()) {
// show 'task instance not found in this project' and offer re-run
} else { throw e; }
} Prevention
- Always derive projectCode from the task definition, not from cached UI state.
- Check task instance existence before deep-linking to log detail pages.
- Watch for DB cleanup jobs that delete task instances referenced by old URLs.
- Test log viewing after environment clones/migrations where project codes shift.
When it happens
Trigger: (1) GET /log/detail with a taskInstId not present in t_ds_task_instance or with a blank host. (2) The instance exists, but the taskDefinition's projectCode differs from the projectCode path parameter — the log belongs to another project.
Common situations: UI constructed the URL with the wrong projectCode; task instance purged by cleanup jobs; environment copied between instances so task codes map to different projects; typo in taskInstId.
Related errors
- task instance is null or host is null
- 10103
- Can not find any datasource by name %s
- Can not find valid workflow by name %s
- Can not find valid project by name %s
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/2e027b3e837072a5.
Report an issue: GitHub.