Skip to content

Event stream (SSE) doesn't resume after tab is backgrounded and restored — requires manual page refresh #47258

Closed

Description

@aydemir

Description

In packages/app/src/context/server-sdk.tsx, pagehide always calls stop() on the event stream (lines ~325-328), but pageshow only calls start() again if event.persisted === true (resumeStreamAfterPageShow, lines 162-165).

Since the event stream itself is an open streaming fetch() connection, it is a known bfcache blocker in most browsers — meaning the page is often not bfcache-eligible, so persisted comes back false on pageshow, and start() is never called.

Result: After backgrounding/returning to the tab (switching apps, locking screen, etc.), the live event stream stays dead and the UI stops reflecting session updates until a full manual page refresh remounts the app.

Confirmed as web-UI-specific: OpenChamber (a third-party client using the same server API/event stream) does not exhibit this issue — server side is fine.

Relevant code:

// lines 162-165
export function resumeStreamAfterPageShow(event: PageTransitionEvent, start: () => unknown) {
  if (!event.persisted) return
  start()
}

// lines 325-328 (onMount)
makeEventListener(window, "pagehide", stop)
makeEventListener(window, "pageshow", (event) => resumeStreamAfterPageShow(event, start))

### Plugins

_No response_

### OpenCode version

_No response_

### Steps to reproduce

_No response_

### Screenshot and/or share link

_No response_

### Operating System

_No response_

### Terminal

_No response_

Activity

  1. github-actions commented on Sep 4, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of an existing issue. Please check:

  2. holny commented on Sep 4, 2026

    @holny
    Contributor

    Same root cause as #39030 (the pageshow handler only restarts the stream after a bfcache restore) — picking both up in one fix there.

  3. aydemir commented on Sep 12, 2026

    @aydemir
    Author

    Same issue on Android Chrome here: app goes to background, the SSE stream goes half-open, and nothing reconnects on foreground.

    Our fix: aydemir/opencode@sse-only (e8ccb4e) — stall guard + watchdog timer + visibility/online reconnect in packages/app/src/context/server-sdk.tsx, with unit tests (server-sdk.test.ts, 22 passing).

    Verified on a real device (3 sessions x ~90 tool calls, no hangs). Feel free to cherry-pick if useful, based on 193de13.

  4. neriousy commented on Oct 19, 2026

    @neriousy
    Member

    This is fixed in v2: the web app restarts its event stream on every pageshow, and resynchronizes after returning to the foreground following inactivity or regaining network connectivity. Upgrade with npm i -g @opencode/cli@latest (or update the desktop app). If you still see this on v2, please open a new issue with the details.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions