Fix Start button not updating: unblock the event loop
All checks were successful
Tests / Python Backend Tests (push) Successful in 5s
Tests / Frontend Tests (push) Successful in 8s
Tests / Rust Sidecar Tests (push) Successful in 2m4s

start_transcription() blocks up to 15s waiting for the Deepgram
WebSocket to connect. Running it synchronously in the async endpoint
blocked the entire uvicorn event loop, preventing:
- pollStatus from completing (frozen HTTP request)
- WebSocket broadcasts from being sent
- Any other API requests from being handled

Fix: run start/stop/reload in thread pool via run_in_executor so
the event loop stays responsive during long-running operations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Developer
2026-04-08 12:43:49 -07:00
parent 2654200fe9
commit ae61c8c75a

View File

@@ -151,14 +151,24 @@ class APIServer:
@app.post("/api/start") @app.post("/api/start")
async def start_transcription(): async def start_transcription():
success, message = ctrl.start_transcription() import asyncio
# Run in thread pool to avoid blocking the event loop
# (start_recording can block up to 15s waiting for Deepgram WS)
loop = asyncio.get_event_loop()
success, message = await loop.run_in_executor(
None, ctrl.start_transcription
)
if not success: if not success:
raise HTTPException(status_code=400, detail=message) raise HTTPException(status_code=400, detail=message)
return {"status": "ok", "message": message} return {"status": "ok", "message": message}
@app.post("/api/stop") @app.post("/api/stop")
async def stop_transcription(): async def stop_transcription():
success, message = ctrl.stop_transcription() import asyncio
loop = asyncio.get_event_loop()
success, message = await loop.run_in_executor(
None, ctrl.stop_transcription
)
if not success: if not success:
raise HTTPException(status_code=400, detail=message) raise HTTPException(status_code=400, detail=message)
return {"status": "ok", "message": message} return {"status": "ok", "message": message}
@@ -223,7 +233,11 @@ class APIServer:
@app.post("/api/reload-engine") @app.post("/api/reload-engine")
async def reload_engine(): async def reload_engine():
success, message = ctrl.reload_engine() import asyncio
loop = asyncio.get_event_loop()
success, message = await loop.run_in_executor(
None, ctrl.reload_engine
)
if not success: if not success:
raise HTTPException(status_code=500, detail=message) raise HTTPException(status_code=500, detail=message)
return {"status": "ok", "message": message} return {"status": "ok", "message": message}