gaubeebangeel (X) set up Qwen's Token Plan in magpie and couldn't use its
realtime voice: magpie had no /v1/realtime, so the WebSocket upgrade got a
404. Token Plan does cover realtime: qwen-audio-3.0-realtime-plus at
wss://<plan host>/api-ws/v1/realtime?model=… with the plan's sk-sp- key,
OpenAI Realtime events
(platform.qianwenai.com/docs/token-plan/best-practices/realtime-voice).
GET /v1/realtime and /realtime upgrade to a WebSocket after the same Front
guards as every route (lanGuard, corsGuard, keys, the rebinding check),
plus a same-origin check on the socket's Origin. The model resolves as on
the other routes (a bare id unlisted anywhere goes to the one DashScope
provider that is on), with key, model and account holds, and each try is
dialled in turn with the account's key. A DashScope base ending
/compatible-mode/v1 dials /api-ws/v1/realtime; any other base dials
base+/realtime (OpenAI). Frames go both ways as they are; a close goes on
with its code and reason. Text frames are masked going up and restored
coming down (audio appends and deltas are not), failing closed. Each
response.done's usage is recorded as a "realtime" call (cached input as
cache read). openai-insecure-api-key / organization / project
subprotocols never go upstream. Shutdown ends open sessions with 1001.
/realtime is a client route on magpie web's port (and in the LazyCat
manifest), and a read-only key is refused it.
Run (mote, at this tree):
- TestRealtime* (fake upstream WebSocket, no network): Token Plan path,
echo, binary, close both ways, usage 60 in / 40 cache read / 20 out,
OpenAI-style path, subprotocol filter, masking; guards: 426, 400, 404,
Origin evil/null/localhost subdomain 403, rebound host, remote without
key 401, key held to another provider 403, vendor 401 passed on.
- Broken by hand, each went red: subprotocol filter removed, masking off,
cached tokens not subtracted.
- GOOS=linux and GOOS=windows go vet ./internal/gateway: clean.
- go test -count=1 -timeout 45m ./internal/gateway ./internal/masking
./internal/gui: the first run found TestClientPathCoversHandler,
TestReadOnlyKeyEveryRoute and then TestLazyCatManifestListsTheClientRoutes
red, all fixed here and rerun green. Otherwise ok. The log has one
recovered "close of closed channel" in continuation_test.go:781's
doneHold fake upstream (a test fake this change doesn't touch; in both
runs), already filed as #6505 (and its duplicate #6690).
- Rebased on origin/main 6dbd6e5b1 and rerun at the rebased head: the
TestRealtime* tests, the three route-list guard tests, gofmt -l, and
GOOS=linux / GOOS=windows go vet ./internal/gateway.
Not run: the full ./... suite at any head (mote at load ~22-33 of 18, mica ~66 of
12). Not tried with a real Token Plan account or a real Realtime client.