Files
magpie/internal
yetone 7af2a18c97 gateway: a realtime session is held to its gateway key's limit and slots
/v1/realtime (56c988cb5) is opened by a GET upgrade. keyLimited holds
only POSTs and keySlots skips every GET, so a gateway key with a token
or cost limit opened realtime sessions after its limit was spent, and
with the key limits plugin off (where a chat gets 503). A key allowed
one request at a time opened any number of sessions. Sessions are long,
so spend reached inside one wasn't checked either.

- keyLimited reserves a realtime upgrade (GET /v1/realtime or /realtime
  asking for a WebSocket) as a request: size 0, the model from the
  query, scoped limits through withSpent. The reservation is held until
  the handler returns, which is when the session ends.
- The session's key ticker, which already closes it when the key is
  turned off, also asks the limit each tick and closes the session
  (1008, the refusal as the reason) once the key can't spend more.
- keySlots holds a realtime upgrade as an eager route, its slot kept for
  the session. TestKeySlotEveryRoute's GET exemption leaves these two
  routes out (keySlotGets).

Run on mote at this tree (origin/main 19794cc10 + this change):
GOOS=darwin/windows/linux go vet ./internal/gateway ./internal/budget
./internal/gwbudget ok; go test ./internal/gateway -run
'Realtime|KeyLimit|KeySlot|Limit|Budget|Concurrency' ok.
Broken by hand, each red: keyLimited back to POST only ->
TestRealtimeHeldToKeyLimit (a spent key's session got 101); the tick's
limit check off -> the session that spent the limit stayed open; keySlots
skipping the GET -> TestRealtimeHoldsKeySlot (a second session opened).
Not run: the full suite, and a real vendor realtime session.
2026-11-16 16:02:54 +08:00
..
…
…
…
…
…
…
…
…
…
…