Skip to content

fix: publish error event on invalid conversation/message in chatflow SSE#37244

Open
1795771535y-cell wants to merge 3 commits into
langgenius:mainfrom
1795771535y-cell:fix/chatflow-hang-invalid-conversation-37197
Open

fix: publish error event on invalid conversation/message in chatflow SSE#37244
1795771535y-cell wants to merge 3 commits into
langgenius:mainfrom
1795771535y-cell:fix/chatflow-hang-invalid-conversation-37197

Conversation

@1795771535y-cell

Copy link
Copy Markdown
Contributor

Summary

Fixes #37197

When sending a chat-messages request with a non-existing conversation_id to a chatflow (advanced-chat) app, the SSE stream opens but only ping/keepalive events are received - the request never completes and no error is returned.

Root Cause

In AdvancedChatAppGenerator._generate_worker, the conversation and message lookup (lines 619-620) was placed BEFORE the try/except block that catches errors and publishes them to the SSE queue:

`python
conversation = self._get_conversation(conversation_id) # raises ConversationNotExistsError
message = self._get_message(message_id)

... later ...

try:
runner.run()
except ...:
queue_manager.publish_error(...)
`

When ConversationNotExistsError or MessageNotExistsError is raised, the worker thread crashes silently without publishing an error event. The main SSE stream loop continues waiting on the queue manager, sending only periodic pings.

Fix

Wrap the conversation/message fetch in a try/except that publishes the error via queue_manager.publish_error(e, PublishFrom.APPLICATION_MANAGER). This is consistent with how chat/app_generator and agent_chat/app_generator already handle this - both have the _get_conversation call inside their try/except blocks.

python try: conversation = self._get_conversation(conversation_id) message = self._get_message(message_id) except (ConversationNotExistsError, MessageNotExistsError) as e: queue_manager.publish_error(e, PublishFrom.APPLICATION_MANAGER) return

Behavior After Fix

Invalid conversation_id -> SSE error event: {"event": "error", "message": "Conversation not exists", "status": 500}

…tening elements

When _truncate_array breaks due to size limit exceeding target_size, the
truncated flag was not set to True, causing dropped tail elements to go
unreported. Additionally, the flag was overwritten (truncated =
part_result.truncated) instead of accumulated, so a later fitting element
could reset a previously-set flag to False.

Fix by setting truncated = True before the size-limit break, and using
logical OR to accumulate (truncated = truncated or part_result.truncated).

Fixes langgenius#37192

Signed-off-by: C4P-T <cap@teamos.dev>
…view

The /files/{id}/file-preview endpoint unconditionally set Content-Type to
application/octet-stream after the Response constructor had already used
the correct upload_file.mime_type, causing all inline previews (images,
PDFs, etc.) to be forced as downloads instead of rendering in-browser.

Move the octet-stream override inside the as_attachment branch so it
only applies when the caller explicitly requests download-as-attachment.
For normal previews, the original mime_type from the Response constructor
is preserved.

Fixes langgenius#37198

Signed-off-by: C4P-T <cap@teamos.dev>
The _generate_worker in AdvancedChatAppGenerator called _get_conversation
and _get_message BEFORE the try/except block that handles errors and
publishes them to the SSE queue. When the conversation_id or message_id
is invalid (e.g., non-existing), ConversationNotExistsError or
MessageNotExistsError crashes the worker thread silently, leaving the
SSE stream hanging with only ping events.

Wrap the conversation/message fetch in a try/except that publishes the
error via queue_manager.publish_error, consistent with how chat/app_generator
and agent_chat/app_generator already handle these errors.

Fixes langgenius#37197

Signed-off-by: C4P-T <cap@teamos.dev>
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jun 9, 2026
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 47.25% 47.25% 0.00%
Strict coverage 46.75% 46.75% 0.00%
Typed symbols 26,553 26,553 0
Untyped symbols 29,962 29,962 0
Modules 2853 2853 0

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

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chatflow hangs on non-existing conversation id

1 participant