Skip to content

[BUG] Codex requests continuously return 502 Bad Gateway after ocx service install in Windows 10 + WSL #2107

Description

@phd-csy

Client or integration

Codex CLI

Area

CLI

Summary

After running ocx service install in a Windows 10 + WSL environment, Codex requests continuously return 502 Bad Gateway and the Codex client repeatedly reconnects.

Environment

This issue occurs on Windows 10 when OpenCodex and Codex run inside WSL.

  • Host operating system: Windows 10
  • Runtime environment: Linux inside WSL
  • Repository: https://github.com/lidge-jun/opencodex
  • OpenCodex version: 2.26.0
  • Service manager: systemd user service inside WSL
  • Local proxy endpoint:
http://<LOOPBACK_HOST>:<OPENCODEX_PORT>/v1
  • Provider: OpenAI / ChatGPT Codex backend

WSL Proxy Configuration

The Windows host runs a local proxy on <PROXY_PORT>. The proxy environment variables are configured inside WSL using the Windows host address obtained from the WSL default route.

The following configuration is used in WSL:

WIN_HOST=$(ip route | awk '/default/ {print $3; exit}')
PROXY_PORT="<PROXY_PORT>"
LOOPBACK_V4="<LOOPBACK_IP_V4>"
LOOPBACK_V6="<LOOPBACK_IP_V6>"
WILDCARD_IP="<WILDCARD_IP>"

export HTTP_PROXY="http://${WIN_HOST}:${PROXY_PORT}"
export HTTPS_PROXY="http://${WIN_HOST}:${PROXY_PORT}"
export ALL_PROXY="socks5h://${WIN_HOST}:${PROXY_PORT}"
export NO_PROXY="localhost,${LOOPBACK_V4},${LOOPBACK_V6},${WILDCARD_IP},${WIN_HOST}"

export http_proxy="$HTTP_PROXY"
export https_proxy="$HTTPS_PROXY"
export all_proxy="$ALL_PROXY"
export no_proxy="$NO_PROXY"

The configuration is persisted in the WSL shell startup file:

# ~/.bashrc

WIN_HOST=$(ip route | awk '/default/ {print $3; exit}')
PROXY_PORT="<PROXY_PORT>"
LOOPBACK_V4="<LOOPBACK_IP_V4>"
LOOPBACK_V6="<LOOPBACK_IP_V6>"
WILDCARD_IP="<WILDCARD_IP>"

export HTTP_PROXY="http://${WIN_HOST}:${PROXY_PORT}"
export HTTPS_PROXY="http://${WIN_HOST}:${PROXY_PORT}"
export ALL_PROXY="socks5h://${WIN_HOST}:${PROXY_PORT}"
export NO_PROXY="localhost,${LOOPBACK_V4},${LOOPBACK_V6},${WILDCARD_IP},${WIN_HOST}"

export http_proxy="$HTTP_PROXY"
export https_proxy="$HTTPS_PROXY"
export all_proxy="$ALL_PROXY"
export no_proxy="$NO_PROXY"

Reproduction Steps

  1. Start Windows 10 and open the WSL distribution.
  2. Configure the proxy environment variables inside WSL.
  3. Install and configure OpenCodex inside WSL.
  4. Run:
ocx service install
  1. Start a conversation with GPT through Codex.

Actual Result

The Codex interface continuously displays:

Reconnecting... 2/5 (19s • esc to interrupt)

The request then fails with:

Unexpected status 502 Bad Gateway:
Provider unreachable:
The socket connection was closed unexpectedly.
For more information, pass `verbose: true` in the second argument to fetch(),
url: http://<LOOPBACK_HOST>:<OPENCODEX_PORT>/v1/responses

The OpenCodex log contains:

[upstream-retry] connection reset (<UPSTREAM_HOST>) — retrying

The request record contains:

{
  "provider": "openai",
  "status": 502,
  "recoveryKinds": ["connection-reset"]
}

Comparison

In the same Windows 10 + WSL environment, run:

ocx service uninstall

Then install the Codex shim:


After installing the Codex shim, conversations with GPT through Codex complete successfully. The following errors do not occur:

```text
502 Bad Gateway
connection reset (<UPSTREAM_HOST>)
The socket connection was closed unexpectedly

Expected Result

After running ocx service install in the Windows 10 + WSL environment, conversations with GPT through Codex should complete successfully, with behavior consistent with ocx codex-shim install.


环境

该问题发生在 Windows 10 系统中,OpenCodex 和 Codex 运行在 WSL 环境内。

  • 主机操作系统:Windows 10
  • 运行环境:WSL 中的 Linux
  • Repository: https://github.com/lidge-jun/opencodex
  • OpenCodex version: 2.26.0
  • 服务管理器:WSL 中的 systemd user service
  • 本地代理端点:
http://<LOOPBACK_HOST>:<OPENCODEX_PORT>/v1
  • Provider:OpenAI / ChatGPT Codex backend

WSL 中的代理配置

Windows 主机上的本地代理监听 <PROXY_PORT> 端口。WSL 中通过默认路由获取 Windows 主机地址,并设置代理环境变量。

WSL 中使用以下配置:

WIN_HOST=$(ip route | awk '/default/ {print $3; exit}')
PROXY_PORT="<PROXY_PORT>"
LOOPBACK_V4="<LOOPBACK_IP_V4>"
LOOPBACK_V6="<LOOPBACK_IP_V6>"
WILDCARD_IP="<WILDCARD_IP>"

export HTTP_PROXY="http://${WIN_HOST}:${PROXY_PORT}"
export HTTPS_PROXY="http://${WIN_HOST}:${PROXY_PORT}"
export ALL_PROXY="socks5h://${WIN_HOST}:${PROXY_PORT}"
export NO_PROXY="localhost,${LOOPBACK_V4},${LOOPBACK_V6},${WILDCARD_IP},${WIN_HOST}"

export http_proxy="$HTTP_PROXY"
export https_proxy="$HTTPS_PROXY"
export all_proxy="$ALL_PROXY"
export no_proxy="$NO_PROXY"

配置持久化在 WSL 的 shell 启动文件中:

# ~/.bashrc

WIN_HOST=$(ip route | awk '/default/ {print $3; exit}')
PROXY_PORT="<PROXY_PORT>"
LOOPBACK_V4="<LOOPBACK_IP_V4>"
LOOPBACK_V6="<LOOPBACK_IP_V6>"
WILDCARD_IP="<WILDCARD_IP>"

export HTTP_PROXY="http://${WIN_HOST}:${PROXY_PORT}"
export HTTPS_PROXY="http://${WIN_HOST}:${PROXY_PORT}"
export ALL_PROXY="socks5h://${WIN_HOST}:${PROXY_PORT}"
export NO_PROXY="localhost,${LOOPBACK_V4},${LOOPBACK_V6},${WILDCARD_IP},${WIN_HOST}"

export http_proxy="$HTTP_PROXY"
export https_proxy="$HTTPS_PROXY"
export all_proxy="$ALL_PROXY"
export no_proxy="$NO_PROXY"

复现步骤

  1. 启动 Windows 10,并进入 WSL。
  2. 在 WSL 中配置代理环境变量。
  3. 在 WSL 中安装并配置 OpenCodex。
  4. 执行:
ocx service install
  1. 通过 Codex 与 GPT 开始对话。

实际结果

Codex 界面持续显示:

Reconnecting... 2/5 (19s • esc to interrupt)

随后请求失败,并显示:

Unexpected status 502 Bad Gateway:
Provider unreachable:
The socket connection was closed unexpectedly.
For more information, pass `verbose: true` in the second argument to fetch(),
url: http://<LOOPBACK_HOST>:<OPENCODEX_PORT>/v1/responses

OpenCodex 日志中出现:

[upstream-retry] connection reset (<UPSTREAM_HOST>) — retrying

请求记录中出现:

{
  "provider": "openai",
  "status": 502,
  "recoveryKinds": ["connection-reset"]
}

对比结果

在相同的 Windows 10 + WSL 环境中执行:

ocx service uninstall

随后安装 Codex shim:

ocx codex-shim install

安装 Codex shim 后,通过 Codex 与 GPT 对话可以正常完成。以下错误不再出现:

502 Bad Gateway
connection reset (<UPSTREAM_HOST>)
The socket connection was closed unexpectedly

预期结果

在 Windows 10 + WSL 环境执行 ocx service install 后,通过 Codex 与 GPT 对话应当能够正常完成,行为应当与执行 ocx codex-shim install 时一致。

Reproduction

  1. Start Windows 10 and open the WSL distribution.
  2. Configure the proxy environment variables inside WSL.
  3. Install and configure OpenCodex inside WSL.
  4. Run:
ocx service install
  1. Start a conversation with GPT through Codex.

Version

2.26.0

Operating system

Windows 10 22H2, WSL2 2.7.12.0

Provider and model

openai/gpt-5.6-luna

Logs or error output

Screenshots and supporting files

No response

Redacted configuration

Checks

  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Activity

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

    bugSomething isn't workingcliCLI, config inject, packaging flagsplatformOS/service/tray/ACL (Windows-heavy, not Windows-only)serviceService lifecycle (WinSW/launchd/scheduler)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions