You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mobile browser tab does not reconnect SSE stream after returning from another app #39030
When accessing opencode serve or opencode web from a mobile browser (Chrome Android), switching to another app and coming back leaves the chat interface frozen. No new messages appear until the user manually refreshes the page.
Steps to reproduce
Run opencode serve --hostname 0.0.0.0
Open the web interface in Chrome on an Android phone
Start a conversation that generates a long response
Switch to another app (e.g. WhatsApp, settings, etc.)
Wait a few seconds
Switch back to Chrome
Expected behavior
The chat should show any new messages that arrived while the tab was backgrounded.
Actual behavior
The chat remains frozen at the last state before switching apps. Only a manual page refresh (F5 or pull-to-refresh) updates the interface.
Root cause
The SSE event stream in packages/app/src/context/server-sdk.tsx only handles tab lifecycle via pagehide/pageshow events, which are designed for bfcache (back-forward cache) navigation. On mobile:
pagehide often does not fire when a tab is backgrounded by switching apps
When it does fire, it calls stop() which aborts the SSE connection and may cancel server-side response generation
pageshow fires with event.persisted=false on return (not a bfcache restore), so the existing handler does nothing
The fix should listen to document.visibilitychange to reconnect the SSE stream when the tab becomes visible again.
Environment
OpenCode version: 1.17.20+
Device: Android phone (Chrome browser)
Server: opencode serve on Linux
Reacted by Andres Perez, seaweeduk, Daniel and Lucas Servén Marín
This issue might be related to an existing open issue. Please check:
SSE stream closes mid-turn (not persistent as documented) #38458: SSE stream closes mid-turn on opencode serve — covers server-side SSE stream persistence issues with /api/event dropping mid-turn; your issue is about the client-side reconnect path (visibilitychange) in the web UI, but both affect reliable SSE delivery when using opencode serve from a browser.
Still reproducible on v1.18.17 on a phone. Switching apps or letting the phone sleep leaves the current conversation frozen even though the response continues server-side.
Besides reloading, switching session tabs or toggling from the main agent to a subagent (or back) immediately reveals the missing updates. That suggests those navigation paths resync session state while returning the existing tab to the foreground does not. Current dev still handles pagehide/pageshow, with pageshow restarting only for a persisted bfcache restore; there is no visibilitychange resume path for ordinary mobile app switching.
I'd like to take this one. Root cause is in packages/client/src/solid/connection.ts: pagehide always stops the stream, but pageshow only calls start() when event.persisted is true — returning from background without the bfcache (most mobile and plain tab-return scenarios) leaves the stream dead. start() is already idempotent, so pageshow can restart unconditionally; bfcache restores, plain tab returns and mobile re-shows all recover. This also covers the same gap reported in #47258. Will include a lifecycle test.
Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.
Activity
github-actions commentedon Jul 27, 2026
This issue might be related to an existing open issue. Please check:
opencode serve— covers server-side SSE stream persistence issues with/api/eventdropping mid-turn; your issue is about the client-side reconnect path (visibilitychange) in the web UI, but both affect reliable SSE delivery when usingopencode servefrom a browser.andresperezl commentedon Aug 18, 2026
Still reproducible on v1.18.17 on a phone. Switching apps or letting the phone sleep leaves the current conversation frozen even though the response continues server-side.
Besides reloading, switching session tabs or toggling from the main agent to a subagent (or back) immediately reveals the missing updates. That suggests those navigation paths resync session state while returning the existing tab to the foreground does not. Current
devstill handlespagehide/pageshow, withpageshowrestarting only for a persisted bfcache restore; there is novisibilitychangeresume path for ordinary mobile app switching.seaweeduk commentedon Aug 20, 2026
been suffering this heavily too, makes it really annoying to use the webui on phone
holny commentedon Sep 4, 2026
I'd like to take this one. Root cause is in
packages/client/src/solid/connection.ts:pagehidealways stops the stream, butpageshowonly callsstart()whenevent.persistedis true — returning from background without the bfcache (most mobile and plain tab-return scenarios) leaves the stream dead.start()is already idempotent, sopageshowcan restart unconditionally; bfcache restores, plain tab returns and mobile re-shows all recover. This also covers the same gap reported in #47258. Will include a lifecycle test.thdxr commentedon Oct 11, 2026
Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (
opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊