Repository navigation
Description
Summary
The desktop in-app browser (Review pane) disconnects/reloads its page every 60-80 seconds, and immediately every time a prompt is sent. Re-attaching the browser connection disposes all of its tunnels, which kills every socket of the page being previewed.
Environment
- opencode version: 2.2.5 (desktop app 2.2.5, bundled CLI 2.2.5)
- OS: Linux 6.18.33.2-microsoft-standard-WSL2 (WSL2,
x86_64), no/dev/dri - Terminal: xterm-256color (desktop app window, X11 via WSLg)
- Shell: /bin/bash
- Install/channel: latest (
.debinstall,resources/app-update.ymlchannellatest; updater reports "already up to date") - Active plugins: none
Reproduction
- Open a session in the desktop app and open the in-app browser pane.
- Load a page that keeps a long-lived connection, e.g. a Vite dev server:
http://localhost:5176. - Leave it idle. Every ~60-80 s the page reloads.
- Send a prompt in the chat. The page reloads immediately.
Expected Behavior
The preview page keeps its connections (including the HMR WebSocket) across idle periods and across prompts, until the user navigates or closes the tab.
Actual Behavior
On a ~60-80 s cycle the server ends /api/event (SSE) and /api/rpc/experimental.browser/attach at the exact same instant with the same lifetime, then the app re-attaches the browser connection.
Observed in ~/.local/share/opencode/log/opencode.log (server side, http.span in ms):
api/event span=59824 status=200 -> 02:18:32.211
experimental.browser/attach span=59824 status=499 -> 02:18:32.215
api/event span=81672 status=200 -> 02:19:54.971
experimental.browser/attach span=81672 status=499 -> 02:19:54.978
api/event span=74450 status=200 -> 02:21:10.466
experimental.browser/attach span=74454 status=499 -> 02:21:10.476
Every re-attach destroys the page's sockets. From ~/.config/ai.opencode.desktop/logs/<ts>/renderer.log, aligned to those same seconds:
[21:10:21.871] [info] [vite] server connection lost. Polling for restart...
[21:10:23.752] [debug] [vite] connecting...
[21:10:23.976] [debug] [vite] connected.
Vite then does a full reload, which is what the user sees as "the browser keeps cutting out".
Related symptom: experimental.browser/tunnel.open returns HTTP 400 359 out of 364 times, because the request arrives against an attachment whose connectionID was already replaced.
Additional Context
Cause is visible in the shipped attach handler: a new attach closes the previous one with state replaced and then calls tunnels.dispose(), which destroys every TCP socket of that attachment:
let c=(q,E="closed")=>H(function*(){let j=a.get(q);if(!j)return;
a.delete(q), j.tunnels.dispose(), yield*Yr(j.closed,E)});
...
attach: ... yield*c(q.sessionID,"replaced") ...
So the tunnel layer is tied 1:1 to the attachment lifetime. Any long-lived connection inside the preview (HMR WebSocket, SSE, polling) is guaranteed to break on every re-attach. Since page traffic is proxied server-side through these tunnels, the preview can never hold a stable connection.
Suggested fixes:
- Do not dispose tunnels on
replaced; keep them until the new attachment confirmsattached, or make tunnels independent of the attachment and key them by tab instead ofconnectionID. - Send periodic keepalive comments on
/api/event(and onbrowser/attach) so an idle stream is not treated as dead. Lifetimes of 59.8 s on an idle session point to a ~60 s idle timeout closing the SSE, and the app then rebuilding all streaming connections including the browser attachment. - Make
tunnel.opentolerate an attachment race instead of returning 400, or return the reason so the client can retry intentionally.
Possibly related: #51857 (stalled-stream watchdog / zombie SSE in the v2 client refactor).
Frequency: continuous, roughly once per minute while a session is open; deterministic extra reset on every prompt submission.
Workaround: use a normal external browser for http://localhost:5176; the in-app pane only holds up for static previews (images/HTML) that do not keep long-lived connections.
Activity
opencodejr commentedon Nov 6, 2026
Thanks for the detailed report and logs. I couldn't reproduce this here: it needs the desktop app's in-app browser pane, and that can't run in our headless test environment. A maintainer with the desktop app will need to try it.
From reading the code on the latest
dev:tunnel.open400s you saw./api/eventevery 15 s. So the ~60–80 s cycle and the re-attach after every prompt most likely start in the desktop client, not with a server-side idle timeout. I haven't verified this.Related issues:
Until this is fixed, opening the dev server in an external browser, as you suggested, avoids the problem.
CerteroMed commentedon Nov 6, 2026
Follow-up with a sharper measurement. The cycle is not a timer and not a stalled stream: the desktop client rebuilds the event stream + browser attachment at every session step, and each rebuild disposes the preview's tunnels.
1. The server does not stall, so the watchdog is not firing
I opened
/api/eventdirectly against the local service for 100 s and timestamped every line:Inter-heartbeat gaps: 15.0 s, six times in a row, minimum and maximum identical. No gap above 5 s, no missing heartbeat. Whatever closes the stream, the server keeps heartbeating normally.
2. The streams live exactly one turn, then close at the step boundary
Same log,
http.spanin ms (event and attach always close together, same span):The span matches the wall-clock length of the preceding turn (opened 02:25:45, closed 02:28:18 = 153 s). The close is immediately followed by the
gitsnapshot spawns and the shell command of the next step, not by any idle timeout.This matches the reported symptom exactly: sending a prompt drops the preview immediately, and the "~60 s" I first reported was just the interval between prompts, not a fixed timeout.
3. Consequence
At every step the client re-attaches,
attachrunsc(sessionID, "replaced")→tunnels.dispose()→ every socket of the page in the Review pane is destroyed. A page that holds a long-lived connection (Vite's HMR WebSocket atlocalhost:5176) loses it, prints[vite] server connection lost. Polling for restart…, reconnects and does a full reload. That is the visible "cut".So the fix priority is the tunnel lifetime, not a timeout value: re-attach must not dispose tunnels that are still carrying a live tab.
CerteroMed commentedon Nov 6, 2026
Cross-platform confirmation: this is not WSL/Linux-specific. Same desktop version (2.2.5) on native Windows shows the identical reload loop.
%APPDATA%\ai.opencode.desktop\logs\20261105T213649\renderer.log(Windows 11, desktop 2.2.5, samehttp://localhost:5176preview):Intervals between losses on that run: 62 s, 62 s, 75 s, 64 s, 72 s, 64 s, 106 s, 307 s, 126 s, 96 s, 62 s, 61 s. Same order of magnitude and same irregular pattern as the Linux logs (59.8 s, 74.5 s, 81.7 s, 153 s), i.e. tied to session steps rather than to the OS.
Counts of
server connection lostper Windows run in the same folder: 48, 26, 10, 4, 3 — the loop has been present for at least a week on Windows too.CerteroMed commentedon Nov 10, 2026
Still reproducing on desktop 2.2.5 (
.deb, Linux / WSL2, bundled CLI 2.2.5), and this run was idle — no prompt sent, no RPC probing from my side.Two refinements to my earlier report:
1. The re-attach does not need a prompt; it is a client tick of ~59.6 s
~/.local/share/opencode/log/opencode.log,run=05efdc1e, window 15:02–15:07 UTC. Every burst is six concurrentbrowser/attachstreams, all ending within ~150 ms of each other, each with a matchingapi/eventclosing <5 ms before it:So in this window the cadence is a hard ~59.6 s, and the burst is six streams, not one (one per open session/tab in the desktop app, presumably). The 121 s stretch is the one longer gap. That rules out "one rebuild per prompt step" as the only trigger — the tick runs with nothing happening in the session at all.
Totals for the whole log so far:
tunnel.openspans are 0–5 ms, so as reported they fail before any socket attempt. There are nohttp_proxy/https_proxyvariables set on this machine (onlyno_proxyfor loopback), so #50476 is not what I am hitting.2. The dispose-on-replace code is still in the 2.2.5 binary
Confirmed against the installed bundle (
/opt/OpenCode/resources/opencode-cli), not justdev:And neither 2.2.6 nor 2.2.7 release notes mention a change to the browser attachment/tunnel lifetime (2.2.7 shipped today, 10:37 UTC; I am on 2.2.5, and updating is not expected to change this).
Unrelated note: #62308 is a different reporter's problem (macOS + AVG Web Shield blocking the service's outbound connections) and was closed as not planned; it does not cover this lifecycle issue, which needs no security software and occurs with
localhosttargets too.Ollegio commentedon Nov 24, 2026
Same behaviour on macOS with 2.4.1, and it is what produces the repeated Code Mode catalog notices. No browser pane needed to see it — the attach churn alone is enough.
Environment: OpenCode Desktop 2.4.1 (macOS Darwin 25.6.0, arm64) plus CLI 2.4.1, both against one shared
opencode serve --service. No desktop-only plugins; the only extra plugins are a localpeon-ping.ts,superpowers,opencode-websearch-deepseek.Server log (
~/.local/share/opencode/log/opencode.log, UTC):POST /api/rpc/experimental.browser/attachresponses. Over the whole log, at an earlier count: 1 212 requests, 1 134499and 78400.499onattachends in the same millisecond as aGET /api/event200, i.e. both streams are rebuilt together, as you describe:18:36:15.020has two attaches ending in the same millisecond withhttp.span=17950and17954; a later burst has six attaches closing within ~150 ms of each other.p50 = 3.3 s,p90 = 48.7 s,max = 14 752 s.What this does to the session: each attach/detach pair flips the
browsernamespace in the Code Mode catalog, and every flip appends asystemmessage to the session.browser, 30 are "browserno longer available".21:33:01 add / 21:33:06 remove,21:34:00 / 21:34:06,21:36:34 / 21:36:40,21:37:00 / 21:37:07,22:18:51 / 22:19:00,23:16:45 / 23:16:51.18:34:06.391attach499+/api/event200→18:34:06.472"The following tool namespaces are no longer available and must not be used:browser".browser); 19 Nov — 17 (14).Workaround I ended up using:
"plugins": ["*", "-opencode.browser"]in the global config. The notices stop (one final removal notice), the attach attempts continue and now return400in ~1 ms each. That only hides the symptom, the reconnect churn is unchanged.Is the rebuild on every session step (as reported in the comments above) still the current design, or is it meant to be kept across steps with the server heartbeat?