[PR #11671] fix(app): handle iOS backgrounding - resync session and reconnect SSE on resume #13892

Open
opened 2026-02-16 18:18:43 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11671

State: open
Merged: No


Summary

Fixes iOS Safari backgrounding issues where the browser kills network connections when the app is backgrounded. When users return, requests would fail and confusing error toasts would appear.

Closes #10721

Changes

  • New visibility.ts utility - Tracks page visibility state with wasRecentlyBackgrounded(), getLastHiddenAt(), isHidden()
  • SSE auto-reconnect - Reconnects with exponential backoff (1s→30s), pauses while hidden
  • Session resync on resume - Resyncs session data when returning from background (after >1s hidden)
  • Smart error suppression - Suppresses error toasts if app was recently backgrounded, then resyncs to check if message actually landed

Testing

  • 10 unit tests for visibility tracking utility
  • Manually verified on iOS Safari with side-by-side comparison video:
    • Before: Error toast appears after backgrounding
    • After: No error toast, graceful recovery

https://github.com/user-attachments/assets/25109bb4-b224-4877-9950-5e8ebd36f0c9

Related

Revives approach from closed PR #10723

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11671 **State:** open **Merged:** No --- ## Summary Fixes iOS Safari backgrounding issues where the browser kills network connections when the app is backgrounded. When users return, requests would fail and confusing error toasts would appear. Closes #10721 ## Changes - **New `visibility.ts` utility** - Tracks page visibility state with `wasRecentlyBackgrounded()`, `getLastHiddenAt()`, `isHidden()` - **SSE auto-reconnect** - Reconnects with exponential backoff (1s→30s), pauses while hidden - **Session resync on resume** - Resyncs session data when returning from background (after >1s hidden) - **Smart error suppression** - Suppresses error toasts if app was recently backgrounded, then resyncs to check if message actually landed ## Testing - 10 unit tests for visibility tracking utility - Manually verified on iOS Safari with side-by-side comparison video: - **Before**: Error toast appears after backgrounding - **After**: No error toast, graceful recovery https://github.com/user-attachments/assets/25109bb4-b224-4877-9950-5e8ebd36f0c9 ## Related Revives approach from closed PR #10723
yindo added the pull-request label 2026-02-16 18:18:43 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13892