fix(stream): preserve Chatflow terminal events and completion - #165
Draft
SamizuHM wants to merge 1 commit into
Draft
fix(stream): preserve Chatflow terminal events and completion#165SamizuHM wants to merge 1 commit into
SamizuHM wants to merge 1 commit into
Conversation
SamizuHM
force-pushed
the
fix/chatflow-stream-completion
branch
from
July 30, 2026 18:46
46a6ff8 to
9c76fa8
Compare
SamizuHM
force-pushed
the
fix/chatflow-stream-completion
branch
from
July 30, 2026 20:07
86fc23c to
4f3beb0
Compare
SamizuHM
marked this pull request as ready for review
July 31, 2026 05:23
Copilot stopped reviewing on behalf of
SamizuHM due to an error
July 31, 2026 05:23
Copilot stopped reviewing on behalf of
SamizuHM due to an error
July 31, 2026 05:24
SamizuHM
marked this pull request as draft
July 31, 2026 05:37
SamizuHM
force-pushed
the
fix/chatflow-stream-completion
branch
from
July 31, 2026 08:45
4f3beb0 to
00d825d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Chatflow has two application-level terminal events: message_end and workflow_finished. The Dify streaming guide documents message_end followed by workflow_finished, but deployed Dify versions can emit the reverse order.
Before this PR, the Chatflow path stopped as soon as it saw workflow_finished. That drops a later message_end. The first revision of this PR instead stopped at message_end, which would drop workflow_finished in the documented order. Treating either event as an unconditional terminal event is therefore incorrect.
Real-stream observation
A manual probe using this PR JAR against a real Chatflow received 343 Dify events in this order:
workflow_started -> node_started/node_finished -> node_started/node_finished -> node_started/node_finished -> node_started -> message x330 -> node_finished -> node_started/node_finished -> workflow_finished -> message_end
The SDK then invoked onStreamComplete. In this run, workflow_finished was event 342 and message_end was event 343. No Dify error event occurred. The temporary conversation was deleted after the probe.
This is intentionally application-agnostic evidence: no endpoint, credential, answer text, or business-specific behavior is included in this PR.
Solution
Completion contract
onStreamComplete only means that the SDK has stopped reading the non-error SSE response. It is not an assertion that a Dify workflow or application-level business operation succeeded.
Tests
Automated tests use in-memory SSE responses and cover:
Command:
Result: 6 tests passed.
Scope and non-goals
This PR fixes SDK-level SSE lifecycle handling only. It does not add application business logic, backend persistence, timeout-based ordering assumptions, or a dependency on a particular Dify deployment. EOF remains a fallback rather than the sole application-level completion signal.
Reference: https://docs.dify.ai/en/api-reference/guides/streaming