From 57dc0455d1c65456ec3860859f917a4cf4f2186f Mon Sep 17 00:00:00 2001 From: jules Date: Sat, 16 May 2026 22:17:54 +1000 Subject: [PATCH] realtime: bail in connect() when getToken returns no token MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without a JWT the Phoenix TenantSocket refuses the handshake ("REFUSED CONNECTION TO ArcadiaWeb.TenantSocket"), the client retries forever, and both ends spam logs. Consumers like skyai-ecosystem set enableRealtime unconditionally at mount, before login completes, which is the common case for this noise. Callers should invoke connect() again after login (e.g. on crema:session-change) — the existing reconnect path covers that. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/realtime.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/realtime.ts b/src/realtime.ts index 9e9022e..6f79759 100644 --- a/src/realtime.ts +++ b/src/realtime.ts @@ -110,6 +110,16 @@ export function createArcadiaRealtime(opts: ArcadiaRealtimeOptions): ArcadiaReal setStatus("connecting"); const token = await opts.getToken(); + // No session → don't open the socket. Phoenix would refuse the + // handshake on the server (TenantSocket.connect/3 requires a JWT) + // and the client would retry forever, spamming both ends. Callers + // should invoke connect() again after login (e.g. on + // `crema:session-change`). + if (!token) { + setStatus("idle"); + return; + } + const factory = opts.socketFactory ?? ((endpoint, o) => new Socket(endpoint, o));