Skip to content

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

Open
athal7 wants to merge 1 commit intoanomalyco:devfrom
athal7:fix/ios-backgrounding-session-resync
Open

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

Conversation

@athal7
Copy link
Contributor

@athal7 athal7 commented Feb 1, 2026

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
trim.8FDE21FE-1ABE-460B-94A2-807440206C3E.MOV

Related

Revives approach from closed PR #10723

@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2026

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

No duplicate PRs found

@athal7 athal7 force-pushed the fix/ios-backgrounding-session-resync branch from 9a3bb8c to de93714 Compare February 1, 2026 21:33
@athal7 athal7 marked this pull request as ready for review February 1, 2026 21:34
@athal7 athal7 requested a review from adamdotdevin as a code owner February 1, 2026 21:34
@athal7 athal7 force-pushed the fix/ios-backgrounding-session-resync branch 7 times, most recently from e059811 to 3ab571d Compare February 3, 2026 11:15
… 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

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