Skip to content

Fix /track-ws 404: install a WebSocket backend (websockets)#6

Merged
ak2k merged 1 commit into
mainfrom
fix/websockets-dep
Jun 5, 2026
Merged

Fix /track-ws 404: install a WebSocket backend (websockets)#6
ak2k merged 1 commit into
mainfrom
fix/websockets-dep

Conversation

@ak2k

@ak2k ak2k commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Bug

Live letter tracking never worked in the deployed service. Every /track-ws WebSocket upgrade returns 404 with this in the gunicorn log:

[WARNING] No supported WebSocket library detected. ... install 'websockets' or 'wsproto'
"GET /track-ws HTTP/1.1" 404
[WARNING] Unsupported upgrade request.

Root cause

uvicorn is declared without the [standard] extra, so the uv2nix-built env contains no WebSocket protocol library (websockets/wsproto). websockets appears in uv.lock only as uvicorn's unselected extra, so it's never installed. Under gunicorn's UvicornWorker, the upgrade can't be handled → 404 for every serial.

This slipped through because the test suite uses Starlette's TestClient, which performs WebSockets in-process and does not exercise uvicorn's protocol backend.

Fix

  • Add websockets>=14,<17 as a direct dependency (lighter than the full uvicorn[standard] extra — no uvloop/httptools/watchfiles — and all the worker needs to accept the upgrade), and re-lock.
  • Add test_uvicorn_has_websocket_backend asserting a ws backend is importable, so this regression can't ship silently again.

Checks

  • Full suite 288 passed (incl. the new guard).
  • checks.lint (ruff) + checks.typecheck (mypy) clean.

Bare `uvicorn` ships no WebSocket protocol library — they live in the
`uvicorn[standard]` extra. Under gunicorn's UvicornWorker that means every
`/track-ws` upgrade is rejected with "No supported WebSocket library
detected" and returns 404, so live letter tracking never worked in the
deployed service (the test suite missed it because Starlette's in-process
TestClient does WebSockets without uvicorn's backend).

Depend on `websockets` directly — lighter than the full `[standard]` extra
(no uvloop/httptools/watchfiles) and all the worker needs to accept the
upgrade. Add a guard test asserting a ws backend is importable so this
can't silently regress.
@ak2k ak2k merged commit f3e8599 into main Jun 5, 2026
4 checks passed
@ak2k ak2k deleted the fix/websockets-dep branch June 5, 2026 23:11
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.

1 participant