Skip to content

feat(browser): stream remote browser traffic over multiplexed binary WebSocket (opencode#66217) - #1288

Merged
Hona merged 2 commits into
devfrom
upstream-f/browser-ws-tunnel
Nov 26, 2026
Merged

Hona merged 2 commits into
devfrom
upstream-f/browser-ws-tunnel

Conversation

@Hona

@Hona Hona commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Ports official anomalyco/opencode#66217 (badd3ea1cdbbeaf6e8d7ae73c5866cfb2a1eda0b) so remote browser traffic streams over one prewarmed, multiplexed binary WebSocket with per-origin HTTP/1.1 keep-alive pooling and non-stalling navigation settlement.

Summary

  • Binary stream protocol and multiplexer (crates/opencode-kit/src/client/browser_rpc/):
    • Added versioned 10-byte big-endian binary frame codec (stream_wire.rs, matching packages/plugin-browser/src/stream-wire.ts): OPEN, OPENED, DATA, WINDOW_UPDATE, FIN, RESET, PING, PONG, GOAWAY with strict length/port/host/window/UTF-8 validation and zero base64 encoding.
    • Added ClientMux + MuxStream (stream_mux/{mod,stream,worker}.rs, matching packages/plugin-browser/src/stream-mux.ts): dedicated non-blocking polling::Poller single-writer loop with priority control queue, fair round-robin 16 KiB DATA interleaving capped at 256 KiB WebSocket buffer, 512 KiB receive window with 128 KiB WINDOW_UPDATE batches, bounded per-stream and 8 MiB per-attachment buffer enforcement, 128-stream / 32-pending-connect caps, 25 s / 60 s heartbeats, half-close FIN, immediate RESET on cancel/drop, and clean detach settling every pending opener/reader/writer with a cancellation error.
    • Added authenticated WebSocket upgrade client (tunnel/client.rs, http.rs, types.rs, matching packages/gui-plugins/src/browser/tunnel-client.ts): derives ws:// / wss:// solely from the configured server URL (preserving reverse-proxy base paths), validates path == /api/experimental/browser/tunnel and protocol == 1, passes the single-use upgrade token exclusively in the request header (never query params), enforces verified TLS, and classifies auth/TLS/blocked/protocol/transport errors explicitly without silently downgrading.
    • Added TransportController (tunnel/stream.rs), per-origin plain HTTP/1.1 keep-alive pooling (tunnel/pool.rs, matching packages/plugin-browser/src/proxy.ts), and integrated them into TunnelProxy (tunnel/proxy.rs, tunnel/pump.rs, framing.rs) while preserving loopback 127.0.0.1:0 SO_EXCLUSIVEADDRUSE binding, 384-bit Basic 407 auth, immediate eviction on error/abort/reset/disconnect, and legacy RPC fallback when tunnel.ws.v1 is not advertised or OPENCODE_BROWSER_TUNNEL_TRANSPORT=legacy is set.
  • Desktop RPC and trusted navigation wiring (apps/desktop/src/surfaces/browser/):
    • Decoded attached.capabilities in types.rs / machine.rs (packages/gui-plugins/src/browser/pane-machine.ts), prewarming the binary WebSocket in rpc/tunnel.rs and transferring attachment liveness to StreamActivated / StreamEnded so reverse-proxy idle timeouts on the silent HTTP attach request do not tear down a live WebSocket (packages/gui-plugins/src/browser/pane.ts).
    • Added off-thread experimental.browser/tunnel.grant with a per-origin pending-grant barrier for trusted desktop navigations on remote attachments (surfaces/browser/{mod,openers}.rs, rpc/tunnel.rs), skipped for legacy attachments and agent-driven commands.
  • Navigation progress deadline and replacement tracking (crates/browser-pane/src/client/mod.rs, apps/desktop/src/surfaces/browser/rpc/exec/{settle,nav}.rs):
    • Initialized TabPromptState::document from TabSnapshot::document on new tabs.
    • Implemented navigationProgressDeadline (packages/gui-plugins/src/browser/navigation-deadline.ts): when the 15 s deadline expires on a navigation whose main document already committed while subresources keep streaming, returns the committed tab (loading: true) immediately instead of failing with a timeout; un-committed stalls preserve the timeout error and open tab.
    • Implemented replacementNavigation (packages/gui-plugins/src/browser/navigation-turn.ts, chromium.ts): distinguishes superseded client redirects (ERR_ABORTED while loading or after commit) from genuine no-commit aborts.

Verification

  • CI run 45746653359 on head c1360881ed: green (guardrails, build-macos, build-windows (x64), build-windows (arm64), build-linux (x64); Linux arm64 skipped).
  • Live WAN verification against remote TLS badd3ea1cd server (OPENCODE_FLAGS=browser_stream_tunnel) with the Windows x64 PR build (3/3 passes, exit 0):
    • Binary WebSocket stream (tunnel.ws.v1) on 10 MiB + concurrent live WebSocket /echo probe (http://127.0.0.1:5173/): negotiated GET /api/experimental/browser/tunnel -> HTTP/1.1 101 Switching Protocols with tunnel.grant and 0 legacy tunnel.{open,read,write} RPC calls; completed bytes=10485760 in bulkMs=2883 (2.88 s, 29.1 Mbps) with echoSamples=18, echoMedianMs=115.3 ms.
    • Binary WebSocket stream on Excalidraw SPA (http://127.0.0.1:5174/): whiteboard canvas, toolbar, and fonts rendered whole over the multiplexed binary WebSocket.
    • Legacy RPC comparison (OPENCODE_BROWSER_TUNNEL_TRANSPORT=legacy) on the same 10 MiB + /echo probe: completed bytes=10485760 in bulkMs=31040 (31.04 s, 2.7 Mbps) with echoSamples=298, echoMedianMs=87.9 ms, echoP95Ms=244.4 ms (10.8x faster bulk throughput over binary WebSocket: 31.04 s -> 2.88 s, 2.7 -> 29.1 Mbps).
  • Local guardrails: 9/9 passed (scripts/guardrails.ps1) and bun scripts/web-clock.ts passed (0 violations).

@Hona
Hona marked this pull request as ready for review November 26, 2026 03:58
@Hona
Hona merged commit 655f5ed into dev Nov 26, 2026
7 checks passed
@Hona
Hona deleted the upstream-f/browser-ws-tunnel branch November 26, 2026 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant