Linear: https://linear.app/engineereddev/issue/ENG-254
What's in this PR:
ws/hub.ts:GET /api/wsupgrade on the same HTTP server (ws).hellowithinWS_HELLO_TIMEOUT_MSor 4401; the token is checked through the device registry's hash map (a revoked token fails at once);ready; replay fromsince(oldest first, ≤ 200) thenreplay_done;resyncwhensinceis unknown or > 200 behind;since: null→ no replay. Any other frame, invalid JSON or a repeatedhello→ 4400.- Broadcast of
push,push_deleted,device_added,device_updated,device_removedto every authenticated socket. On revoke, the event goes to the others first, then the device's sockets close with 4401. - Heartbeat: app-level
pingeveryWS_PING_SECONDS; two missed pongs → terminate. Backpressure:bufferedAmount> 1 MB → terminate. - Presence: open-socket counts per device feed
DeviceDTO.online(devices list,/api/me, events), withdevice_updateddebounced 2 s. - Shutdown hook closes every socket with 1012.
ws/timers.tsprovides injected timers for fast tests.
Verify (lead, on 4f2605b, based on 555a737):
pnpm install --frozen-lockfile→ exit 0mise run check:server→ exit 0 (Tests 215 passed (215), including 16 real-socket scenarios)mise run e2e:server→ exit 0 (14 tests; bundled runtime with the WebSocket on MinIO)- No
pneumo-e2e-*containers left.
Deviations:
- A repeated
hellocloses with 4400 (the spec says "any frame other than hello/pong after hello"; a second hello is treated as invalid). - Termination happens after two complete missed pong windows.
🤖 Generated with Claude Code