{"record":{"id":"d67eea2e53ccc768","repo":"flowable/flowable-engine","slug":"could-not-find-a-task-instance-with-id-taskid-d67eea","errorCode":null,"errorMessage":"Could not find a task instance with id '\" + taskId + \"'.","messagePattern":"Could not find a task instance with id '\" \\+ taskId \\+ \"'\\.","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":404,"severity":"error","filePath":"modules/flowable-rest/src/main/java/org/flowable/rest/service/api/history/HistoricTaskInstanceBaseResource.java","lineNumber":335,"sourceCode":"     */\n    protected HistoricTaskInstance getHistoricTaskInstanceFromRequest(String taskId) {\n        HistoricTaskInstance taskInstance = getHistoricTaskInstanceFromRequestWithoutAccessCheck(taskId);\n\n        if (restApiInterceptor != null) {\n            restApiInterceptor.accessHistoryTaskInfoById(taskInstance);\n        }\n\n        return taskInstance;\n    }\n\n    /**\n     * Returns the {@link HistoricTaskInstance} that is requested without calling the access interceptor\n     * Throws the right exceptions when bad request was made or instance was not found.\n     */\n    protected HistoricTaskInstance getHistoricTaskInstanceFromRequestWithoutAccessCheck(String taskId) {\n        HistoricTaskInstance taskInstance = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();\n        if (taskInstance == null) {\n            throw new FlowableObjectNotFoundException(\"Could not find a task instance with id '\" + taskId + \"'.\", HistoricTaskInstance.class);\n        }\n        \n        return taskInstance;\n    }\n\n    protected void addTaskVariables(HistoricTaskInstanceQuery taskInstanceQuery, List<QueryVariable> variables) {\n        for (QueryVariable variable : variables) {\n            if (variable.getVariableOperation() == null) {\n                throw new FlowableIllegalArgumentException(\"Variable operation is missing for variable: \" + variable.getName());\n            }\n            if (variable.getVariableOperation() != QueryVariableOperation.EXISTS && variable.getVariableOperation() != QueryVariableOperation.NOT_EXISTS) {\n                if (variable.getValue() == null) {\n                    throw new FlowableIllegalArgumentException(\"Variable value is missing for variable: \" + variable.getName());\n                }\n            }\n\n            boolean nameLess = variable.getName() == null;\n","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-rest/src/main/java/org/flowable/rest/service/api/history/HistoricTaskInstanceBaseResource.java#L317-L353","documentation":"The history task lookup via historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult() returned null, so Flowable throws FlowableObjectNotFoundException typed to HistoricTaskInstance. It means no historic task with that id exists in the history tables.","triggerScenarios":"Any history task endpoint (getHistoricTaskInstanceFromRequestWithoutAccessCheck) with a taskId that does not exist, was never completed/persisted to history, or belongs to a different engine.","commonSituations":"Task is still active (not yet in history); using the runtime task id against history after the task was deleted without history; pointing at the wrong database/tenant; id truncation in client code.","solutions":["Confirm the task id via runtime TaskService query if the task is still active","Query ACT_HI_TASKINST (or the history task query) to verify the id exists in history","If the task must be historic, ensure history level records tasks ('audit' or higher)","Check tenant/datasource configuration to ensure you query the engine that owns the task"],"exampleFix":"// before\nHistoricTaskInstance t = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();\nhistoricTaskApi.get(taskId); // throws\n// after\nHistoricTaskInstance t = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();\nif (t == null) {\n    Task active = taskService.createTaskQuery().taskId(taskId).singleResult();\n    if (active != null) { /* task still running: use runtime endpoints */ }\n}","handlingStrategy":"try-catch","validationCode":"HistoricTaskInstance t = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();\nif (t == null) { /* task not in history; check runtime taskService */ }","typeGuard":null,"tryCatchPattern":"try { HistoricTaskInstance t = api.getHistoricTask(taskId); }\ncatch (FlowableObjectNotFoundException e) { /* fall back to runtime task query */ }","preventionTips":["Check the runtime task query when the task may still be active","Validate taskId format/source before the call","Ensure you are querying the correct engine/tenant datasource"],"tags":["rest-api","history","task","not-found","flowable"],"backgroundTag":"resource-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}