anomalyco / anomalyco/opencode

Mobile browser tab does not reconnect SSE stream after returning from another app

Open
#39,030 4 comments 4 reactions 1 assignee View on GitHub

@Brendonovich is already working on this.

Since Jul 27, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

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

  1. Run opencode serve --hostname 0.0.0.0
  2. Open the web interface in Chrome on an Android phone
  3. Start a conversation that generates a long response
  4. Switch to another app (e.g. WhatsApp, settings, etc.)
  5. Wait a few seconds
  6. 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:

  1. pagehide often does not fire when a tab is backgrounded by switching apps
  2. When it does fire, it calls stop() which aborts the SSE connection and may cancel server-side response generation
  3. 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.