Skip to content

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

Closed
athal7 wants to merge 1 commit intoanomalyco:devfrom
athal7:opencode/clever-island
Closed

fix(app): handle iOS backgrounding - resync session and reconnect SSE on resume#10723
athal7 wants to merge 1 commit intoanomalyco:devfrom
athal7:opencode/clever-island

Conversation

@athal7
Copy link
Contributor

@athal7 athal7 commented Jan 26, 2026

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

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

… on resume

- Add visibilitychange listener in session.tsx to resync when tab becomes visible
- Refactor global-sdk.tsx SSE consumption with auto-reconnect on clean disconnect
- Use exponential backoff (1s-30s) and pause reconnects while hidden
- Add visibility tracking utility to detect recent backgrounding
- Gate error toasts in prompt-input.tsx when failure likely due to backgrounding
- Check if message landed before removing optimistic UI on resume

Fixes anomalyco#10721
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iOS Safari/Firefox: session history rolls back after backgrounding until refresh + error toasts on resume

1 participant