{"record":{"id":"ee25a92cfedfa562","repo":"flowable/flowable-engine","slug":"could-not-find-a-task-instance-with-id-taskid","errorCode":null,"errorMessage":"Could not find a task instance with id '${taskId}'.","messagePattern":"Could not find a task instance with id '(.+?)'\\.","errorType":"http","errorClass":"FlowableObjectNotFoundException","httpStatus":404,"severity":"error","filePath":"modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/history/task/HistoricTaskInstanceBaseResource.java","lineNumber":316,"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":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/history/task/HistoricTaskInstanceBaseResource.java#L298-L334","documentation":"FlowableObjectNotFoundException thrown when a historic task instance cannot be found for the supplied taskId. getHistoricTaskInstanceFromRequestWithoutAccessCheck performs the lookup via HistoricTaskInstanceQuery and throws when no row matches; shared by many historic-task REST endpoints. Note this path skips the access interceptor check.","triggerScenarios":"Any GET on /cmmn-history/historic-task-instances/{taskId} (or sub-resources like variables/identity links) where the taskId does not match a historic task row - task purged by history cleanup, wrong database, or a runtime task id passed where only historic ids are valid.","commonSituations":"Using the runtime Task id after task completion; history cleaner removed old records; typo'd or fabricated ids; querying the wrong engine datasource in multi-datasource setups.","solutions":["Confirm the task exists via GET /cmmn-history/historic-task-instances with query filters and copy the exact historic task id.","Catch FlowableObjectNotFoundException and map it to HTTP 404.","Check the history cleanup configuration and retention period.","Verify you are not passing a runtime task id to a history-only endpoint after process completion.","Confirm the correct Flowable engine/datasource is being queried."],"exampleFix":"// before\nHistoricTaskInstance t = historyService.createHistoricTaskInstanceQuery().taskId(id).singleResult();\n// after\nHistoricTaskInstance t = historyService.createHistoricTaskInstanceQuery().taskId(id).singleResult();\nif (t == null) {\n    return ResponseEntity.notFound().build();\n}","handlingStrategy":"try-catch","validationCode":"// ensure the id exists in history before use\nList<HistoricTaskInstanceResponse> hits = query(\"/cmmn-history/historic-task-instances?taskId=\" + id);","typeGuard":null,"tryCatchPattern":"try {\n    HistoricTaskInstanceResponse t = getHistoricTask(id);\n} catch (FlowableObjectNotFoundException e) {\n    return ResponseEntity.notFound().build();\n}","preventionTips":["Distinguish runtime task ids from historic task ids.","Configure history cleanup retention to match data-access needs.","Always null-check singleResult() in custom code built on these queries.","Use the same datasource/engine for id generation and lookup."],"tags":["flowable","rest","history","task-not-found"],"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"}