Skip to content

Fix blocking async server handlers#618

Merged
jonsaadfalcon merged 2 commits into
mainfrom
fix-219-async-httpx
Jul 1, 2026
Merged

Fix blocking async server handlers#618
jonsaadfalcon merged 2 commits into
mainfrom
fix-219-async-httpx

Conversation

@ElliotSlusky

@ElliotSlusky ElliotSlusky commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • replace synchronous HTTP calls in async model management and SendBlue setup handlers with awaited httpx.AsyncClient calls
  • run speech transcription in a worker thread so Whisper backends do not block the event loop
  • enable WAL, NORMAL sync, busy timeout, and serialized writes for TelemetryStore SQLite writes

Closes #219

Testing

  • OPENJARVIS_HOME=/tmp/openjarvis-test-home-219 PYTHONPATH=src python3 -m pytest tests/server/test_model_management.py tests/server/test_speech_routes.py tests/server/test_agent_manager_routes.py tests/telemetry/test_store.py
  • python3 -m ruff check src/openjarvis/server/routes.py src/openjarvis/server/api_routes.py src/openjarvis/server/agent_manager_routes.py src/openjarvis/telemetry/store.py tests/server/test_model_management.py tests/server/test_speech_routes.py tests/server/test_agent_manager_routes.py tests/telemetry/test_store.py
  • git diff --check

Notes: local uv run pytest ... is blocked by local uv 0.5.9 failing to parse the current lockfile (uv.lock line 4129, editable package without version). A broader local adjacent run passed 162 tests and had 3 unrelated existing environment failures from the missing native memory extension / old metrics assertion.

@jonsaadfalcon jonsaadfalcon merged commit d865b4b into main Jul 1, 2026
7 checks passed
@jonsaadfalcon jonsaadfalcon deleted the fix-219-async-httpx branch July 1, 2026 00:37
jonsaadfalcon pushed a commit that referenced this pull request Jul 6, 2026
The OpenAI-compat and Ollama engines exposed stream()/stream_full() as async def but iterated a synchronous httpx.Client.iter_lines() internally, blocking the single event loop on every inter-token read (serializing concurrent chats; one wedged upstream read froze the whole API). Convert both to a shared AsyncHTTPEngineMixin using httpx.AsyncClient + aiter_lines() with a per-event-loop pooled client and the configured timeout applied; map mid-stream transport errors (RemoteProtocolError/ReadError) to EngineConnectionError via a deliberately narrow set that keeps CancelledError/GeneratorExit propagating; handle non-2xx explicitly (incl. 3xx and a typed EngineContextLengthError for context-window overflow 400s); switch litellm streaming to acompletion; and offload the blocking non-streaming handlers and websocket generate() to asyncio.to_thread. No public API change. Strong MockTransport-based tests, including a pin that the async path never touches the sync client. Complements #618.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance] Synchronous httpx.Client blocks the event loop in async FastAPI handlers

2 participants