Skip to content

[Bug][Master] No reconciliation for stale t_ds_serial_command; workflow can stay RUNNING with a FAILURE task after master crash/failover` #18698

Backlog

Description

@sql-wj

Search before asking

  • I had searched in the issues and found no similar issues.

What happened

Describe the bug

After #18406 (fixed by #18415 in 3.4.3), an architectural gap remains: the "persist task failure to DB" step and the "advance the workflow" step are two non-atomic operations. If the master crashes / restarts / fails over between them, the DB is left with task = FAILURE while workflow = RUNNING. The serial lock (t_ds_serial_command) is not released, so subsequent serial schedules of the same workflow can never trigger.

#18406 only fixes one specific DAG shape (Continue failure strategy + a blocked intermediate predecessor). It does not provide any independent reconciliation for the serial lock.

Which version of DolphinScheduler

3.4.2 (observed); 3.4.3 partially fixed (#18406/#18415). The non-atomicity and the missing serial-lock reconciliation are NOT fixed in 3.4.3.

To Reproduce

  1. Use a workflow whose task can fail.
  2. Make the master crash/restart/failover in the window between the task-failure write to DB and the workflow-advance steps (or otherwise get the workflow stuck while a task is FAILURE).
  3. Observe: t_ds_task_instance.state = FAILURE, t_ds_workflow_instance.state = RUNNING_EXECUTION, and a stale row remains in t_ds_serial_command.
  4. Subsequent serial schedules of the same workflow never trigger.

Root cause

In AbstractTaskStateAction.onFailedEvent():

releaseTaskInstanceResourcesIfNeeded(taskExecution);
persistentTaskInstanceFailedEventToDB(taskExecution, ...);   // (1) persisted to DB
...
graph.markTaskExecutionChainFailure(taskExecution);          // (2) in-memory only
publishWorkflowInstanceTopologyLogicalTransitionEvent(...);  // (3) in-memory only

persistentTaskInstanceFailedEventToDB is a bare taskInstanceDao.updateById(...) with no @Transactional. Steps (2) and (3) live only in master memory. If the master dies after (1) but before (2)/(3) complete, steps (2)/(3) vanish with the memory, leaving task = FAILURE, workflow = RUNNING in the DB.

On failover, the graph is rebuilt from the DB, but the failed task is not reliably re-marked into a failure chain and the workflow terminal event is not triggered — emitWorkflowFinishedEventIfApplicable returns early when !isWorkflowFinishable. The workflow stays RUNNING.

Additionally, WorkflowSerialCoordinator.doStart() (lines 93–109) only handles SERIAL_WAIT / DISCARD / PRIORITY. There is no logic to scan terminal/zombie workflows and recycle their stale t_ds_serial_command rows. Serial-lock cleanup depends 100% on workflowFinish being reached.

Proposed improvement

Add a reconciliation task to WorkflowSerialCoordinator that scans already-terminal / zombie workflows and recycles their residual t_ds_serial_command rows. This is complementary to the #18406 fix (which only covers the Continue + blocked-predecessor shape).

Additional context

What you expected to happen

Once a task is persisted as FAILURE, the workflow should reliably advance
to its terminal state (FAILURE), and its serial lock (t_ds_serial_command)
should be released. Even if the master crashes or fails over in between,
the failover rebuild should recognize the already-failed task, drive the
workflow to a terminal state, and clean up the stale serial command.

Persisting the task failure and advancing the workflow are two separate,
non-atomic steps in AbstractTaskStateAction.onFailedEvent():

1. persistentTaskInstanceFailedEventToDB()  -> bare updateById, no
   @Transactional, written to DB immediately
2. markTaskExecutionChainFailure()          -> in-memory only
3. publishWorkflowInstanceTopologyLogicalTransitionEvent() -> in-memory only

Steps 2 and 3 live only in master memory. If the master crashes/restarts/
fails over after step 1 but before 2-3 finish, steps 2-3 are lost with the
memory, leaving task = FAILURE but workflow = RUNNING in the DB.

Failover rebuilds the graph from the DB but does not reliably re-mark the
failed task into a failure chain or trigger the workflow terminal event
(emitWorkflowFinishedEventIfApplicable returns early when the workflow is
not "finishable"), so the workflow stays RUNNING.

Separately, the serial lock has no independent reconciliation:
WorkflowSerialCoordinator.doStart() only handles SERIAL_WAIT / DISCARD /
PRIORITY and never scans terminal/zombie workflows to recycle their stale
t_ds_serial_command rows. So serial-lock cleanup depends entirely on
workflowFinish being reached, which never happens here.

This is the gap NOT covered by #18406 / #18415 (which only fixed the
Continue + blocked-predecessor DAG shape).

How to reproduce

This is a crash-window / failover defect, so it is best shown by observing
the inconsistent state directly, plus an optional fault-injection trigger.

Path 1 — observe the inconsistent state directly (reliable)

  1. Query for workflows whose task has failed but whose workflow instance is
    still RUNNING. In DolphinScheduler 3.4.x:

    -- task_state / wf_state enum values: verify against TaskExecutionStatus
    -- and WorkflowExecutionStatus; the query below filters on
    -- task = FAILURE and workflow = RUNNING_EXECUTION
    SELECT w.id, w.name, w.state AS wf_state, t.state AS task_state
    FROM t_ds_workflow_instance w
    JOIN t_ds_task_instance t ON t.workflow_instance_id = w.id
    WHERE w.state = /* RUNNING_EXECUTION /
    AND t.state = /
    FAILURE */;

  2. For those workflow ids, a stale serial command remains:

    SELECT * FROM t_ds_serial_command
    WHERE workflow_instance_id IN (<ids from step 1>);

  3. Trigger the same workflow again with serial scheduling: the next run
    never starts because the stale serial lock is never released.

Path 2 — fault injection (best effort, window is hard to hit)

  1. Deploy 3.4.2 and configure a workflow with a task that fails, with serial
    scheduling enabled.
  2. Immediately after the task failure is written to the DB but before the
    workflow advances, force-kill the master (or trigger a failover).
    The window between "persist task failure" and "advance workflow" is
    small, so this may take several attempts.
  3. Restart the master / let failover rebuild the graph from the DB.
  4. Observe: t_ds_task_instance.state = FAILURE,
    t_ds_workflow_instance.state = RUNNING_EXECUTION, and the
    t_ds_serial_command row is never cleaned up.

Anything else

No response

Version

3.4.2

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    bug
    Waiting for reply
    on Oct 13, 2026
  2. SbloodyS commented on Oct 13, 2026

    @SbloodyS
    Member

    Based on the 3.4.3 source, this report does not yet establish a separate crash/failover bug. Although persisting the task failure and advancing the in-memory graph are separate operations, recovery includes an event replay path: WorkflowFailoverCommandHandler rebuilds the graph using existing task instances, and TaskFailureStateAction.onStartEvent() republishes TaskFailedLifecycleEvent for a task already in FAILURE. That event re-enters the failure-chain marking and topology transition logic. Additionally, workflowFinish() updates the workflow state and deletes its serial command within the same transaction.
    A FAILURE task belonging to a RUNNING_EXECUTION workflow is also insufficient evidence by itself: the task may be awaiting retry, or other branches may still be executing under the Continue failure strategy. The absence of an independent serial-command reconciliation mechanism is a potential resilience improvement, but it does not demonstrate that the existing failover recovery path fails.
    To confirm this as a bug, please provide:

    • The exact affected version/build, preferably with reproduction on 3.4.3.
    • A minimal workflow export showing the DAG, failure strategy, task retry settings, and serial execution mode.
    • The precise crash injection point and the Master topology, including how restart/failover was performed.
    • Master logs covering the failure, failover command processing, recovered workflow startup, and subsequent task/workflow lifecycle events.
    • Timestamped task, workflow, and serial-command records before the crash and after recovery, showing that the workflow remains stuck after retries and other branches have finished.
    • Evidence that a later serial instance remains blocked, including its command/instance state.
      The key missing evidence is where the recovered execution stops progressing despite the failure-event replay path. That would help distinguish a recovery defect from the previously reported DAG issue or an expected intermediate state.
  3. sql-wj commented on Oct 13, 2026

    @sql-wj
    Author

    Describe the bug

    After #18406 (fixed by #18415 in 3.4.3), an architectural gap remains: the "persist task failure to DB" step and the "advance the workflow" step are two non-atomic operations. If the master crashes / restarts / fails over between them, the DB is left with task = FAILURE while workflow = RUNNING. The serial lock (t_ds_serial_command) is not released, so subsequent serial schedules of the same workflow can never trigger.

    #18406 only fixes one specific DAG shape (Continue failure strategy + a blocked intermediate predecessor). It does not provide any independent reconciliation for the serial lock.

    Which version of DolphinScheduler

    3.4.2 (observed); 3.4.3 partially fixed (#18406/#18415). The non-atomicity and the missing serial-lock reconciliation are NOT fixed in 3.4.3.

    To Reproduce

    1. Use a workflow whose task can fail.
    2. Make the master crash/restart/failover in the window between the task-failure write to DB and the workflow-advance steps (or otherwise get the workflow stuck while a task is FAILURE).
    3. Observe: t_ds_task_instance.state = FAILURE, t_ds_workflow_instance.state = RUNNING_EXECUTION, and a stale row remains in t_ds_serial_command.
    4. Subsequent serial schedules of the same workflow never trigger.

    Root cause

    In AbstractTaskStateAction.onFailedEvent():

    releaseTaskInstanceResourcesIfNeeded(taskExecution);
    persistentTaskInstanceFailedEventToDB(taskExecution, ...);   // (1) persisted to DB
    ...
    graph.markTaskExecutionChainFailure(taskExecution);          // (2) in-memory only
    publishWorkflowInstanceTopologyLogicalTransitionEvent(...);  // (3) in-memory only

    persistentTaskInstanceFailedEventToDB is a bare taskInstanceDao.updateById(...) with no @Transactional. Steps (2) and (3) live only in master memory. If the master dies after (1) but before (2)/(3) complete, steps (2)/(3) vanish with the memory, leaving task = FAILURE, workflow = RUNNING in the DB.

    On failover, the graph is rebuilt from the DB, but the failed task is not reliably re-marked into a failure chain and the workflow terminal event is not triggered — emitWorkflowFinishedEventIfApplicable returns early when !isWorkflowFinishable. The workflow stays RUNNING.

    Additionally, WorkflowSerialCoordinator.doStart() (lines 93–109) only handles SERIAL_WAIT / DISCARD / PRIORITY. There is no logic to scan terminal/zombie workflows and recycle their stale t_ds_serial_command rows. Serial-lock cleanup depends 100% on workflowFinish being reached.

    Proposed improvement

    Add a reconciliation task to WorkflowSerialCoordinator that scans already-terminal / zombie workflows and recycles their residual t_ds_serial_command rows. This is complementary to the #18406 fix (which only covers the Continue + blocked-predecessor shape).

  4. SbloodyS commented on Oct 15, 2026

    @SbloodyS
    Member

    Based on the 3.4.3 source, this report does not yet establish a separate crash/failover bug.

    [Source evidence] Although persisting task failure and advancing the in-memory graph are separate operations, recovery includes event replay. WorkflowFailoverCommandHandler rebuilds the execution graph using existing task instances, and TaskFailureStateAction.onStartEvent() republishes TaskFailedLifecycleEvent for a task already in FAILURE. This re-enters the retry, failure-chain marking, and topology-transition logic. Additionally, workflowFinish() updates the workflow state and deletes its serial command within the same transaction.

    [Assessment] A FAILURE task within a RUNNING_EXECUTION workflow is insufficient evidence of a stuck workflow: the task may be awaiting retry, or other branches may still be running under the Continue failure strategy. Independent serial-command reconciliation could be a resilience improvement, but its absence alone does not demonstrate that recovery fails.

    To confirm the bug, please provide a minimal reproduction on 3.4.3, including the DAG, failure strategy, retry settings, serial execution mode, exact crash injection point, and Master logs covering failover and recovered execution. Timestamped database records should show that the workflow remains stuck after retries and other branches have finished, with a subsequent serial instance still blocked.

    The key missing evidence is where recovery stops progressing despite the failure-event replay path.

  5. ruanwenjun commented on Oct 16, 2026

    @ruanwenjun
    Member

    @sql-wj Are you saying there's a bug in the fault-tolerant process? Can you write a test method that can be reproduced?

  6. kittimzhe commented on Oct 16, 2026

    @kittimzhe
    Contributor

    Opening the consensus question @SbloodyS asked for before #18709 can come back.

    Where we agree (per your source evidence): crash recovery replays events — WorkflowFailoverCommandHandler rebuilds the graph from existing task instances, so a master dying between "persist task failure" and "advance the workflow" does not corrupt the workflow side. #18709 does not dispute that, and never needed to.

    The residue the PR targets is narrower: rows in t_ds_serial_command whose instance is terminal, missing, or has a null id. Normal cleanup is same-transaction with workflow finish, and the trigger path persists state before inserting the row in the same transaction — so a stale row is not produced by the crash-between-two-writes window. What remains is defense-in-depth for rows that are already stale when read (upgrades from older deployments, rows orphaned by operational restores, or paths neither of us has enumerated).

    The consensus question is about shape, not necessity of the fix. Three candidates:

    1. Read-time reconciliation (what [Fix-18698][Master] Reconcile stale serial commands whose workflow instance is already final #18709 implements): the serial coordinator's poll deletes rows whose instance is terminal/missing/null-id, and drops them from the in-memory list in the same pass. Cost: one extra query per poll cycle. Benefit: self-healing with no operator action.
    2. Acquire-time guard: check the instance state only when a serial group is about to hand a row to a handler. Cheaper, but a stale row still blocks nothing and lingers in the table.
    3. No runtime change: treat the table as operational residue, document it, and let a cleanup job or doctor command handle it.

    My preference is 1, with the null-id and missing-instance cases only (terminal-state deletion is the part that could disagree with a legitimate pause/stop race, and #18709's tests pin that distinction). But if maintainers see the table as strictly derived-and-rebuildable, 3 is defensible and #18709 stays closed.

    Which shape do we want? Once that's settled, #18709 (or its replacement) comes back matching it.

  7. github-actions commented on Nov 16, 2026

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity for 30 days. It will be closed in next 7 days if no further activity occurs.

  8. github-actions commented on Nov 24, 2026

    @github-actions

    This issue has been closed because it has not received response for too long time. You could reopen it if you encountered similar problems in the future.

  9. kittimzhe commented on Nov 26, 2026

    @kittimzhe
    Contributor

    Following up on the consensus question I posted on Oct 16 — the issue was auto-closed by the stale bot before anyone could weigh in, so summarizing where things stand.

    Since then, two related fixes landed:

    I re-checked current dev: WorkflowSerialCoordinator still performs no instance-state check when polling, so a row whose instance is terminal, missing, or has a null id would still be handed to a handler. That said, from reading current dev I no longer see a code path that marks the instance terminal outside the finish transaction, so the strongest residue path appears closed — what remains is operational (upgrades from older deployments, restores, manual DB edits).

    So the question narrows to: is this considered done (issue stays closed, matching shape 3 — no runtime change), or should #18709 come back narrowed (read-time reconciliation limited to missing/null-id rows, without terminal-state deletion)? Happy either way — just don't want the question lost to the stale bot.

    @SbloodyS @ruanwenjun

  10. ruanwenjun commented on Nov 26, 2026

    @ruanwenjun
    Member

    @kittimzhe I've reopened this issue, but I'm still not entirely sure what the current problem is. Are you saying that some incompatible data—whether caused by manual operations in the database or due to past upgrades—has never been cleared, resulting in data that is out of sync? If that's the case, we shouldn't consider addressing it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneed more information

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions