{"record":{"id":"c2ae48480ecf750a","repo":"apache/dolphinscheduler","slug":"the-workflow-workflowname-state-act","errorCode":null,"errorMessage":"\"The workflow: \" + workflowName + \" state: \" + actualState + \" is not match:\" + expectState","messagePattern":"\"The workflow: \" \\+ workflowName \\+ \" state: \" \\+ actualState \\+ \" is not match:\" \\+ expectState","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/workflow/statemachine/AbstractWorkflowStateAction.java","lineNumber":217,"sourceCode":"     */\n    protected abstract void emitWorkflowFinishedEventIfApplicable(final IWorkflowExecution workflowExecution);\n\n    protected boolean isWorkflowFinishable(final IWorkflowExecution workflowExecution) {\n        return workflowExecution.getWorkflowExecutionGraph().isAllTaskExecutionChainFinish();\n    }\n\n    /**\n     * Assert that the state of the task is the expected state.\n     *\n     * @throws IllegalStateException if the state of the task is not the expected state.\n     */\n    protected void throwExceptionIfStateIsNotMatch(final IWorkflowExecution workflowExecution) {\n        checkNotNull(workflowExecution, \"workflowExecution is null\");\n        final WorkflowExecutionStatus actualState = workflowExecution.getState();\n        final WorkflowExecutionStatus expectState = matchState();\n        if (actualState != expectState) {\n            final String workflowName = workflowExecution.getName();\n            throw new IllegalStateException(\n                    \"The workflow: \" + workflowName + \" state: \" + actualState + \" is not match:\" + expectState);\n        }\n    }\n\n    protected void logWarningIfCannotDoAction(final IWorkflowExecution workflowExecution,\n                                              final AbstractLifecycleEvent event) {\n        log.warn(\"Workflow {} state is {} cannot do action on event: {}\",\n                workflowExecution.getName(),\n                workflowExecution.getState(),\n                event);\n    }\n\n    protected void finalizeEventAction(final IWorkflowExecution workflowExecution) {\n        log.info(WorkflowInstanceUtils.logWorkflowInstanceInDetails(workflowExecution));\n\n        workflowCacheRepository.remove(workflowExecution.getId());\n        workflowEventBusCoordinator.unRegisterWorkflowEventBus(workflowExecution);\n        workflowAlertManager.sendAlertWorkflowInstance(workflowExecution.getWorkflowInstance());","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/workflow/statemachine/AbstractWorkflowStateAction.java#L199-L235","documentation":"Protected helper in AbstractWorkflowStateAction that verifies the workflow execution's current state matches the state handled by this state action subclass before performing an action. A mismatch means an event was routed to the wrong state handler — a state-machine invariant breach.","triggerScenarios":"A workflow lifecycle event (e.g. task success/failure) delivered while the workflow execution is in a different state than the handler expects (e.g. a 'stop' event handled by RunningStateAction when the workflow already failed).","commonSituations":"Concurrent events racing during failover, duplicate events after master restart, event bus delivering stale events for already-finished workflows.","solutions":["Log workflow name, actual and expected state to identify the racing event","Check for duplicate/stale events in the execution event bus","Verify master failover isn't replaying old events","Retry or drop the event gracefully after confirming the workflow's actual state"],"exampleFix":"// before\nstateAction.doAction(workflowExecution, event); // may throw on mismatch\n// after\nif (stateAction.matchState() == workflowExecution.getState()) {\n    stateAction.doAction(workflowExecution, event);\n} else {\n    log.warn(\"Skipping event {} for {} in state {}\", event, workflowExecution.getName(), workflowExecution.getState());\n}","handlingStrategy":"validation","validationCode":"if (workflowExecution.getState() != expectedState) { log.warn(\"state mismatch: {} vs {}\", workflowExecution.getState(), expectedState); return; }","typeGuard":null,"tryCatchPattern":"try { stateAction.doAction(workflowExecution, event); } catch (IllegalStateException e) { log.warn(\"stale event skipped: {}\", e.getMessage()); }","preventionTips":["De-duplicate workflow events by execution id and state","Drain/reconcile the event bus after failover","Only dispatch events through the state-machine router matching current state"],"tags":["java","state-machine","workflow"],"backgroundTag":"invalid-state-transition","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}