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

Aperta Adatta ai principianti
#656 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@NopeCharon ci sta già lavorando.

Dal 5/12/2026.

  • #658 di @NopeCharon — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
fastapi, python

Direzione di ricerca

Inizia da backend/ leggendo gli handler di POST /conversations/agent-retriever e POST /helpers/suggestedQuestions; l’issue descrive entrambe le chiamate bloccanti e la correzione proposta con run_in_threadpool. Usa la riproduzione descritta nell’issue con il grafo simulato e httpx.AsyncClient per verificare che /healthcheck risponda mentre viene generata una risposta JSON. Il lavoro è completato quando entrambi gli handler mantengono reattivo il loop degli eventi e la riproduzione è coperta da test di regressione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
51
Fork
27
Merge medio
11h 59m
PR unite (30g)
33

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di The-OpenROAD-Project/ORAssistant

Tutte le issue di The-OpenROAD-Project/ORAssistant

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.