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

未关闭 适合新手
#656 0 条评论 0 个 reaction 已指派 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 分钟
30 天内合并 PR
33

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

The-OpenROAD-Project/ORAssistant 的其他 Issue

查看 The-OpenROAD-Project/ORAssistant 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。