Skip to content

fix(desktop): persist browser sessions across restarts, prevent tab unmounts, and increase tunnel limit - #53453

Closed
4Liberty wants to merge 1 commit into
anomalyco:devfrom
4Liberty:fix/browser-session-persistence
Closed

4Liberty wants to merge 1 commit into
anomalyco:devfrom
4Liberty:fix/browser-session-persistence

Conversation

@4Liberty

@4Liberty 4Liberty commented Oct 5, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #50382

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Resolves three issues affecting OpenCode Desktop's embedded browser pane:

  1. Sessions/Cookies Wiped on Reload: The browser pane previously generated an ephemeral UUID partition (opencode-browser-${crypto.randomUUID()}), causing all cookies, logins, IndexedDB, and Local Storage to be discarded on app restart or pane re-attachment. Switched to partition: "persist:opencode-browser" so Electron persists session cookies and authentication state across restarts in the persistent partition directory.
  2. Background Tabs Destroyed & Reloaded: Main frame navigation in the host window previously triggered did-start-navigation -> close(entry) -> page.dispose(), causing the browser pane to be destroyed and fully reloaded upon refocus. We retain lifecycle cleanup on actual window destruction while preventing spurious unmounts on internal window routing.
  3. Tunnel Bottleneck on Rich Assets: The RPC network proxy enforced an aggressive hard limit of 64 concurrent sockets (sockets.size >= 64), causing asset-rich pages to stall or throw 502 connection limit errors. Raised the connection ceiling to 512.

How did you verify your code works?

  • Verified Electron session persistence: session cookies and Local Storage are successfully retained across app restarts in Partitions/opencode-browser.
  • Tested page stability across backgrounding and navigation.
  • Verified asset loading concurrency under heavy network requests.

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

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

@4Liberty 4Liberty changed the title fix(browser): persist session storage across restarts, prevent tab unmount on navigation, increase tunnel connection limit fix(desktop): persist browser sessions across restarts, prevent tab unmounts, and increase tunnel limit Oct 8, 2026
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@ephraimduncan

Copy link
Copy Markdown

Logins also clear at each restart for me on 2.2.5. But I do not think one shared persist:opencode-browser partition can work, because of how the pane sends its traffic.

createBrowserNetwork gives each pane its own proxy, which tunnels to the server of that pane's session, and sets it with partition.setProxy(). The proxy is a setting of the partition. With one partition for all panes, the newest pane's proxy replaces the proxy of every other pane. A pane for a session on a remote server then browses through a different server. When the newest pane closes, its proxy closes with it, and the other panes lose their connection. Each pane also calls closeAllConnections() when it opens and when it closes, and with one partition that cuts the connections of all panes. webRequest.onBeforeRequest keeps only its last listener too, so the fileRoots of the newest pane decide which file:// pages every pane can open.

What works for me is a partition per pane, as now, with one shared cookie jar in the main process. Each new partition gets the jar on app session-created, and the changed events of each pane's cookies go to the jar and to the other panes. I store the jar with safeStorage, because EnableCookieEncryption is off in the 2.2.5 macOS build, so a persist: partition would write login cookies to disk unencrypted. Local storage and IndexedDB still clear at restart, but GitHub and Google keep their logins in cookies.

For the maintainers: is it intended that the pane forgets logins at restart? #50382 asked about this. It was closed with the V1 issues, but it is about the V2 desktop browser. I can see one reason to keep the current behavior. The agent drives the same pane, so a saved login lets the agent act as the user on that site.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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.

desktop(browser): embedded browser never persists cookies - logins (e.g. Google) lost on every app restart

2 participants