feat(sync): the app listens to the companion WebSocket for instant web-to-app sync (#175) #193

Merged
maximus merged 4 commits from issue-175-sync-websocket into master 2026-11-08 15:35:46 +00:00

4 commits

Author SHA1 Message Date
le king fu
ffe5556ec3 test(sync): pin the canSync check after the ticket and the timer cleanup on stop (#175)
Refs #175

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 21:46:59 -05:00
le king fu
e00bcf6e8a fix(sync): keep the notice window on its timer and survive a throwing WebSocket (#175)
Self-review findings. A notice landing after the nominal end of the window
but before its (late) timer armed a second window timer; the first one then
cleared the handle of the second, and the next notice synced inside a
window. The window now lasts until its single timer fires. A WebSocket
constructor that throws is handled as a failed connection instead of an
unhandled rejection that left the state on "connecting".

Refs #175

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 21:20:14 -05:00
le king fu
4a30d646b4 fix(sync): retry the socket with backoff while no token is available yet (#175)
At launch the Logto session may not be loaded when the socket starts: a
missing token used to stop the socket like a ticket 401, until the next
return to the foreground. It now waits with the reconnection backoff,
without any request; only a 401 stops the socket.

Refs #175

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 21:16:19 -05:00
le king fu
df40602a49 feat(sync): listen to the companion WebSocket for instant web-to-app sync (#175)
The app opens the companion WebSocket in the foreground (ticket from
POST /api/ws-ticket, then wss://.../ws derived from SYNC_API_BASE). A sync
notice asks the scheduler at once; later notices within 20 s fold into one
sync at the end of the window. The fixed 30 s tick skips while the socket is
open and the last sync is under 2 min old.

Reconnection: 1 s doubled, capped at 60 s, +-20 % jitter, reset after 30 s
open; auth_expired takes a new ticket at once; ticket 401 stops until the
next start; ticket 429 waits for the bounded Retry-After. The socket closes
in the background, on sign-out, sync off and canSync false.

syncSocket.ts is pure and import-free (tests/syncSocket.test.mjs under node);
syncSocketClient.ts wires fetch, WebSocket and timers and only calls
scheduleSync. REVIEW.md Haut Sync line and review-levels.py include both.

Refs #175

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 21:13:16 -05:00