{"record":{"id":"7e2259214c388a24","repo":"flowable/flowable-engine","slug":"no-historic-task-instance-found-with-id","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-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DeleteHistoricTaskInstanceCmd.java","lineNumber":51,"sourceCode":"    \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.getCmmnHistoryManager(commandContext).recordHistoricTaskDeleted(historicTaskInstance);\n        \n        return null;\n    }\n\n}\n","sourceCodeStart":33,"sourceCodeEnd":63,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DeleteHistoricTaskInstanceCmd.java#L33-L63","documentation":"DeleteHistoricTaskInstanceCmd throws FlowableObjectNotFoundException when no historic task instance exists for the given taskId in the CMMN engine's history tables. History rows only exist if history is enabled and the task was recorded. The command refuses to proceed because there is nothing to delete.","triggerScenarios":"Calling CmmnHistoryService.deleteHistoricTaskInstance(taskId) (via HistoricTaskService.getHistoricTask returning null) with a taskId that never existed, was already deleted, or whose task was never recorded in history (history level off / task still running).","commonSituations":"Retrying a delete after the first one succeeded; deleting historic tasks from a different engine instance than the one that recorded them; running with history level NONE so no historic task rows are written; typo'ed or stale task IDs from external integrations.","solutions":["Verify the taskId exists via cmmnHistoryService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult() before deleting.","Check the flowable history level configuration (e.g. 'full'/'audit') to ensure historic tasks are actually recorded.","Handle the FlowableObjectNotFoundException and treat the delete as a no-op if the record is already gone."],"exampleFix":"// before\nhistoryService.deleteHistoricTaskInstance(taskId);\n// after\nHistoricTaskInstance hti = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();\nif (hti != null) {\n    historyService.deleteHistoricTaskInstance(taskId);\n}","handlingStrategy":"validation","validationCode":"if (taskId == null || historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult() == null) { throw new IllegalStateException(\"no historic task \" + taskId); }\nhistoryService.deleteHistoricTaskInstance(taskId);","typeGuard":null,"tryCatchPattern":"try { historyService.deleteHistoricTaskInstance(taskId); } catch (FlowableObjectNotFoundException e) { log.warn(\"Historic task {} already gone\", taskId); }","preventionTips":["Always query for the historic task before deleting.","Ensure history level records tasks (audit/full), not NONE.","Treat not-found deletes as idempotent no-ops in cleanup jobs."],"tags":["cmmn","history","not-found","java"],"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-14T11:17:12.474Z"}