A JSON chat answer blocks the backend event loop for the whole RAG run

オープン 初心者向け
#656 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@NopeCharon がすでに取り組んでいます。

2026年12月5日 から。

  • #658 @NopeCharon による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
85/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
fastapi, python

調査の方向性

backend/から作業を始め、POST /conversations/agent-retrieverとPOST /helpers/suggestedQuestionsのハンドラーを読みます。issueでは、両方のブロッキング呼び出しと、run_in_threadpoolを使う修正案が説明されています。issueにあるモックグラフとhttpx.AsyncClientを使った再現手順で、JSON回答の生成中も/healthcheckが応答することを確認します。完了条件は、両方のハンドラーがイベントループの応答性を保ち、この再現手順を回帰テストでカバーすることです。

索引モデルが issue の本文から書いたものです。

説明

POST /conversations/agent-retriever is an async def endpoint. Without "stream": true, it runs the graph synchronously:

output = list(graph.graph.stream(inputs, stream_mode="updates"))

That call holds the event loop for the whole run: retrieval, reranking, and the LLM calls. Until the run ends, the backend answers no other request. The Docker image runs one uvicorn process, so meanwhile:

  • /healthcheck and /conversations/ready wait. The compose healthcheck calls /healthcheck with a 10 s timeout.
  • Other users' questions, the Next.js conversation list, and suggested questions wait, so concurrent questions are answered one at a time.

POST /helpers/suggestedQuestions has the same problem on a smaller scale: it calls the synchronous OpenAI client inside async def, and the Next.js app calls it after every answer.

The streaming path is not affected: it uses astream_events, which runs the sync graph nodes in worker threads.

Reproduce

From backend/, with the test setup in CONTRIBUTING.md: a mocked graph whose run takes 2 s (time.sleep(2) in stream), the conversations and healthcheck routers, and an httpx.AsyncClient over ASGITransport. Start a JSON answer, then sleep 0.2 s and call /healthcheck:

sleep(0.2) returned after 2.15s
healthcheck 200 answered 2.16s after the chat request started
Proposed fix

Run both blocking calls in a worker thread with run_in_threadpool, as FastAPI does for def endpoints. The graph then runs off the event loop in the JSON path, as it already does in the streaming path.

主要言語
Python
スター
51
フォーク
27
平均マージ
11時間 59分
マージ済み PR(30日)
33

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

The-OpenROAD-Project/ORAssistant のほかの issue

The-OpenROAD-Project/ORAssistant の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。