Skip to content

fix: improve error handling for workflow execution (#37919) - #40885

Draft
wylswz wants to merge 1 commit into
langgenius:lts/1.13.xfrom
wylswz:fix/chatflow-input-moderation-sse-terminal
Draft

fix: improve error handling for workflow execution (#37919)#40885
wylswz wants to merge 1 commit into
langgenius:lts/1.13.xfrom
wylswz:fix/chatflow-input-moderation-sse-terminal

Conversation

@wylswz

@wylswz wylswz commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

(cherry picked from commit b33e8f0)

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods

@wylswz
wylswz requested a review from a team August 17, 2026 11:04
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 17, 2026
@wylswz
wylswz marked this pull request as draft August 17, 2026 11:04
@github-actions github-actions Bot added the web This relates to changes on the web. label Aug 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-08-17 11:06:04.617522831 +0000
+++ /tmp/pyrefly_pr.txt	2026-08-17 11:05:50.583506291 +0000
@@ -483,9 +483,9 @@
 ERROR Object of class `dict` has no attribute `encode`
 ERROR Object of class `dict` has no attribute `encode`
 ERROR Runtime checkable protocol `Generator` has an unsafe overlap with type `Generator[Mapping[str, Any] | str, Any] | Mapping[str, Any]` [unsafe-overlap]
-   --> tasks/app_generate/workflow_execute_task.py:435:37
+   --> tasks/app_generate/workflow_execute_task.py:636:33
 ERROR Runtime checkable protocol `Generator` has an unsafe overlap with type `Generator[Mapping[str, Any] | str] | Mapping[str, Any]` [unsafe-overlap]
-   --> tasks/app_generate/workflow_execute_task.py:489:37
+   --> tasks/app_generate/workflow_execute_task.py:698:33
 ERROR `Literal['error']` is not assignable to attribute `status` with type `Never` [bad-assignment]
    --> tasks/regenerate_summary_index_task.py:278:61
 ERROR `str` is not assignable to attribute `error` with type `Never` [bad-assignment]
@@ -7201,12 +7201,130 @@
     --> tests/unit_tests/tasks/test_mail_send_task.py:1299:67
 ERROR Argument `dict[str, bool]` is not assignable to parameter `substitutions` with type `Mapping[str, str]` in function `tasks.mail_inner_task._render_template_with_strategy` [bad-argument-type]
     --> tests/unit_tests/tasks/test_mail_send_task.py:1300:64
-ERROR Argument `Iterator[Any]` is not assignable to parameter `response_stream` with type `Generator[Mapping[str, Any] | str]` in function `tasks.app_generate.workflow_execute_task._publish_streaming_response` [bad-argument-type]
-  --> tests/unit_tests/tasks/test_workflow_execute_task.py:55:33
-ERROR Argument `UUID` is not assignable to parameter `workflow_run_id` with type `str` in function `tasks.app_generate.workflow_execute_task._publish_streaming_response` [bad-argument-type]
-  --> tests/unit_tests/tasks/test_workflow_execute_task.py:55:50
-ERROR Argument `Iterator[Any]` is not assignable to parameter `response_stream` with type `Generator[Mapping[str, Any] | str]` in function `tasks.app_generate.workflow_execute_task._publish_streaming_response` [bad-argument-type]
-  --> tests/unit_tests/tasks/test_workflow_execute_task.py:65:33
+ERROR Argument `object` is not assignable to parameter `event` with type `BaseModel | Mapping[str, Any] | str` in function `tasks.app_generate.workflow_execute_task._get_event_name` [bad-argument-type]
+  --> tests/unit_tests/tasks/test_workflow_execute_task.py:97:57
+ERROR Argument `object` is not assignable to parameter `event` with type `BaseModel | Mapping[str, Any] | str` in function `tasks.app_generate.workflow_execute_task._get_task_id` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:113:54
+ERROR Argument `Iterator[Any]` is not assignable to parameter `response_stream` with type `Generator[BaseModel | Mapping[str, Any] | str]` in function `tasks.app_generate.workflow_execute_task._publish_streaming_response` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:136:9
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:145:13
+ERROR Argument `Iterator[Any]` is not assignable to parameter `response_stream` with type `Generator[BaseModel | Mapping[str, Any] | str]` in function `tasks.app_generate.workflow_execute_task._publish_streaming_response` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:153:9
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:162:13
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:184:13
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:185:12
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:185:12
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:186:12
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:186:12
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:187:12
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:187:12
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:188:12
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:188:12
+ERROR Argument `Iterator[Any]` is not assignable to parameter `response_stream` with type `Generator[BaseModel | Mapping[str, Any] | str]` in function `tasks.app_generate.workflow_execute_task._publish_streaming_response` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:214:13
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:222:13
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:223:12
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:224:23
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:224:23
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:225:12
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:226:12
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:226:12
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:227:12
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:227:12
+ERROR Argument `Iterator[Any]` is not assignable to parameter `response_stream` with type `Generator[BaseModel | Mapping[str, Any] | str]` in function `tasks.app_generate.workflow_execute_task._publish_streaming_response` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:260:13
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:268:13
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:269:12
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:270:12
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:270:12
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:271:12
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:271:12
+ERROR Argument `Iterator[Any]` is not assignable to parameter `response_stream` with type `Generator[BaseModel | Mapping[str, Any] | str]` in function `tasks.app_generate.workflow_execute_task._publish_streaming_response` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:304:13
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:312:13
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:313:12
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:314:12
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:314:12
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:315:12
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:315:12
+ERROR Argument `Iterator[Any]` is not assignable to parameter `response_stream` with type `Generator[BaseModel | Mapping[str, Any] | str]` in function `tasks.app_generate.workflow_execute_task._publish_streaming_response` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:337:9
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:346:13
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:347:12
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:348:12
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:348:12
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:349:12
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:349:12
+ERROR Argument `Iterator[Any]` is not assignable to parameter `response_stream` with type `Generator[BaseModel | Mapping[str, Any] | str]` in function `tasks.app_generate.workflow_execute_task._publish_streaming_response` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:387:9
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:396:13
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:489:12
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:489:12
+ERROR Cannot index into `str` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:490:12
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:490:12
+ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `tasks.app_generate.workflow_execute_task._resume_advanced_chat` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:699:19
+ERROR Argument `SimpleNamespace` is not assignable to parameter `workflow` with type `Workflow` in function `tasks.app_generate.workflow_execute_task._resume_advanced_chat` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:700:18
+ERROR Argument `SimpleNamespace` is not assignable to parameter `conversation` with type `Conversation` in function `tasks.app_generate.workflow_execute_task._resume_advanced_chat` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:702:22
+ERROR Argument `SimpleNamespace` is not assignable to parameter `workflow_run` with type `WorkflowRun` in function `tasks.app_generate.workflow_execute_task._resume_advanced_chat` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:709:22
+ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `tasks.app_generate.workflow_execute_task._resume_workflow` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:752:19
+ERROR Argument `SimpleNamespace` is not assignable to parameter `workflow` with type `Workflow` in function `tasks.app_generate.workflow_execute_task._resume_workflow` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:753:18
+ERROR Argument `SimpleNamespace` is not assignable to parameter `workflow_run` with type `WorkflowRun` in function `tasks.app_generate.workflow_execute_task._resume_workflow` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:760:22
+ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `tasks.app_generate.workflow_execute_task._resume_workflow` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:807:19
+ERROR Argument `SimpleNamespace` is not assignable to parameter `workflow` with type `Workflow` in function `tasks.app_generate.workflow_execute_task._resume_workflow` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:808:18
+ERROR Argument `SimpleNamespace` is not assignable to parameter `workflow_run` with type `WorkflowRun` in function `tasks.app_generate.workflow_execute_task._resume_workflow` [bad-argument-type]
+   --> tests/unit_tests/tasks/test_workflow_execute_task.py:815:22
 ERROR Object of class `BlobChunkMessage` has no attribute `variable_name`
 ERROR Object of class `BlobChunkMessage` has no attribute `variable_name`
 ERROR Object of class `BlobChunkMessage` has no attribute `variable_value`

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 0.00% 0.00% 0.00%
Strict coverage 0.00% 0.00% 0.00%
Typed symbols 0 0 0
Untyped symbols 0 0 0
Modules 0 0 0

workflow_run_id: str,
workflow_run: WorkflowRun,
) -> None:
resumed_generate_entity = generate_entity.model_copy(update={"stream": True})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This line is introduced when resolving conflicts, introduced by #32826

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants