Stop responding to the interface /chat-messages/:task_id/stop does not work #11937

Closed
opened 2026-02-21 19:04:51 -05:00 by yindo · 4 comments
Owner

Originally created by @He1zi on GitHub (Mar 21, 2025).

Originally assigned to: @crazywoola on GitHub.

Self Checks

  • 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 (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.15.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

After we use /chat-message to initiate a conversation, response_mode is streaming, and then I use /chat-messages/:task_id/stop to stop the current conversation, but at this time the previously initiated conversation is still continuing to reply and has not stopped.

✔️ Expected Behavior

For streaming replies that are being replied to, after using /chat-message/:task_id/stop, the current replying session can be stopped, and I can send the next request through /chat-messages again

Actual Behavior

For a streaming reply that is being replied to, after using /chat-message/:task_id/stop, the current streaming reply is still replying and has not stopped.

Originally created by @He1zi on GitHub (Mar 21, 2025). Originally assigned to: @crazywoola on GitHub. ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.15.3 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce After we use /chat-message to initiate a conversation, response_mode is streaming, and then I use /chat-messages/:task_id/stop to stop the current conversation, but at this time the previously initiated conversation is still continuing to reply and has not stopped. ### ✔️ Expected Behavior For streaming replies that are being replied to, after using /chat-message/:task_id/stop, the current replying session can be stopped, and I can send the next request through /chat-messages again ### ❌ Actual Behavior For a streaming reply that is being replied to, after using /chat-message/:task_id/stop, the current streaming reply is still replying and has not stopped.
yindo added the 🐞 bug🤔 cant-reproduce labels 2026-02-21 19:04:51 -05:00
yindo closed this issue 2026-02-21 19:04:51 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 21, 2025):

Hello, @He1zi! I'm here to help you with bugs, questions, and becoming a contributor. Let's tackle this issue together while we wait for a human maintainer.

The issue you're experiencing with the /chat-messages/:task_id/stop endpoint not stopping the current streaming reply in Dify version 0.15.3 when self-hosted with Docker is due to the lack of proper stream management and termination logic in the current implementation. To resolve this, you need to implement a BaseStreamManager class to manage active streams, modify the AppCompletionController to handle immediate termination, and update the CompletionService for proper stream cleanup.

Here's a brief overview of the necessary changes:

  1. Add a BaseStreamManager class in api/core/model_runtime/model_providers/base.py to manage active streams and handle termination.

  2. Modify AppCompletionController in api/controllers/service_api/app/completion.py to handle stop requests and set stop flags.

  3. Update CompletionService in api/services/completion_service.py to register and clean up streams.

These changes will ensure immediate stream termination and proper resource cleanup. You can find more detailed instructions and code snippets in this issue.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Mar 21, 2025): <!-- Greeting --> Hello, @He1zi! I'm here to help you with bugs, questions, and becoming a contributor. Let's tackle this issue together while we wait for a human maintainer. <!-- Answer --> The issue you're experiencing with the `/chat-messages/:task_id/stop` endpoint not stopping the current streaming reply in Dify version 0.15.3 when self-hosted with Docker is due to the lack of proper stream management and termination logic in the current implementation. To resolve this, you need to implement a `BaseStreamManager` class to manage active streams, modify the `AppCompletionController` to handle immediate termination, and update the `CompletionService` for proper stream cleanup. Here's a brief overview of the necessary changes: 1. **Add a `BaseStreamManager` class** in `api/core/model_runtime/model_providers/base.py` to manage active streams and handle termination. 2. **Modify `AppCompletionController`** in `api/controllers/service_api/app/completion.py` to handle stop requests and set stop flags. 3. **Update `CompletionService`** in `api/services/completion_service.py` to register and clean up streams. These changes will ensure immediate stream termination and proper resource cleanup. You can find more detailed instructions and code snippets in [this issue](https://github.com/langgenius/dify/issues/13035). <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/077b222c-9055-4bc4-9f82-589e7781f941?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/077b222c-9055-4bc4-9f82-589e7781f941?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/077b222c-9055-4bc4-9f82-589e7781f941?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/077b222c-9055-4bc4-9f82-589e7781f941?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/077b222c-9055-4bc4-9f82-589e7781f941?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/077b222c-9055-4bc4-9f82-589e7781f941?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/077b222c-9055-4bc4-9f82-589e7781f941?feedback_type=other)</sup>
Author
Owner

@He1zi commented on GitHub (Mar 24, 2025):

I tried this interface again and it can stop the streaming response normally. If your test is also normal, can this issue be closed? Sorry, maybe I made a mistake when I tested it before.

@He1zi commented on GitHub (Mar 24, 2025): I tried this interface again and it can stop the streaming response normally. If your test is also normal, can this issue be closed? Sorry, maybe I made a mistake when I tested it before.
Author
Owner

@He1zi commented on GitHub (Mar 25, 2025):

@crazywoola can i close the issue?

@He1zi commented on GitHub (Mar 25, 2025): @crazywoola can i close the issue?
Author
Owner

@crazywoola commented on GitHub (Mar 25, 2025):

Sure

@crazywoola commented on GitHub (Mar 25, 2025): Sure
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#11937