[chat] Fix 500 error — run_stream must be plain def, not async def #934

Closed
sleepy wants to merge 0 commits from fix/async-generator-500 into dev
Owner

Critical fix. The long-context agent that split chat_routes.py into a package made run_stream an async def, causing it to return a coroutine instead of an async generator. Every chat request 500s with:

TypeError: 'async for' requires an object with __aiter__ method, got coroutine

One-line fix: async def run_stream → def run_stream.

Critical fix. The long-context agent that split chat_routes.py into a package made `run_stream` an `async def`, causing it to return a coroutine instead of an async generator. Every chat request 500s with: ``` TypeError: 'async for' requires an object with __aiter__ method, got coroutine ``` One-line fix: `async def run_stream` → `def run_stream`.
The long-context agent that split chat_routes.py made run_stream an
async def, which means calling run_stream(...) returns a coroutine instead
of an async generator. The caller (stream.py) does:
  safe_stream = run_stream(...)
  agent_runs.start(session, safe_stream)
agent_runs.start() then does 'async for ev in agen' on the coroutine,
which raises TypeError: 'async for' requires an object with __aiter__.

The fix: change 'async def run_stream' to 'def run_stream' since the
function returns an async generator object, it is not itself one.
sleepy closed this pull request 2026-06-04 15:35:48 +02:00

Pull request closed

Sign in to join this conversation.
No description provided.