Skip to content

app: /chat non-blocking maken (run_in_threadpool rond Mistral-call) — event loop blokkeert nu tot 180s #80

Closed

Description

@Atrium0804

Part of #78

Probleem

async def chat in app/main.py roept de blocking mistral_client.answer_question(...) (requests.post, timeout=180s) direct aan in de event loop. Met 1 uvicorn-worker blokkeert één trage agent-run de hele app: gemeten — een GET /healthz 1s na een gemockte 8s /chat duurde 7,0s in plaats van ~0s. Alle gelijktijdige requests (ook andere gebruikers) schuiven aan en halen de proxy-timeout niet.

Gewenst

  • Draai de Mistral-call off-loop: await run_in_threadpool(mistral_client.answer_question, ...) (starlette.concurrency) of schakel mistral_client om naar httpx AsyncClient. Kies één van beide consequent.
  • Idem voor check_reachable in /healthz (blocking requests.get, timeout=10s).
  • DEFAULT_TIMEOUT = 180 in app/mistral_client.py blijft de backstop.

Acceptatiecriteria

  • Nieuwe test in app/tests/test_app.py: tijdens een gemockte trage answer_question (bv. 5s) reageert een gelijktijdige GET /healthz (gemockt, instant) binnen ~1s.
  • Alle bestaande tests in app/tests/ groen (pytest app/tests).
  • Handmatige check: twee gelijktijdige /chat-vragen in de lokale dev-server blokkeren elkaar niet meer.

Context

Gemeten in de diagnose van #78 (2026-11-13). Dit ticket blokkeert het 202/status-ticket voor echte voortgangsstappen in de UI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions