Workflow results in FAIL status #4142

Closed
opened 2026-02-21 18:04:55 -05:00 by yindo · 2 comments
Owner

Originally created by @rerorero on GitHub (Jun 17, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.11

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Run any workflows that can be successful

CleanShot 2024-06-17 at 23 01 23

✔️ Expected Behavior

Result in success

Actual Behavior

Result in FAIL status

Originally created by @rerorero on GitHub (Jun 17, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.11 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Run any workflows that can be successful ![CleanShot 2024-06-17 at 23 01 23](https://github.com/langgenius/dify/assets/8503062/03e2a5da-b52f-4993-a6cd-e2d361f9bb90) ### ✔️ Expected Behavior Result in success ### ❌ Actual Behavior Result in FAIL status
yindo added the 🌊 feat:workflow label 2026-02-21 18:04:55 -05:00
yindo closed this issue 2026-02-21 18:04:55 -05:00
Author
Owner

@rerorero commented on GitHub (Jun 17, 2024):

Looks like https://github.com/langgenius/dify/pull/5299 has introduced the issue, let me fix it

@rerorero commented on GitHub (Jun 17, 2024): Looks like https://github.com/langgenius/dify/pull/5299 has introduced the issue, let me fix it
Author
Owner

@dosubot[bot] commented on GitHub (Jun 17, 2024):

Hey @rerorero, I'm here to help you out with any bugs, questions, or becoming a contributor 🤖

To resolve the issue where running any workflows results in a FAIL status in Dify version 0.6.11, which you suspect was introduced by changes in pull request #5299, you should check the _handle_workflow_finished method in the WorkflowCycleManage class. Specifically, ensure that the QueueWorkflowFailedEvent is being handled correctly and that the workflow run status is being updated appropriately.

Here is the relevant part of the code that handles the workflow finishing:

def _handle_workflow_finished(self, event: QueueStopEvent | QueueWorkflowSucceededEvent | QueueWorkflowFailedEvent) \
        -> Optional[WorkflowRun]:
    workflow_run = db.session.query(WorkflowRun).filter(
        WorkflowRun.id == self._task_state.workflow_run_id).first()
    if not workflow_run:
        return None

    if isinstance(event, QueueStopEvent):
        workflow_run = self._workflow_run_failed(
            workflow_run=workflow_run,
            start_at=self._task_state.start_at,
            total_tokens=self._task_state.total_tokens,
            total_steps=self._task_state.total_steps,
            status=WorkflowRunStatus.STOPPED,
            error='Workflow stopped.'
        )

        latest_node_execution_info = self._task_state.latest_node_execution_info
        if (latest_node_execution_info and 
            workflow_node_execution := db.session.query(WorkflowNodeExecution).filter(
                WorkflowNodeExecution.id == latest_node_execution_info.workflow_node_execution_id).first()) and \
                workflow_node_execution.status == WorkflowNodeExecutionStatus.RUNNING.value:
            self._workflow_node_execution_failed(
                workflow_node_execution=workflow_node_execution,
                start_at=latest_node_execution_info.start_at,
                error='Workflow stopped.'
            )
    elif isinstance(event, QueueWorkflowFailedEvent):
        workflow_run = self._workflow_run_failed(
            workflow_run=workflow_run,
            start_at=self._task_state.start_at,
            total_tokens=self._task_state.total_tokens,
            total_steps=self._task_state.total_steps,
            status=WorkflowRunStatus.FAILED,
            error=event.error
        )
    else:
        outputs = (self._task_state.latest_node_execution_info and 
                   (workflow_node_execution := db.session.query(WorkflowNodeExecution).filter(
                       WorkflowNodeExecution.id == self._task_state.latest_node_execution_info.workflow_node_execution_id).first()) and 
                   workflow_node_execution.outputs) or None

        workflow_run = self._workflow_run_success(
            workflow_run=workflow_run,
            start_at=self._task_state.start_at,
            total_tokens=self._task_state.total_tokens,
            total_steps=self._task_state.total_steps,
            outputs=outputs
        )

    self._task_state.workflow_run_id = workflow_run.id

    db.session.close()

    return workflow_run

Ensure that the QueueWorkflowFailedEvent is correctly updating the workflow run status to FAILED and capturing the error message. Additionally, verify that the node.run method in the WorkflowEngineManager class is handling exceptions properly and that the NodeRunResult is being set to FAILED status when an error occurs. Here is the relevant part of the code:

try:
    node_run_result = node.run(
        variable_pool=workflow_run_state.variable_pool
    )
except GenerateTaskStoppedException as e:
    node_run_result = NodeRunResult(
        status=WorkflowNodeExecutionStatus.FAILED,
        error='Workflow stopped.'
    )
except Exception as e:
    logger.exception(f"Node {node.node_data.title} run failed: {str(e)}")
    node_run_result = NodeRunResult(
        status=WorkflowNodeExecutionStatus.FAILED,
        error=str(e)
    )

if node_run_result.status == WorkflowNodeExecutionStatus.FAILED:
    if callbacks:
        for callback in callbacks:
            callback.on_workflow_node_execute_failed(
                node_id=node.node_id,
                node_type=node.node_type,
                node_data=node.node_data,
                error=node_run_result.error,
                inputs=node_run_result.inputs,
                outputs=node_run_result.outputs,
                process_data=node_run_result.process_data,
            )
    raise ValueError(f"Node {node.node_data.title} run failed: {node_run_result.error}")

By ensuring that exceptions are properly caught and the workflow status is updated correctly, you can resolve the issue of workflows resulting in a FAIL status [1][2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jun 17, 2024): <!-- Greeting --> Hey @rerorero, I'm here to help you out with any bugs, questions, or becoming a contributor 🤖 <!-- Answer --> To resolve the issue where running any workflows results in a FAIL status in Dify version 0.6.11, which you suspect was introduced by changes in pull request #5299, you should check the `_handle_workflow_finished` method in the `WorkflowCycleManage` class. Specifically, ensure that the `QueueWorkflowFailedEvent` is being handled correctly and that the workflow run status is being updated appropriately. Here is the relevant part of the code that handles the workflow finishing: ```python def _handle_workflow_finished(self, event: QueueStopEvent | QueueWorkflowSucceededEvent | QueueWorkflowFailedEvent) \ -> Optional[WorkflowRun]: workflow_run = db.session.query(WorkflowRun).filter( WorkflowRun.id == self._task_state.workflow_run_id).first() if not workflow_run: return None if isinstance(event, QueueStopEvent): workflow_run = self._workflow_run_failed( workflow_run=workflow_run, start_at=self._task_state.start_at, total_tokens=self._task_state.total_tokens, total_steps=self._task_state.total_steps, status=WorkflowRunStatus.STOPPED, error='Workflow stopped.' ) latest_node_execution_info = self._task_state.latest_node_execution_info if (latest_node_execution_info and workflow_node_execution := db.session.query(WorkflowNodeExecution).filter( WorkflowNodeExecution.id == latest_node_execution_info.workflow_node_execution_id).first()) and \ workflow_node_execution.status == WorkflowNodeExecutionStatus.RUNNING.value: self._workflow_node_execution_failed( workflow_node_execution=workflow_node_execution, start_at=latest_node_execution_info.start_at, error='Workflow stopped.' ) elif isinstance(event, QueueWorkflowFailedEvent): workflow_run = self._workflow_run_failed( workflow_run=workflow_run, start_at=self._task_state.start_at, total_tokens=self._task_state.total_tokens, total_steps=self._task_state.total_steps, status=WorkflowRunStatus.FAILED, error=event.error ) else: outputs = (self._task_state.latest_node_execution_info and (workflow_node_execution := db.session.query(WorkflowNodeExecution).filter( WorkflowNodeExecution.id == self._task_state.latest_node_execution_info.workflow_node_execution_id).first()) and workflow_node_execution.outputs) or None workflow_run = self._workflow_run_success( workflow_run=workflow_run, start_at=self._task_state.start_at, total_tokens=self._task_state.total_tokens, total_steps=self._task_state.total_steps, outputs=outputs ) self._task_state.workflow_run_id = workflow_run.id db.session.close() return workflow_run ``` Ensure that the `QueueWorkflowFailedEvent` is correctly updating the workflow run status to `FAILED` and capturing the error message. Additionally, verify that the `node.run` method in the `WorkflowEngineManager` class is handling exceptions properly and that the `NodeRunResult` is being set to `FAILED` status when an error occurs. Here is the relevant part of the code: ```python try: node_run_result = node.run( variable_pool=workflow_run_state.variable_pool ) except GenerateTaskStoppedException as e: node_run_result = NodeRunResult( status=WorkflowNodeExecutionStatus.FAILED, error='Workflow stopped.' ) except Exception as e: logger.exception(f"Node {node.node_data.title} run failed: {str(e)}") node_run_result = NodeRunResult( status=WorkflowNodeExecutionStatus.FAILED, error=str(e) ) if node_run_result.status == WorkflowNodeExecutionStatus.FAILED: if callbacks: for callback in callbacks: callback.on_workflow_node_execute_failed( node_id=node.node_id, node_type=node.node_type, node_data=node.node_data, error=node_run_result.error, inputs=node_run_result.inputs, outputs=node_run_result.outputs, process_data=node_run_result.process_data, ) raise ValueError(f"Node {node.node_data.title} run failed: {node_run_result.error}") ``` By ensuring that exceptions are properly caught and the workflow status is updated correctly, you can resolve the issue of workflows resulting in a FAIL status <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/app/task_pipeline/workflow_cycle_manage.py)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/workflow/workflow_engine_manager.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4142