Codex界面反复显示 正在重新连接 n/5。
Codex 7890 代理与沙盒弹窗处理记录整理时间2026-07-10环境Windows 11Codex 桌面版OpenAI.Codex 26.623.19656.0结论这次问题分两层Codex 模型请求的 websocket 直连会超时界面反复显示正在重新连接 n/5。为了解决重连设置HTTPS_PROXY127.0.0.1:7890后Codex elevated 沙盒又因为代理端口状态不一致反复刷新触发codex-windows-sandbox-setup.exe弹窗。最终处理方式用户级环境变量固定 Codex 主进程代理。Codex 配置里的shell_environment_policy不再把代理变量传给沙盒内 shell 命令。保留[windows] sandbox elevated不降级到unelevated。问题链路1. 初始重连问题本机系统代理为127.0.0.1:7890监听进程为BettboxCore。当 Codex 没有显式代理环境变量时模型流式请求会先尝试wss://chatgpt.com/backend-api/codex/responses该 websocket 路径超时于是出现正在重新连接 1/5 正在重新连接 2/5 ... 正在重新连接 5/55 次失败后Codex 才降级到 httpfalling back to HTTP Request completed methodPOST urlhttps://chatgpt.com/backend-api/codex/responses status200 OK测试确认只给 Codex 进程设置HTTPS_PROXYhttp://127.0.0.1:7890后请求可以直接成功不再等待 5 次重连。2. 后续沙盒弹窗问题设置代理变量后Windows 反复弹出类似错误C:\Program Files\WindowsApps\OpenAI.Codex_26.623.19656.0_x64__2p2nqsd0c76g0\app\resources\codex-windows-sandbox-setup.exe 找不到指定的模块。这个弹窗不是项目代码报错也不是7890端口坏了。沙盒日志位置C:\Users\Zcs\.codex\.sandbox\sandbox.2026-07-09.log日志显示沙盒防火墙允许端口在两个状态之间来回变化sandbox setup required: offline firewall settings changed (stored_ports[], desired_ports[7890]) sandbox setup required: offline firewall settings changed (stored_ports[7890], desired_ports[])含义是Codex 主流程和某些子流程看到的代理变量不一致导致 elevated 沙盒一会儿认为要允许7890一会儿又认为不需要允许代理端口。2026-07-10 复发后重新确认stored_ports[7890], desired_ports[]这说明普通 shell 命令和fs-helper对代理端口的判断仍不一致。继续把HTTPS_PROXY注入给沙盒内 shell 命令会让 elevated 沙盒反复刷新。本次修改1. 用户级环境变量位置HKCU:\Environment当前值HTTPS_PROXYhttp://127.0.0.1:7890 NO_PROXYlocalhost,127.0.0.1,::1未设置HTTP_PROXY ALL_PROXY用途让新启动的 Codex Desktop 主进程显式走127.0.0.1:7890。解决模型 websocket 直连超时导致的n/5重连。2. Codex 沙盒内 shell 环境修改文件C:\Users\Zcs\.codex\config.toml当前配置[shell_environment_policy] exclude [ HTTPS_PROXY, HTTP_PROXY, ALL_PROXY, https_proxy, http_proxy, all_proxy, ] set { NO_PROXY localhost,127.0.0.1,::1 }用途Codex 主进程继续走用户级HTTPS_PROXY。沙盒内 shell 命令不再继承HTTPS_PROXY/HTTP_PROXY/ALL_PROXY。避免 elevated 沙盒因为7890端口状态不一致反复刷新。影响不影响 Codex 聊天、思考、模型请求。可能影响沙盒内命令联网例如pip install、npm install、curl、git clone。如果某条命令必须走代理临时在那条命令里加$env:HTTPS_PROXYhttp://127.0.0.1:7890;要运行的命令3. 保留 elevated 沙盒当前配置仍是[windows] sandbox elevated未切换到[windows] sandbox unelevated未做的事没有修改 Bettbox 配置。没有改 Windows 系统代理。没有改 WinHTTP 代理。没有删除 Codex 沙盒用户。没有删除防火墙规则。没有删除C:\Users\Zcs\.codex\.sandbox。没有重装 Codex。备份修改C:\Users\Zcs\.codex\config.toml前已备份C:\Users\Zcs\.codex\config.toml.bak-20260710-102936 C:\Users\Zcs\.codex\config.toml.bak-20260709-101223验证检查用户级变量Get-ItemProperty-PathHKCU:\Environment|Select-ObjectHTTPS_PROXY,NO_PROXY,HTTP_PROXY,ALL_PROXY检查 Codex 配置Select-String-PathC:\Users\Zcs\.codex\config.toml-Pattern^\[shell_environment_policy\]|HTTPS_PROXY|NO_PROXY|^\[windows\]|sandbox\s*-Context 0,2观察日志时正常情况应看到proxy(http://127.0.0.1:7890/) intercepts https://chatgpt.com/ Request completed methodPOST urlhttps://chatgpt.com/backend-api/codex/responses status200 OK不应继续反复出现stream disconnected - retrying sampling request (1/5 ...) Reconnecting... 2/5 sandbox setup required: offline firewall settings changed (stored_ports[], desired_ports[7890]) sandbox setup required: offline firewall settings changed (stored_ports[7890], desired_ports[]) setup refresh: spawning ... codex-windows-sandbox-setup.exe2026-07-10 验证结果改完后跑一次最小命令C:\Users\Zcs\.codex\.sandbox\sandbox.2026-07-10.log没有新增setup refresh日志最后停在改动前的10:25:36。端口变化时怎么改如果代理端口从7890改成7897只需要改用户级环境变量。用户级环境变量[Environment]::SetEnvironmentVariable(HTTPS_PROXY,http://127.0.0.1:7897,User)[Environment]::SetEnvironmentVariable(NO_PROXY,localhost,127.0.0.1,::1,User)改完后完全退出 Codex Desktop再重新打开。回滚删除用户级环境变量reg delete HKCU\Environment/v HTTPS_PROXY/f reg delete HKCU\Environment/v NO_PROXY/f恢复 Codex 配置前先确认是否要用备份覆盖当前配置C:\Users\Zcs\.codex\config.toml.bak-20260709-101223其他电脑是否适用适用条件也是 Windows。也使用 Codex Desktop。也使用本机代理。代理端口确实是127.0.0.1:7890或能替换成对应端口。问题表现同样是 websocket 先重连http 降级后才成功。不建议无脑照搬的情况代理端口不是7890。Codex 直连本来就正常。公司网络或安全软件限制用户级代理环境变量。迁移到其他电脑时先查端口Get-NetTCPConnection-State Listen|Where-Object{$_.LocalAddress-eq127.0.0.1}|Select-ObjectLocalAddress,LocalPort,OwningProcess再按实际端口设置用户级HTTPS_PROXY。shell_environment_policy不要再固定代理变量保持排除代理变量即可。参考https://developers.openai.com/codex/windows#windows-sandboxhttps://developers.openai.com/codex/config-advanced#shell-environment-policy