Repository navigation
Closed
Description
What happens
On networks where outbound 443 is only allowed through an HTTP proxy, every model call fails with:
HTTP/2 connect to https://agentn.us.api5.cursor.sh timed out after 15000ms
GetServerConfig and AvailableModels succeed because they use fetch(), which Bun routes through
HTTPS_PROXY. The Run stream is opened with a bare http2.connect(origin) in connectSession()
(src/transport/connect.ts). node:http2 never reads proxy variables, so it dials the agent host
directly and the firewall drops the connection.
Environment
- cursor-opencode-provider 0.6.4 (transport code is identical in 0.7.2)
- OpenCode 1.18.3 (Bun 1.3.14), Linux
HTTPS_PROXY=http://proxy.example.com:3128,NO_PROXY=.corp.example; direct outbound 443 blocked
Steps to reproduce
- On such a network, start OpenCode with
HTTPS_PROXY=http://proxy.example.com:3128. - Pick any
cursor/*model and send a prompt.
Expected: a response. Actual: the timeout above. (Without the proxy variables it already fails earlier withGetServerConfig timed out after 5000ms.)
Suggested fix
When an HTTPS proxy applies to the agent host (https_proxy/HTTPS_PROXY, minusno_proxy/NO_PROXYmatches), open an HTTP CONNECT tunnel inconnectSession()before creating the session, and hand the tunnelled TLS socket tohttp2.connect:
let session: http2.ClientHttp2Session
const proxy = resolveHttpsProxy(host, port) // undefined when NO_PROXY matches
if (proxy) {
const socket = await openConnectTunnel(proxy, host, port) // net.connect + "CONNECT host:443", resolves on 200
session = http2.connect(origin, {
createConnection: () => tls.connect({ socket, servername: host, ALPNProtocols: ["h2"] }),
})
} else {
session = http2.connect(origin)
}Findings from testing this on Bun 1.3.14 (OpenCode's runtime):
- Doing the CONNECT handshake first and then
tls.connect({ socket })on the native proxy socket works: ALPNh2, PING and full Runs go through the tunnel. The existing 15 s connect timer can cover both steps. - Avoid TLS over a custom
Duplex(e.g. returningtls.connect({ socket: someDuplex })from a synchronouscreateConnection). Destroying such a session mid-handshake segfaults Bun 1.3.14, which is exactly what the connect-timeout path does. - Write the CONNECT request by hand over
net.connectrather thanhttp.request({ method: "CONNECT" }); Bun'snode:httpclient only recently gained CONNECT support. - Support credentials in the proxy URL (
http://user:pass@host:port->Proxy-Authorization: Basic ...).
As a workaround we currently wrap http2.connect from a local OpenCode plugin.
Metadata
Metadata
Assignees
Labels
No labels
Activity
oakimov commentedon Sep 24, 2026
Thanks for the clear repro and Bun-safe CONNECT recipe — that diagnosis matches the transport split (unary
fetchvs barehttp2.connect).A fix is implemented on local
main(not pushed yet):src/transport/https-proxy.ts:HTTPS_PROXY/NO_PROXYresolution, manual CONNECT overnet.connect, Basic auth, thentls.connect({ socket, ALPNProtocols: ["h2"] })on the native tunnel socket (no custom Duplex).connectSession()insrc/transport/connect.tsuses that tunnel when a proxy applies; the existing 15s connect timeout covers tunnel + TLS + h2.Proxy-Authorization).Will link the commit/PR here once it’s pushed.
oakimov commentedon Sep 24, 2026
Opened #27 with the CONNECT-tunnel fix: #27
@ThomasFeher if you have a chance, please try that branch (or a build from it) on your proxied network and report back whether Runs get through — details are in the PR test plan. Thanks again!
ThomasFeher commentedon Sep 28, 2026
Thank you for addressing that so quickly! I'll not be able to test it this week, but I'll do so next week, hopefully, and provide feedback then.