Skip to content

HTTP/2 Run stream ignores HTTPS_PROXY / NO_PROXY (connect timeout behind an HTTP proxy) #26

Closed

Description

@ThomasFeher

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
  1. On such a network, start OpenCode with HTTPS_PROXY=http://proxy.example.com:3128.
  2. Pick any cursor/* model and send a prompt.
    Expected: a response. Actual: the timeout above. (Without the proxy variables it already fails earlier with GetServerConfig timed out after 5000ms.)
    Suggested fix
    When an HTTPS proxy applies to the agent host (https_proxy/HTTPS_PROXY, minus no_proxy/NO_PROXY matches), open an HTTP CONNECT tunnel in connectSession() before creating the session, and hand the tunnelled TLS socket to http2.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: ALPN h2, 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. returning tls.connect({ socket: someDuplex }) from a synchronous createConnection). 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.connect rather than http.request({ method: "CONNECT" }); Bun's node:http client 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.

Activity

  1. oakimov commented on Sep 24, 2026

    @oakimov
    Owner

    Thanks for the clear repro and Bun-safe CONNECT recipe — that diagnosis matches the transport split (unary fetch vs bare http2.connect).

    A fix is implemented on local main (not pushed yet):

    • New src/transport/https-proxy.ts: HTTPS_PROXY / NO_PROXY resolution, manual CONNECT over net.connect, Basic auth, then tls.connect({ socket, ALPNProtocols: ["h2"] }) on the native tunnel socket (no custom Duplex).
    • connectSession() in src/transport/connect.ts uses that tunnel when a proxy applies; the existing 15s connect timeout covers tunnel + TLS + h2.
    • Unit tests cover NO_PROXY matching and a local CONNECT fixture (including Proxy-Authorization).

    Will link the commit/PR here once it’s pushed.

  2. oakimov commented on Sep 24, 2026

    @oakimov
    Owner

    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!

  3. ThomasFeher commented on Sep 28, 2026

    @ThomasFeher
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions