{"record":{"id":"2e027b3e837072a5","repo":"apache/dolphinscheduler","slug":"task-instance-not-found","errorCode":"TASK_INSTANCE_NOT_FOUND","errorMessage":"TASK_INSTANCE_NOT_FOUND","messagePattern":"TASK_INSTANCE_NOT_FOUND","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/LoggerServiceImpl.java","lineNumber":138,"sourceCode":"    /**\n     * query log\n     *\n     * @param loginUser   login user\n     * @param projectCode project code\n     * @param taskInstId  task instance id\n     * @param skipLineNum skip line number\n     * @param limit       limit\n     * @return log string data\n     */\n    @Override\n    @SuppressWarnings(\"unchecked\")\n    public String queryLog(User loginUser, long projectCode, int taskInstId, int skipLineNum, int limit) {\n        // check user access for project\n        projectService.checkProjectAndAuthThrowException(loginUser, projectCode, VIEW_LOG);\n        // check whether the task instance can be found\n        TaskInstance task = taskInstanceDao.queryById(taskInstId);\n        if (task == null || StringUtils.isBlank(task.getHost())) {\n            throw new ServiceException(Status.TASK_INSTANCE_NOT_FOUND);\n        }\n\n        TaskDefinition taskDefinition = taskDefinitionDao.queryByCode(task.getTaskCode());\n        if (taskDefinition != null && projectCode != taskDefinition.getProjectCode()) {\n            throw new ServiceException(Status.TASK_INSTANCE_NOT_FOUND, taskInstId);\n        }\n        return queryLog(task, skipLineNum, limit);\n    }\n\n    /**\n     * get log bytes\n     *\n     * @param loginUser   login user\n     * @param projectCode project code\n     * @param taskInstId  task instance id\n     * @return log byte array\n     */\n    @Override","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/LoggerServiceImpl.java#L120-L156","documentation":"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.","triggerScenarios":"(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.","commonSituations":"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.","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."],"exampleFix":"// before: mismatched project code\nGET /projects/1111/log/detail?taskInstId=55 (task 55 belongs to project 2222)\n// after\nGET /projects/2222/log/detail?taskInstId=55","handlingStrategy":"try-catch","validationCode":"TaskInstance task = taskInstanceDao.queryById(taskInstId);\nif (task == null || StringUtils.isBlank(task.getHost())) throw new ServiceException(Status.TASK_INSTANCE_NOT_FOUND);\nTaskDefinition def = taskDefinitionDao.queryByCode(task.getTaskCode());\nif (def == null || projectCode != def.getProjectCode()) throw new ServiceException(Status.TASK_INSTANCE_NOT_FOUND, taskInstId);","typeGuard":"boolean canViewLog(long projectCode, int taskInstId) {\n    TaskInstance t = taskInstanceDao.queryById(taskInstId);\n    return t != null && StringUtils.isNotBlank(t.getHost())\n        && taskDefinitionDao.queryByCode(t.getTaskCode()) != null\n        && taskDefinitionDao.queryByCode(t.getTaskCode()).getProjectCode() == projectCode;\n}","tryCatchPattern":"try {\n    String log = loggerService.queryLog(loginUser, projectCode, taskInstId, skip, limit);\n} catch (ServiceException e) {\n    if (e.getCode() == Status.TASK_INSTANCE_NOT_FOUND.getCode()) {\n        // show 'task instance not found in this project' and offer re-run\n    } else { throw e; }\n}","preventionTips":["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."],"tags":["logging","task-instance","not-found","cross-project"],"backgroundTag":"task-instance-not-found","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"}