{"record":{"id":"26e8792658b35c8c","repo":"flowable/flowable-engine","slug":"no-historic-task-instance-found-with-id-26e879","errorCode":null,"errorMessage":"No historic task instance found with id: ","messagePattern":"No historic task instance found with id: ","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteHistoricTaskInstanceCmd.java","lineNumber":50,"sourceCode":"    private static final long serialVersionUID = 1L;\n    protected String taskId;\n\n    public DeleteHistoricTaskInstanceCmd(String taskId) {\n        this.taskId = taskId;\n    }\n\n    @Override\n    public Object execute(CommandContext commandContext) {\n\n        if (taskId == null) {\n            throw new FlowableIllegalArgumentException(\"taskId is null\");\n        }\n\n        // Check if task is completed\n        HistoricTaskInstanceEntity historicTaskInstance = CommandContextUtil.getHistoricTaskService().getHistoricTask(taskId);\n\n        if (historicTaskInstance == null) {\n            throw new FlowableObjectNotFoundException(\"No historic task instance found with id: \" + taskId, HistoricTaskInstance.class);\n        }\n        if (historicTaskInstance.getEndTime() == null) {\n            throw new FlowableException(\"task does not have an endTime, cannot delete \" + historicTaskInstance);\n        }\n\n        CommandContextUtil.getHistoryManager(commandContext).recordHistoricTaskDeleted(historicTaskInstance);\n        \n        return null;\n    }\n\n}\n","sourceCodeStart":32,"sourceCodeEnd":62,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteHistoricTaskInstanceCmd.java#L32-L62","documentation":"Lookup failure in DeleteHistoricTaskInstanceCmd.execute: taskId passed the null check, but no historic task instance exists in the history store with that id (already deleted, or the task never ended/never existed historically).","triggerScenarios":"historyService.deleteHistoricTask(taskId) with an id that does not match any row in ACT_HI_TASKINST: wrong id, task not yet created in history, history level too low to record tasks, or history cleanup already removed it.","commonSituations":"Running with history level 'none' or 'activity' so tasks are not recorded, using the runtime taskId after purge/cleanup jobs, or cross-environment ids (test id used against prod engine).","solutions":["Verify the task exists via historyService.createHistoricTaskInstanceQuery().taskId(id).singleResult() before deleting","Check the engine history level is at least 'audit' so tasks are recorded","Confirm you are using the taskId from the same engine/database as the delete call"],"exampleFix":"// before\nhistoryService.deleteHistoricTask(taskId);\n// after\nHistoricTaskInstance hti = historyService.createHistoricTaskInstanceQuery()\n    .taskId(taskId).singleResult();\nif (hti != null) {\n    historyService.deleteHistoricTask(taskId);\n}","handlingStrategy":"validation","validationCode":"HistoricTaskInstance hti = historyService.createHistoricTaskInstanceQuery()\n    .taskId(taskId).singleResult();\nif (hti == null) {\n    logger.warn(\"No historic task for id \" + taskId + \", skipping delete\");\n    return;\n}","typeGuard":"boolean historicTaskExists = id -> historyService.createHistoricTaskInstanceQuery()\n    .taskId(id).count() > 0;","tryCatchPattern":"try {\n    historyService.deleteHistoricTask(taskId);\n} catch (FlowableObjectNotFoundException e) {\n    logger.info(\"Historic task already gone: \" + taskId);\n}","preventionTips":["Ensure history level is at least 'audit' so tasks are recorded","Existence-check before delete in cleanup scripts","Use ids from the same engine/database instance"],"tags":["flowable","not-found","history","task"],"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"}