dify - 💡(How to fix) Fix Persist partially generated messages when /chat-messages/:task_id/stop is called

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

As a result, when the user refreshes the page or fetches the history via GET /messages, the partially generated message is completely lost. This creates a frustrating user experience. Users often stop the generation not because the answer is wrong, but because they have already seen the information they need and want to save time/tokens. Losing this valuable partial response feels like a bug to the end user.

Fix Action

Fix / Workaround

  1. Describe alternatives you've considered Currently, the only workaround is entirely on the frontend: intercepting the stop action, keeping the rendered bubble in the UI, and trying to stitch it together with local storage cache when the user re-enters the conversation. However, this is hacky, prone to state inconsistencies, and doesn't solve the core issue that the backend history is missing data.
RAW_BUFFERClick to expand / collapse

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • 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.
  • Please do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

  1. Is your feature request related to a problem? Please describe. Currently, when using the streaming mode for chat applications, if a user clicks "Stop generating" and the frontend calls POST /chat-messages/:task_id/stop, the backend seems to kill the task entirely without saving the already generated SSE chunks to the database.

As a result, when the user refreshes the page or fetches the history via GET /messages, the partially generated message is completely lost. This creates a frustrating user experience. Users often stop the generation not because the answer is wrong, but because they have already seen the information they need and want to save time/tokens. Losing this valuable partial response feels like a bug to the end user.

  1. Describe the solution you'd like When the stop API is triggered, instead of strictly aborting and discarding the temporary state, the backend should perform a "graceful stop". It should take the buffered answer content that has already been streamed to the client, commit it to the database for that message_id, and perhaps mark its status or finish_reason as stopped (similar to how OpenAI or Gemini handles aborted streams).

  2. Describe alternatives you've considered Currently, the only workaround is entirely on the frontend: intercepting the stop action, keeping the rendered bubble in the UI, and trying to stitch it together with local storage cache when the user re-enters the conversation. However, this is hacky, prone to state inconsistencies, and doesn't solve the core issue that the backend history is missing data.

  3. Additional context Standard AI products (like Gemini, ChatGPT) all persist the text generated prior to the stop action. Supporting this in Dify would greatly align the developer and end-user experience with industry standards.

2. Additional context or comments

No response

3. Can you help us with this feature?

  • I am interested in contributing to this feature.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING