GeezerVison is showing github.com — desktop browser: preview reloads every ~60s because re-attach disposes tunnels · Issue #62234 · anomalyco/opencode
desktop browser: preview reloads every ~60s because re-attach disposes tunnels #62234DescriptionSummary
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 (
.deb install, resources/app-update.yml channel latest; 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 confirms attached, or make tunnels independent of the attachment and key them by tab instead of connectionID.
- Send periodic keepalive comments on
/api/event (and on browser/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.open tolerate 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. Reacted by Keith Wickramasekara Reacted by Keith Wickramasekara Activityopencodejr commented on 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:
- When a browser attachment is replaced, its tunnels are still disposed. So any re-attach drops the preview page's sockets, including Vite's HMR WebSocket. That matches the reloads and the
tunnel.open 400s you saw.
- The server already sends a heartbeat on
/api/event every 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 commented on 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/event directly against the local service for 100 s and timestamped every line:
21:29:08.591 : heartbeat
21:29:23.584 : heartbeat
21:29:38.585 : heartbeat
21:29:53.586 : heartbeat
21:30:08.586 : heartbeat
21:30:23.586 : heartbeat
21:30:38.587 : heartbeat
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.span in ms (event and attach always close together, same span):
02:25:45.282 api/event span=???
...
02:28:18.734 api/event span=153266 status=200
02:28:18.738 experimental.browser/attach span=153266 status=499
02:28:18.770 api/event span=153304 status=200
02:28:18.773 experimental.browser/attach span=153304 status=499
02:28:19.643 api/event span=153348 status=200
02:28:19.645 experimental.browser/attach span=153348 status=499
02:28:20.999 spawning process command=/bin/bash ... (next session step)
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 git snapshot 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, attach runs c(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 at localhost: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 commented on 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, same http://localhost:5176 preview):
[20:04:51.687] [debug] [vite] connected.
[20:05:27.427] [info] [vite] server connection lost. Polling for restart...
[20:05:29.167] [debug] [vite] connected.
[20:06:27.731] [info] [vite] server connection lost. Polling for restart...
[20:06:29.453] [debug] [vite] connected.
[20:07:29.226] [info] [vite] server connection lost. Polling for restart...
[20:07:30.928] [debug] [vite] connected.
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 lost per 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 commented on 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 concurrent browser/attach streams, all ending within ~150 ms of each other, each with a matching api/event closing <5 ms before it:
15:03:36.839 browser/attach 499 span=60288
15:03:36.843 browser/attach 499 span=60297
15:03:36.854 browser/attach 499 span=60285
15:03:36.906 browser/attach 499 span=60329
15:03:36.942 browser/attach 499 span=60360
15:03:36.969 browser/attach 499 span=60405
15:04:37.090 browser/attach 499 span=58962
15:04:37.094 ... span=58960 15:04:37.097 ... span=58949
15:04:37.152 ... span=59211 15:04:37.182 ... span=59015 15:04:37.184 ... span=59023
15:05:37.620 ... span=59364 15:05:37.624 ... span=59359
15:05:37.735 ... span=59529 15:05:37.757 ... span=59494
15:05:37.759 ... span=59490 15:05:37.762 ... span=59502
15:07:40.544 ... span=121874 (+5 more, spans 121729–121746)
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:
grep -c 'browser/attach' opencode.log -> 3623 (3621 x 499, 2 x 400)
grep -c 'browser/tunnel.open' opencode.log -> 1451 (1451 x 400, i.e. 100%)
tunnel.open spans are 0–5 ms, so as reported they fail before any socket attempt. There are no http_proxy/https_proxy variables set on this machine (only no_proxy for 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 just dev:
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"); ...
tunnels: YF() // fresh tunnel map per attachment
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 localhost targets too. Ollegio commented on 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 local peon-ping.ts, superpowers, opencode-websearch-deepseek.
Server log (~/.local/share/opencode/log/opencode.log, UTC):
- 2026-11-23 alone: 257
POST /api/rpc/experimental.browser/attach responses. Over the whole log, at an earlier count: 1 212 requests, 1 134 499 and 78 400.
- Every
499 on attach ends in the same millisecond as a GET /api/event 200, i.e. both streams are rebuilt together, as you describe:
2026-11-23T18:36:39.239Z ... http.method=GET http.url=/api/event http.status=200
2026-11-23T18:36:39.242Z ... http.method=POST http.url=/api/rpc/experimental.browser/attach http.status=499
2026-11-23T18:36:39.244Z ... http.method=GET http.url=/api/event http.status=200
2026-11-23T18:36:39.245Z ... http.method=POST http.url=/api/rpc/experimental.browser/attach http.status=499
- Bursts are concurrent, not one stream:
18:36:15.020 has two attaches ending in the same millisecond with http.span=17950 and 17954; a later burst has six attaches closing within ~150 ms of each other.
- Attach lifetime spread over the log:
p50 = 3.3 s, p90 = 48.7 s, max = 14 752 s.
What this does to the session: each attach/detach pair flips the browser namespace in the Code Mode catalog, and every flip appends a system message to the session.
- 151 such notices in the DB, 69 mention
browser, 30 are "browser no longer available".
- Pairs, same session, 5–40 s apart:
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.
- The detach notice follows the cancelled attach within ~80 ms:
18:34:06.391 attach 499 + /api/event 200 → 18:34:06.472 "The following tool namespaces are no longer available and must not be used: browser".
- Daily counts: 23 Nov — 51 notices (49 about
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 return 400 in ~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?
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|