Skip to content

fix(remote-control): honor HTTP proxies for WebSocket connections - #5037

Merged
sailist merged 2 commits into
mainfrom
bug-387-websocket-proxy-main
Nov 18, 2026
Merged

sailist merged 2 commits into
mainfrom
bug-387-websocket-proxy-main

Conversation

@sailist

@sailist sailist commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Users behind a corporate HTTP proxy cannot establish a Remote Control tunnel: the relay WebSocket connection ignores the HTTP_PROXY / HTTPS_PROXY / NO_PROXY environment variables and always dials the relay directly. This is a re-submission of #5004 (targeting release/2026-11-16) against main.

Bug Reproduction Steps

  1. Set HTTP_PROXY/HTTPS_PROXY to a working proxy and unset direct egress.
  2. Run kimi remote-control (or any flow that opens the relay tunnel).
  3. The WebSocket registration handshake never reaches the relay because it bypasses the configured proxy.

Root Cause

connectWebSocket in packages/remote-control/src/remote-control.ts constructs ws.WebSocket without an agent, so the connection always goes direct even when proxy env vars are set. Fundamental fix, not a workaround: the relay connection now honors the same proxy resolution (HTTP_PROXY/HTTPS_PROXY/ALL_PROXY/NO_PROXY) that other HTTP traffic in the codebase already uses.

Code Changes

  • packages/agent-core-v2/src/_base/utils/proxy.ts: export the existing resolveHttpProxyUrls helper so the remote-control package can reuse the same env-var resolution.
  • packages/remote-control/src/remote-control.ts: build one proxy agent per relay origin (createRelayProxyAgent) — resolves NO_PROXY first and skips proxying for matched hosts, picks httpsProxy/httpProxy by relay scheme, and falls back to a direct connection (with a stderr warning) when the proxy URL is invalid. The agent is threaded through both WebSocket handshake attempts (subprotocol-token and Authorization-header variants).
  • packages/remote-control/package.json: add https-proxy-agent dependency (already used elsewhere in the repo).
  • Test: the existing auth-relay end-to-end case now dials through a local CONNECT proxy and asserts both handshakes arrive via the proxy, covering the NO_PROXY-bypass-aware path.

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
Relay WebSocket honors HTTP_PROXY/HTTPS_PROXY/ALL_PROXY Always direct Proxied unless NO_PROXY matches Users who set proxy vars globally but wanted remote-control direct Add the relay host to NO_PROXY
Invalid proxy URL N/A (ignored) Warns on stderr, connects directly — Fix or unset the proxy var

Affected: remote-control tunnel connections only; all other HTTP traffic already behaved this way. Covered by the updated end-to-end case in packages/remote-control/test/remote-control.test.ts.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset. (changeset included)
  • Ran gen-docs skill, or this PR needs no doc update.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T05:12:13.004870Z 37f8448 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 18, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@37f8448
npx https://pkg.pr.new/@moonshot-ai/kimi-code@37f8448

commit: 37f8448

@sailist
sailist merged commit 3a05a7e into main Nov 18, 2026
17 checks passed
@sailist
sailist deleted the bug-387-websocket-proxy-main branch November 18, 2026 07:21
@github-actions github-actions Bot mentioned this pull request Nov 19, 2026
devin-ai-integration Bot added a commit to 7723qqq/kimi-code that referenced this pull request Nov 24, 2026
Port upstream MoonshotAI#5037: resolve HTTP_PROXY/HTTPS_PROXY/NO_PROXY for the
relay connection and tunnel the WebSocket through an HttpsProxyAgent,
keeping the loopback bypass from resolveNoProxy. Invalid proxy values
fall back to a direct connection with a stderr note.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
devin-ai-integration Bot added a commit to 7723qqq/kimi-code that referenced this pull request Nov 24, 2026
…end drift-allow

- bun scripts/upstream-ledger.mjs --refresh: 148 new pending rows covering
  the 2.7.0 tail and upstream/main.
- Mark MoonshotAI#5043/MoonshotAI#5037/MoonshotAI#5049 ported (26f22db, 0d20273, d61aacc) and
  MoonshotAI#5042 equivalent (multiline feedback editor already shipped, localized).
- Refresh MoonshotAI#4820 evidence: the machine-architecture blocker retired with the
  2.7.0 merge.
- drift-allow: add the missing translated/renamed upstream files (media.ts,
  node-local hostServices/rgLocator/runRg, executor validate.ts, remaining
  vitest configs) so upstream-drift stops flagging deliberate removals.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

2 participants