[claude] App-state aware WebSocket reconnect on foreground (#33) #77

Merged
claude merged 1 commits from claude/issue-33 into main 2026-03-23 01:51:48 +00:00
Collaborator

Fixes #33

Changes

  • AppState listener in TimmyProvider: Listens for active/background transitions on iOS and Android (skipped on web)
  • Foreground reconnect: When app returns from background, checks ws.readyState. If not OPEN, cancels pending retries, resets backoff counter, sets status to "reconnecting", and calls connectWs()
  • Background disconnect: Proactively closes the WebSocket when backgrounding to avoid OS killing it mid-frame (saves battery)
  • New "reconnecting" status: Added to ConnectionStatus type, displayed as amber pulsing badge in ConnectionBadge
  • No duplicate connections: Old socket is fully closed before new one opens; pending retry timers are cancelled before reconnecting

Acceptance criteria met

  • Feed reconnects within seconds on foreground return
  • ConnectionBadge shows "Reconnecting" with amber pulse while socket is down
  • No duplicate WS connections (old socket closed, retry timers cancelled)
  • Exponential backoff preserved for sustained network loss; reset on foreground return
  • Works on both iOS and Android (skips AppState on web)
Fixes #33 ## Changes - **AppState listener in TimmyProvider**: Listens for `active`/`background` transitions on iOS and Android (skipped on web) - **Foreground reconnect**: When app returns from background, checks `ws.readyState`. If not OPEN, cancels pending retries, resets backoff counter, sets status to "reconnecting", and calls `connectWs()` - **Background disconnect**: Proactively closes the WebSocket when backgrounding to avoid OS killing it mid-frame (saves battery) - **New "reconnecting" status**: Added to `ConnectionStatus` type, displayed as amber pulsing badge in `ConnectionBadge` - **No duplicate connections**: Old socket is fully closed before new one opens; pending retry timers are cancelled before reconnecting ## Acceptance criteria met - Feed reconnects within seconds on foreground return - ConnectionBadge shows "Reconnecting" with amber pulse while socket is down - No duplicate WS connections (old socket closed, retry timers cancelled) - Exponential backoff preserved for sustained network loss; reset on foreground return - Works on both iOS and Android (skips AppState on web)
claude added 1 commit 2026-03-23 01:51:00 +00:00
feat: add AppState-aware WebSocket reconnect on mobile foreground
Some checks failed
CI / Typecheck & Lint (pull_request) Failing after 0s
b9a9d44da6
When the app returns from background, check if the WebSocket is still
open. If not, close the stale socket and reconnect with reset backoff.
Proactively close the WS when backgrounding to save battery and avoid
OS killing it mid-frame. Add "reconnecting" connection status with
amber pulsing badge so users see the app is re-establishing connection.

Fixes #33

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
claude merged commit 0bdf9336bc into main 2026-03-23 01:51:48 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: replit/timmy-tower#77