You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.14.1
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
2024-12-20.154846.mp4
As shown on video.
Using Chatflow, start a conversation and click the stop button while the conversation is producing text.
The status of API /api/chat-messages is ERR_INCOMPLETE_CHUNKED_ENCODING.
This failed state causes the program to fail to stop properly.
✔️ Expected Behavior
Stop properly.
❌ Actual Behavior
Unable to stop correctly.
2024-12-20.155903.mp4
At the same time, the container "dify-api" has error logs.
[2024-12-20 08:01:07 +0000] [86] [ERROR] Error handling request
Traceback (most recent call last):
File "/app/api/.venv/lib/python3.12/site-packages/gunicorn/workers/base_async.py", line 114, in handle_request
for item in respiter:
^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/werkzeug/wsgi.py", line 256, in __next__
return self._next()
^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/werkzeug/wrappers/response.py", line 32, in _iter_encoded
for item in iterable:
^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/flask/helpers.py", line 125, in generator
yield from gen
File "/app/api/libs/helper.py", line 191, in generate
yield from response
File "/app/api/core/app/features/rate_limiting/rate_limit.py", line 112, in __next__
return next(self.generator)
^^^^^^^^^^^^^^^^^^^^
File "/app/api/core/app/apps/base_app_generate_response_converter.py", line 40, in _generate_simple_response
for chunk in cls.convert_stream_simple_response(response):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/core/app/apps/advanced_chat/generate_response_converter.py", line 98, in convert_stream_simple_response
for chunk in stream_response:
^^^^^^^^^^^^^^^
File "/app/api/core/app/apps/advanced_chat/generate_task_pipeline.py", line 191, in _to_stream_response
for stream_response in generator:
^^^^^^^^^
File "/app/api/core/app/apps/advanced_chat/generate_task_pipeline.py", line 222, in _wrapper_process_stream_response
for response in self._process_stream_response(tts_publisher=tts_publisher, trace_manager=trace_manager):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/core/app/apps/advanced_chat/generate_task_pipeline.py", line 452, in _process_stream_response
yield self._workflow_finish_to_stream_response(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/core/app/task_pipeline/workflow_cycle_manage.py", line 461, in _workflow_finish_to_stream_response
if workflow_run.created_by_role == CreatedByRole.ACCOUNT.value:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/attributes.py", line 566, in __get__
return self.impl.get(state, dict_) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/attributes.py", line 1086, in get
value = self._fire_loader_callables(state, key, passive)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/attributes.py", line 1116, in _fire_loader_callables
return state._load_expired(state, passive)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/state.py", line 803, in _load_expired
self.manager.expired_attribute_loader(self, toload, passive)
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/loading.py", line 1603, in load_scalar_attributes
raise orm_exc.DetachedInstanceError(
sqlalchemy.orm.exc.DetachedInstanceError: Instance <WorkflowRun at 0x7f0e23306bd0> is not bound to a Session; attribute refresh operation cannot proceed (Background on this error at: https://sqlalche.me/e/20/bhk3)
The text was updated successfully, but these errors were encountered:
The error you're encountering, ERR_INCOMPLETE_CHUNKED_ENCODING, during streaming responses in the Dify application seems to be related to a DetachedInstanceError in SQLAlchemy. This error occurs when an instance of a SQLAlchemy model is accessed without being bound to an active session, which prevents attribute refresh operations from proceeding.
In the context of your issue, the error log indicates that the workflow_run.created_by_role attribute is being accessed on a WorkflowRun instance that is not bound to a session. This typically happens if the session that loaded the instance has been closed or if the instance was detached from the session.
To address this issue, you can try the following:
Ensure Session Management: Make sure that the SQLAlchemy session is properly managed and that instances are not accessed outside the session's scope. This might involve ensuring that the session is open when accessing attributes or re-attaching the instance to an active session.
Review Streaming Logic: Check the logic in the streaming process, particularly in the _to_stream_response and _workflow_finish_to_stream_response functions, to ensure that instances are accessed within a valid session context.
Error Handling: Implement error handling to catch and manage DetachedInstanceError exceptions, possibly by re-attaching the instance to a session or by logging the error for further investigation.
These steps should help mitigate the issue and ensure that the application can handle stopping a conversation without encountering this error.
Self Checks
Dify version
0.14.1
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
2024-12-20.154846.mp4
As shown on video.
Using Chatflow, start a conversation and click the stop button while the conversation is producing text.
The status of API /api/chat-messages is ERR_INCOMPLETE_CHUNKED_ENCODING.
This failed state causes the program to fail to stop properly.
✔️ Expected Behavior
Stop properly.
❌ Actual Behavior
Unable to stop correctly.
2024-12-20.155903.mp4
At the same time, the container "dify-api" has error logs.
The text was updated successfully, but these errors were encountered: