NameError in _proxy_websocket: every WebSocket proxy request crashes after recording (expert_plane out of scope) #68

Open
opened 2026-09-08 17:42:07 +00:00 by nsaspy · 0 comments
Owner

Summary

_proxy_websocket references expert_plane at two call sites, but expert_plane is a build_app kwarg that is never passed into the function. Every WebSocket proxy request raises NameError: name 'expert_plane' is not defined after the CaptureEvent is recorded — on both the failure and success paths.

Location (main @ HEAD)

  • llm_log/proxy.py:315 — failure path (_schedule_expert_ingest(request.app, expert_plane, event, b"") after recording the 502)
  • llm_log/proxy.py:391 — success path (same call after recording the 101 event)

_proxy_websocket's signature (line 269) has no expert_plane parameter; the sibling HTTP path avoids this because proxy() closes over build_app's local.

Observed impact (production, journalctl --user -u llm-log)

  • 26 × NameError: name 'expert_plane' is not defined. Did you mean: 'ExpertPlane'? tracebacks (2026-09-01), all via proxy.py:315.
  • After a failed upstream WS handshake the client receives a 500 instead of the intended 502 "upstream websocket connection failed" (the exception escapes before the return).
  • Expert-plane ingest for WS traffic never happens on any path.
  • Dormant in the last 24h only because all WS attempts died at handshake (52 × WSServerHandshakeError: 401 on wss://api.openai.com/v1/responses); any successful WS session would hit line 391.

Suggested fix

Thread expert_plane (and optionally require_expert_plane) through _proxy_websocket's parameters, mirroring proxy(), or stash it on the app like _INGEST_TASKS_KEY. One-line-ish fix at both call sites plus signature.

Regression fixture

A fake upstream that accepts the WS upgrade; assert the relay completes, the 101 event is recorded, and no 500/NameError is logged.

## Summary `_proxy_websocket` references `expert_plane` at two call sites, but `expert_plane` is a `build_app` kwarg that is never passed into the function. Every WebSocket proxy request raises `NameError: name 'expert_plane' is not defined` **after** the CaptureEvent is recorded — on both the failure and success paths. ## Location (main @ HEAD) - `llm_log/proxy.py:315` — failure path (`_schedule_expert_ingest(request.app, expert_plane, event, b"")` after recording the 502) - `llm_log/proxy.py:391` — **success** path (same call after recording the 101 event) `_proxy_websocket`'s signature (line 269) has no `expert_plane` parameter; the sibling HTTP path avoids this because `proxy()` closes over `build_app`'s local. ## Observed impact (production, journalctl --user -u llm-log) - 26 × `NameError: name 'expert_plane' is not defined. Did you mean: 'ExpertPlane'?` tracebacks (2026-09-01), all via `proxy.py:315`. - After a failed upstream WS handshake the client receives a **500** instead of the intended `502 "upstream websocket connection failed"` (the exception escapes before the return). - Expert-plane ingest for WS traffic never happens on any path. - Dormant in the last 24h only because all WS attempts died at handshake (52 × `WSServerHandshakeError: 401` on `wss://api.openai.com/v1/responses`); any successful WS session would hit line 391. ## Suggested fix Thread `expert_plane` (and optionally `require_expert_plane`) through `_proxy_websocket`'s parameters, mirroring `proxy()`, or stash it on the app like `_INGEST_TASKS_KEY`. One-line-ish fix at both call sites plus signature. ## Regression fixture A fake upstream that accepts the WS upgrade; assert the relay completes, the 101 event is recorded, and no 500/NameError is logged.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nsaspy/llm-log#68
No description provided.