LLM text chunks are streamed as message_file when assistant message has files
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Start with api/core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py and trace QueueLLMChunkEvent handling into message_cycle_manager.py. Compare that path with QueueMessageFileEvent handling and review the unit test added in related PR #31414. Done means text chunks consistently produce message events while file metadata remains message_file events.
Written by the indexing model from the issue text.
Description
Self Checks
- I have read the Contributing Guide and Language Policy.
- 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, otherwise it will be closed.
- 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- Please do not modify this template :) and fill in all the required fields.
Dify version
main branch at b96ea94505e3abe00daba69faa8bba9bcf9deb0a.
Cloud or Self Hosted
Self Hosted (Source) / upstream main code path.
Steps to reproduce
- Use a chat/completion flow that streams an assistant response and also produces an assistant-side message file for the same message. For example, a workflow/tool path that emits
QueueMessageFileEventbefore or during LLM token streaming. - The file event is handled by
MessageCycleManager.message_file_to_stream_response(), which caches the message id in_message_has_fileand correctly emits amessage_fileevent for the file metadata. - When a later
QueueLLMChunkEventis processed inEasyUIBasedGenerateTaskPipeline._process_stream_response(), the code callsMessageCycleManager.get_message_event_type(message_id=...)and reuses that event type for LLM text chunks. - Since the same message already has an assistant file,
get_message_event_type()returnsStreamEvent.MESSAGE_FILE. - The LLM text chunk is therefore emitted through
message_to_stream_response(..., event_type=StreamEvent.MESSAGE_FILE)instead ofStreamEvent.MESSAGE.
Current code evidence on main:
api/core/app/task_pipeline/easy_ui_based_generate_task_pipeline.pystill precomputes the event type forQueueLLMChunkEventby callingget_message_event_type(message_id=self._message_id)and passes it tomessage_to_stream_response().api/core/app/task_pipeline/message_cycle_manager.pyreturnsStreamEvent.MESSAGE_FILEfromget_message_event_type()when the message id is present in_message_has_fileor when an assistantMessageFileexists for that message.
Related previously closed PR with a small fix and unit test: https://github.com/langgenius/dify/pull/31414
✔️ Expected Behavior
QueueLLMChunkEvent text chunks should always be streamed as event: message, regardless of whether the same assistant message also has files.
File metadata should continue to be streamed separately as event: message_file via QueueMessageFileEvent.
❌ Actual Behavior
When the assistant message has a file, LLM text chunks can be streamed as event: message_file. The web client may treat those chunks as file events instead of normal message text, so streamed answer text can be dropped or not rendered correctly.
- Dominant language
- TypeScript
- Stars
- 157k
- Forks
- 24.7k
- Avg merge
- 22h 32m
- Merged PRs (30d)
- 611
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from langgenius/dify
-
Annotation Reply: a stored score threshold of 0.0 is silently replaced with 1, disabling the feature Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
langgenius/dify#42639 · 1 comment · 1 reaction ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
langgenius/dify#42468 · 1 comment · 1 reaction ·
-
🐞 bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
langgenius/dify#42446 · 1 reaction ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
langgenius/dify#42355 · 1 comment · 1 reaction ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
langgenius/dify#42350 · 1 comment · 1 reaction ·
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100