[Question]: V0.22.1 version, error reported through API call [ERROR] Error in ASGI Framework
Self Checks
- [x] I have searched for existing issues search for existing issues, including closed ones.
- [x] I confirm that I am using English to submit this report (Language Policy).
- [x] Non-english title submitions will be closed directly ( 非英文标题的提交将会被直接关闭 ) (Language Policy).
- [x] Please do not modify this template :) and fill in all the required fields.
Describe your problem
V0.22.1 version, both API calls and website embedded calls will result in errors. v0.22.0 is fine, but the specific errors are as follows:
ragflow-gpu-1 | [2025-11-27 17:31:56 +0800] [17] [INFO] 127.0.0.1:52176 POST /v1/canvas/upload/1ba9355eb89311f09e8a0242ac170007 1.1 200 282 47389 ragflow-gpu-1 | [2025-11-27 17:32:01 +0800] [17] [ERROR] Error in ASGI Framework ragflow-gpu-1 | Traceback (most recent call last): ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/hypercorn/asyncio/task_group.py", line 27, in _handle ragflow-gpu-1 | await app(scope, receive, send, sync_spawn, call_soon) ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/hypercorn/app_wrappers.py", line 34, in call ragflow-gpu-1 | await self.app(scope, receive, send) ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/app.py", line 1735, in call ragflow-gpu-1 | await self.asgi_app(scope, receive, send) ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/app.py", line 1761, in asgi_app ragflow-gpu-1 | await asgi_handler(receive, send) ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/asgi.py", line 60, in call ragflow-gpu-1 | raise_task_exceptions(done) ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/utils.py", line 186, in raise_task_exceptions ragflow-gpu-1 | raise task.exception() ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/asgi.py", line 117, in handle_request ragflow-gpu-1 | await asyncio.wait_for(self._send_response(send, response), timeout=timeout) ragflow-gpu-1 | File "/usr/lib/python3.10/asyncio/tasks.py", line 445, in wait_for ragflow-gpu-1 | return fut.result() ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/asgi.py", line 146, in _send_response ragflow-gpu-1 | async for data in response_body: ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/utils.py", line 90, in _gen_wrapper ragflow-gpu-1 | yield await loop.run_in_executor(None, copy_context().run, _inner) ragflow-gpu-1 | File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run ragflow-gpu-1 | result = self.fn(*self.args, **self.kwargs) ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/utils.py", line 83, in _inner ragflow-gpu-1 | return next(iterable) ragflow-gpu-1 | File "/ragflow/api/apps/sdk/session.py", line 452, in generate ragflow-gpu-1 | for answer in agent_completion(tenant_id=tenant_id, agent_id=agent_id, **req): ragflow-gpu-1 | File "/ragflow/api/db/services/canvas_service.py", line 222, in completion ragflow-gpu-1 | for ans in canvas.run(query=query, files=files, user_id=user_id, inputs=inputs): ragflow-gpu-1 | TypeError: 'async_generator' object is not iterable ragflow-gpu-1 | 2025-11-27 17:32:01,286 ERROR 17 Error in ASGI Framework ragflow-gpu-1 | Traceback (most recent call last): ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/hypercorn/asyncio/task_group.py", line 27, in _handle ragflow-gpu-1 | await app(scope, receive, send, sync_spawn, call_soon) ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/hypercorn/app_wrappers.py", line 34, in call ragflow-gpu-1 | await self.app(scope, receive, send) ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/app.py", line 1735, in call ragflow-gpu-1 | await self.asgi_app(scope, receive, send) ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/app.py", line 1761, in asgi_app ragflow-gpu-1 | await asgi_handler(receive, send) ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/asgi.py", line 60, in call ragflow-gpu-1 | raise_task_exceptions(done) ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/utils.py", line 186, in raise_task_exceptions ragflow-gpu-1 | raise task.exception() ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/asgi.py", line 117, in handle_request ragflow-gpu-1 | await asyncio.wait_for(self._send_response(send, response), timeout=timeout) ragflow-gpu-1 | File "/usr/lib/python3.10/asyncio/tasks.py", line 445, in wait_for ragflow-gpu-1 | return fut.result() ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/asgi.py", line 146, in _send_response ragflow-gpu-1 | async for data in response_body: ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/utils.py", line 90, in _gen_wrapper ragflow-gpu-1 | yield await loop.run_in_executor(None, copy_context().run, _inner) ragflow-gpu-1 | File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run ragflow-gpu-1 | result = self.fn(*self.args, **self.kwargs) ragflow-gpu-1 | File "/ragflow/.venv/lib/python3.10/site-packages/quart/utils.py", line 83, in _inner ragflow-gpu-1 | return next(iterable) ragflow-gpu-1 | File "/ragflow/api/apps/sdk/session.py", line 452, in generate ragflow-gpu-1 | for answer in agent_completion(tenant_id=tenant_id, agent_id=agent_id, **req): ragflow-gpu-1 | File "/ragflow/api/db/services/canvas_service.py", line 222, in completion ragflow-gpu-1 | for ans in canvas.run(query=query, files=files, user_id=user_id, inputs=inputs): ragflow-gpu-1 | TypeError: 'async_generator' object is not iterable ragflow-gpu-1 | [2025-11-27 17:32:01 +0800] [17] [INFO] 127.0.0.1:51266 POST /api/v1/agents/1ba9355eb89311f09e8a0242ac170007/completions 1.1 - - 104955
The error happens because the canvas.run method is an async generator, so it must be iterated with async for, not a regular for loop. In v0.22.1, the service layer (canvas_service.py) uses async for correctly, but the API layer (like api/apps/sdk/session.py) still uses a regular for loop with agent_completion, which leads to the TypeError: 'async_generator' object is not iterable you’re seeing.
To fix this, update the API layer to use async for answer in agent_completion(...) instead of for answer in agent_completion(...). This change will align the iteration with the async generator contract and resolve the error. This requirement was not enforced in v0.22.0, which is why you didn’t see the error there.
For reference, see the implementation of canvas.run as an async generator and the correct usage in the service layer:
Canvas.run implementation
Correct async for usage in canvas_service.py
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
@yaoq827 How to reproduce you issue? or can you share the workflow file with us ?
When calling the agent through the API in v0.22.1, the following error message appears: {"code":100,"data":null,"message":"TypeError("'async generator' object is not iterable")"}, which was normal in the previous version.
@gaby-jiang Can you share the json file with us via [email protected]
test.json This agent can reproduce the issue. @Magicbook1108
@gaby-jiang You can either switch back to v0.22.0 or pull the latest code from the main branch. The async-related issues were introduced in v0.22.1 and have already been fixed in recent pull requests. The next stable release will include these fixes, and everything should work normally then.