Skip to content

Poll Controller (fallback transport)

src/lib/offline/poll.ts is the periodic-polling transport. It was the MVP real-time mechanism (ADR-006, spec 013) and is now the fallback that runs only while the live WebSocket is unavailable (ADR-011); the live path suspends it.

  • POLL_INTERVAL_MS (10 s) and STALE_AFTER_MS (= 3× interval) — cadence and staleness window.
  • BASE_SURFACES — the surfaces the controller refreshes (lists, tasks, steps, my-day, memberships).
  • surfaceKey(s) — stable key per surface (cursor bookkeeping).
  • decideSince(...) — compute the ?since cursor for a surface’s delta read.
  • shouldPoll(online, hidden) — gate polling on connectivity + page visibility (no polling when offline or backgrounded).
  • PollController / getPollState() / subscribePollState(listener) — the controller and its observable state for the status UI.

The controller calls the same delta-read reconcilers as the live transport (see Sync-Core Reconcilers), so polling and push share one data path. When LiveConnection is connected, the fast poll is suspended; on disconnect it resumes, and every reconnect runs a catch-up read — preserving convergence and offline-first regardless of socket health (ADR-006 → ADR-011).

Related: LiveConnection WS Client (the primary transport), Sync-Core Reconcilers (the shared fold logic).