Repository navigation
Conversation
|
The following comment was made by an LLM, it may be inaccurate: |
|
@Hona could you take a look at this one? |
There was a problem hiding this comment.
The transport change looks sound. I couldn't reproduce the speedup because it needs the Electron desktop app and a remote server. The new tests in plugin-browser, server and core pass, and all eight changed packages type-check.
I found no security regression on the new route. Origin, authentication, method and input are checked before the connection is upgraded, and the upgrade is lazy, so ownership checks and an unreachable target still fail as normal HTTP errors. The sliding window limits what the receiver buffers, half-close passes through pipe, and TCP errors end the tunnel through raceFirst.
Public API impact:
- Added: HTTP endpoint
GET /api/rpc/:rpcID/:method/socket(rpc.connect, markedx-websocket). - Added: optional
websocket?: trueonRpc.Methodin@opencode/schema/rpc;PortableMethodforbids it. - Changed:
RpcCallContextin the plugin API goes from an interface to a conditional type and gainssocketfor websocket methods. - Added:
connecton coreRpc.Interface. - Changed: typed RPC clients now skip websocket methods.
- Removed:
experimental.browsermethodstunnel.open,tunnel.read,tunnel.writeandtunnel.close, replaced by the websocket methodtunnel. The attach/controlversiongoes from 4 to 5. - Added: a
rpc.connectmethod in the generated promise and effect clients (see the inline comment).
The additions are backwards compatible for existing plugins and SDK users. The browser plugin change is deliberately breaking: a desktop and server on different versions fail when attaching (schema mismatch on version). That seems acceptable for an experimental plugin, but reverse proxies now also have to allow WebSocket upgrades on this route.
Main concern: the generated SDK gets a rpc.connect that can't work (inline).
| ), | ||
| ) | ||
| .add( | ||
| HttpApiEndpoint.get("rpc.connect", "/api/rpc/:rpcID/:method/socket", { |
There was a problem hiding this comment.
This endpoint ends up in the generated clients: both packages/client/src/promise/generated/client.ts and packages/client/src/effect/generated/client.ts now expose rpc.connect as a plain GET with no upgrade, which can't work. pty.connect and persistentPty.connect avoid this through promiseOmitEndpoints / effectOmitEndpoints in packages/protocol/src/client.ts. Could you add rpc.connect there and regenerate, so the SDK doesn't ship a method that is broken?
There was a problem hiding this comment.
Fixed in dbpolito@ecdcee961b: added rpc.connect to both omit lists and regenerated the clients. No replacement HTTP method or extra abstraction. Pre-push lint and all 36 typecheck tasks passed; 53 browser tests and the socket-route test passed. The broader client test files still report three failures outside this RPC surface.
There was a problem hiding this comment.
Thanks, I checked ecdcee961b. rpc.connect is now in both omit lists, and the regenerated promise and effect clients and RpcApi no longer expose the broken connect method. That resolves this thread. The only other new commit is a merge of dev, which doesn't touch the files this PR changes.
|
hi, sorry for bumping this, but i also just stumbled upon this issue. any ETA or blockers? as it seems to involve both client and server upgrade |
|
maybe @Hona could take a look on this one? i didn't look into the conflicts, not sure something changed on upstream regarding this, but i can definitely update this if we're moving forward with it. |
|
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:
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. |

Issue for this PR
No linked issue.
Type of change
Tip
Over a remote connection with ~140 ms RTT, the 6 MiB image test went from ~70 s to ~4 s (roughly 18× faster, using rounded estimates). An uncached load of the OpenCode docs went from 3.91 s to 1.48 s (2.6× faster).
What does this PR do?
I was seeing very slow page loads in the desktop browser when connected to a remote server.
The proxy sends traffic through JSON RPC in chunks of up to 64 KiB, waiting for a response before sending or requesting more. That gets expensive over a high-latency connection, especially for images and JS bundles. The bytes also have to be Base64 encoded.
This replaces those calls with one binary WebSocket per TCP connection. A bounded sliding window controls buffering without waiting for a round trip after every chunk. Browser commands still use RPC.
Authentication, origin checks, attachment ownership, connection limits, and TCP half-close are preserved.
Warning
Desktop and server must be updated together. The old transport is removed, and reverse proxies must allow WebSocket upgrades.
How did you verify your code works?
I tested both versions from the same desktop against the same remote server, with about 140 ms round-trip latency.
The image test loads an uncompressed 6 MiB image with caching disabled:
Load times varied between runs. The ~4 s figure is a rounded estimate, not a calculated average.
I also tested an uncached load of https://opencode.ai/v2/docs, transferring approximately 130 KiB across 6 requests:
These page timings are individual uncached loads, not averaged results.
Tests cover transfers larger than the flow-control window, paused consumers, half-close, cancellation, malformed frames, authentication, and attachment ownership. Pre-push lint and typechecks pass. Four failures in the broader client tests also reproduce on the unchanged base.
To repeat the image test, save the script below as
example.json the remote machine, runnode example.js, and openhttp://localhost:1337in the desktop browser pane. Use matching desktop/server versions for each comparison.The script runs five uncached loads and reports their average.
Reproduction script: example.js
No dependencies or supporting files are needed.
Screenshots / recordings
Before:
After:
Checklist
Added by the opencode bot (AI-generated).
Public API: adds GET /api/rpc/:rpcID/:method/socket and
websocket: trueRPC methods; removes the experimental.browser tunnel.* RPC methods (desktop and server must match)