refactor(connect): one live connection, no token in any address (SSE removed)

Plan step 4.0. Owner (2026-11-17): no phone in use needs to keep working, so no
compatibility path.
- Removed the SSE channel: routers/sse.py (/api/sse/stream, which still accepted a JWT whose
  session had ended — a signed-out phone could keep listening), services/sse_bus.py (every
  backend module now calls services/ws_bus.broadcast_sync directly), waiter useSSE.js.
- Credentials only in the first frame: the waiter's useWebSocket and the manager's
  LiveProvider send {token} there like the terminal; routers/ws.py no longer reads ?token=
  (a token in a URL ends up in proxy and server logs).
- Waiter: SSEContext → LiveContext (LiveProvider, useLiveContext, liveAlive, the
  'live-event' / 'live-reconnected' window events), dead SSE compat code removed.
- Tests: a token in the address is refused, /api/sse/stream is 404; e2e browser (3 delivery
  modes) and manager assert no token in the live connection's address. Android taps now
  wait for their element (the fixed sleeps made the suite flaky, KI-009).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 10:49:21 +02:00
co-authored by Claude Opus 5.5
parent d0c6a10e47
commit f85894a72e
43 changed files with 112 additions and 350 deletions
+3 -4
View File
@@ -3,7 +3,7 @@
// hook is now a thin wrapper around this. No React.
//
// Protocol (local_backend/routers/ws.py):
// 1. connect to ws[s]://host/api/ws/connect?token=<jwt> (or no query, see `credentials`)
// 1. connect to ws[s]://host/api/ws/connect (never a token in the address: phase 4.0)
// 2. send { cursor: <last seq>, ...credentials() } at once (0 = first connect / no history)
// 3. the server replays missed events, then sends { type: "ready" }
// — or { type: "refused", data: { code } } and closes (4001 sign in again, 4003 device)
@@ -15,11 +15,10 @@
// the `cursor` store the app provides (the waiter keeps it in IndexedDB).
//
// const live = createLiveClient({
// url: () => wsUrl(`/api/ws/connect?token=${encodeURIComponent(token)}`),
// url: () => wsUrl('/api/ws/connect'),
// credentials: () => ({ token }), // a paired screen: ({ device: deviceToken, token: sessionToken })
// cursor: { load: async () => seq, save: seq => … },
// onEvent: (type, data) => …, onReady: () => …, onDisconnect: () => …,
// // terminal (paired device): credentials go in the first frame, never in the URL
// credentials: () => ({ device: deviceToken, token: sessionToken }),
// onRefused: code => …, // e.g. 'device.revoked', 'auth.session_ended'; it keeps retrying
// })
// live.start(); …; live.reconnect(); …; live.stop()