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

Closed
opened 2026-02-16 18:18:23 -05:00 by yindo · 0 comments
Owner

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

State: closed
Merged: No


Summary

Fixes session history rollback and error toasts that appear when resuming OpenCode web UI on iOS after backgrounding.

Changes

1. Visibility-triggered session resync (pages/session.tsx)

  • Add visibilitychange listener that resyncs the current session when the tab becomes visible after being hidden for 1+ seconds

2. SSE auto-reconnect with backoff (context/global-sdk.tsx)

  • Wrap SSE consumption in a reconnect loop that automatically reconnects on clean disconnect (common on iOS backgrounding)
  • Use exponential backoff (1s → 2s → 4s → ... → max 30s)
  • Pause reconnection attempts while tab is hidden to save resources

3. Visibility tracking utility (utils/visibility.ts)

  • New shared module to track when the page was last hidden/visible
  • wasRecentlyBackgrounded(thresholdMs) detects if the page was just resumed from background

4. Background-aware error handling (components/prompt-input.tsx)

  • Gate error toasts when failure likely occurred due to iOS backgrounding
  • For prompt submission: resync session and verify if message actually landed before showing error or removing optimistic UI
  • For shell/command submission: suppress toast if recently backgrounded

Fixes #10721

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10723 **State:** closed **Merged:** No --- ## Summary Fixes session history rollback and error toasts that appear when resuming OpenCode web UI on iOS after backgrounding. ## Changes ### 1. Visibility-triggered session resync (`pages/session.tsx`) - Add `visibilitychange` listener that resyncs the current session when the tab becomes visible after being hidden for 1+ seconds ### 2. SSE auto-reconnect with backoff (`context/global-sdk.tsx`) - Wrap SSE consumption in a reconnect loop that automatically reconnects on clean disconnect (common on iOS backgrounding) - Use exponential backoff (1s → 2s → 4s → ... → max 30s) - Pause reconnection attempts while tab is hidden to save resources ### 3. Visibility tracking utility (`utils/visibility.ts`) - New shared module to track when the page was last hidden/visible - `wasRecentlyBackgrounded(thresholdMs)` detects if the page was just resumed from background ### 4. Background-aware error handling (`components/prompt-input.tsx`) - Gate error toasts when failure likely occurred due to iOS backgrounding - For prompt submission: resync session and verify if message actually landed before showing error or removing optimistic UI - For shell/command submission: suppress toast if recently backgrounded Fixes #10721
yindo added the pull-request label 2026-02-16 18:18:23 -05:00
yindo closed this issue 2026-02-16 18:18:23 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13541