Skip to content

fix: handle Dify workflow stream errors - #10545

Merged
Soulter merged 2 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/dify-workflow-errors
Oct 14, 2026
Merged

Soulter merged 2 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/dify-workflow-errors

Conversation

@wcqqq1214

@wcqqq1214 wcqqq1214 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Dify workflow errors could be reported as empty success or leave partial replies without an error notice.

Modifications / 改动点

  • Surface stream errors and reject streams that end without a valid workflow result.

  • Validate completion status while preserving partial-succeeded outputs and existing output checks.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

  • 24 isolated event checks passed across streaming and non-streaming modes, including errors, early EOF, success, partial success, and empty output. External dependencies were mocked; no test files added.
  • ruff format --check ., ruff check ., and git diff --check passed.

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。

  • 📚 I checked the affected WebUI instructions and screenshots in docs/zh and docs/en against the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog.
    / 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新 docs/zh 和 docs/en 的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txt 和 pyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Ensure Dify workflow streaming reports execution failures and requires a valid completed workflow result.

Bug Fixes:

  • Surface Dify workflow stream errors and reject incomplete or unsuccessful workflow executions instead of returning empty or partial replies without an error.

Enhancements:

  • Preserve valid partial-success results while continuing to validate workflow outputs.

@wcqqq1214
wcqqq1214 marked this pull request as ready for review October 13, 2026 05:30

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/core/agent/runners/dify/dify_agent_runner.py" line_range="243" />
<code_context>
+                                f"Dify workflow error (status: {chunk.get('status')}, "
+                                f"code: {chunk.get('code')}): "
+                                f"{chunk.get('message') or 'No error details provided.'}"
+                            )
                         case "workflow_started":
                             logger.info(
</code_context>
<issue_to_address>
**Dify diagnostics reach chat users**

When a Dify workflow error contains sensitive diagnostic details and an ordinary chat user triggers that error, `step()` embeds the exception text in the `err` response, and `run_third_party_agent` forwards that chain to the requester, exposing internal workflow diagnostics.

Send a generic error message to the requester and retain detailed diagnostics only in access-controlled logs.

Also at `astrbot/core/agent/runners/dify/dify_agent_runner.py:274`.
</issue_to_address>

### Comment 2
<location path="astrbot/core/agent/runners/dify/dify_agent_runner.py" line_range="268-271" />
<code_context>
-                                    f"Dify 工作流出现错误:{chunk['data']['error']}"
-                                )
+                            status = chunk["data"].get("status")
+                            if chunk["data"].get("error") or status not in (
+                                "succeeded",
+                                "partial-succeeded",
+                            ):
                                 raise Exception(
-                                    f"Dify 工作流出现错误:{chunk['data']['error']}"
</code_context>
<issue_to_address>
**Partial results become errors**

When dify returns `partial-succeeded` with a non-empty `data.error`, the `workflow_finished` check raises before the output is read, so `step()` returns an error instead of the available partial result.

Honor the `partial-succeeded` status before treating `data.error` as fatal.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: astrbot/core/agent/runners/dify/dify_agent_runner.py:243, astrbot/core/agent/runners/dify/dify_agent_runner.py:271


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread astrbot/core/agent/runners/dify/dify_agent_runner.py
Comment on lines +268 to +271
if chunk["data"].get("error") or status not in (
"succeeded",
"partial-succeeded",
):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Partial results become errors

When dify returns partial-succeeded with a non-empty data.error, the workflow_finished check raises before the output is read, so step() returns an error instead of the available partial result.

Honor the partial-succeeded status before treating data.error as fatal.

Prompt for AI agents
In `astrbot/core/agent/runners/dify/dify_agent_runner.py` at lines 268-271:

**Partial results become errors**

When dify returns `partial-succeeded` with a non-empty `data.error`, the `workflow_finished` check raises before the output is read, so `step()` returns an error instead of the available partial result.

Honor the `partial-succeeded` status before treating `data.error` as fatal.

@wcqqq1214

Copy link
Copy Markdown
Contributor Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/core/agent/runners/dify/dify_agent_runner.py" line_range="271" />
<code_context>
                             logger.debug(f"Dify 工作流结果:{chunk}")
-                            if chunk["data"]["error"]:
+                            status = chunk["data"].get("status")
+                            if chunk["data"].get("error") or status not in (
+                                "succeeded",
+                                "partial-succeeded",
</code_context>
<issue_to_address>
**Partial workflow outputs are discarded**

When dify emits a `workflow_finished` event with status `partial-succeeded`, a nonempty `data.error`, and the configured output available, the `data.error` check rejects the event before the configured output is checked or parsed, so the runner returns an error instead of the partial result.

Accept `partial-succeeded` events despite `data.error` and parse their available configured output.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: astrbot/core/agent/runners/dify/dify_agent_runner.py:271


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

logger.debug(f"Dify 工作流结果:{chunk}")
if chunk["data"]["error"]:
status = chunk["data"].get("status")
if chunk["data"].get("error") or status not in (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Partial workflow outputs are discarded

When dify emits a workflow_finished event with status partial-succeeded, a nonempty data.error, and the configured output available, the data.error check rejects the event before the configured output is checked or parsed, so the runner returns an error instead of the partial result.

Accept partial-succeeded events despite data.error and parse their available configured output.

Prompt for AI agents
In `astrbot/core/agent/runners/dify/dify_agent_runner.py` at line 271:

**Partial workflow outputs are discarded**

When dify emits a `workflow_finished` event with status `partial-succeeded`, a nonempty `data.error`, and the configured output available, the `data.error` check rejects the event before the configured output is checked or parsed, so the runner returns an error instead of the partial result.

Accept `partial-succeeded` events despite `data.error` and parse their available configured output.

@Soulter
Soulter merged commit 626c6d3 into AstrBotDevs:master Oct 14, 2026
23 checks passed
@wcqqq1214
wcqqq1214 deleted the fix/dify-workflow-errors branch October 14, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants