502 Bad Gateway Codex 代理接管覆盖 config.toml
Quick fix
关闭全局代理改规则模式直连127.0.0.1,或升级cc-switch避免全量覆盖config.toml。
Symptom
Section titled “Symptom”■ unexpected status 502 Bad Gateway: , url: http://127.0.0.1:15721/v1/responses本页涵盖两个互相关联的根因,它们在不同场景下都会导致 Codex 无法正常通过 CC Switch 本地代理工作。
**根因一:系统全局代理拦截本地回环流量。** 当用户开启 Clash Verge / v2rayU 等代理软件的「全局代理」模式时,所有流量(包括发往 `127.0.0.1` 和 `localhost` 的本地请求)都会被强制路由到代理服务器。由于 CC Switch 的本地代理监听在 `127.0.0.1:15721`,全局代理会导致 Codex 无法直接访问该端口,从而返回 `502 Bad Gateway`。
**根因二:CC Switch 代理接管全量覆盖 config.toml。** 当开启 Codex 本地代理接管(`enableLocalProxy = true`)时,CC Switch 在启动、供应商切换或异常退出恢复时,会使用数据库中保存的供应商模板对 `~/.codex/config.toml` 进行「全量覆盖式」改写,而非增量合并。这会导致用户手动添加的 MCP 服务器配置、`[desktop]` UI 偏好、`[memories]` 记忆设置、`[projects]` 信任级别、`sandbox_mode` 等非供应商相关的个性化配置段被全部丢弃。此外,在异常退出恢复路径中,CC Switch 会从 `proxy_live_backup` 表中读取接管前的整文件快照并原样写回,导致用户在接管期间删除的 MCP 服务器「复活」。
检查代理软件(如 Clash Verge / v2rayU)的代理模式,将「全局代理」改为「规则代理」。
在 Clash Verge / v2rayU 规则配置中添加: # DOMAIN-SUFFIX,localhost,DIRECT# IP-CIDR,127.0.0.0/8,DIRECT确保规则代理中 `127.0.0.1` 和 `localhost` 走直连(DIRECT),不经过代理节点。
如果问题因 CC Switch 重启导致 MCP 或个性化配置丢失,升级 CC Switch 到最新版本。在设置中开启「保留 Codex 官方鉴权」选项,避免 OAuth 登录状态被覆盖。
如果升级后问题仍然存在,作为临时绕过方案,可以手动修改 CC Switch 数据库(`~/.cc-switch/cc-switch.db`)中 `proxy_live_backup` 表的 `original_config` 字段,将缺失的 TOML 段追加进去。
Affected Versions
Section titled “Affected Versions”Source Issues
Section titled “Source Issues”本页汇总自 29 个真实 issue
- #770codex开启代理后报错
- #1423codex 配置问题
- #1755貌似最新版的cc switch设置了codex CLI 配置代理后会劫持桌面codex版本的请求
- #1959默认的config.toml (TOML)格式是不全的......
- #2222[BUG] 正则表达式导致的Codex测试模型在config.toml中不在首行时会被忽略,导致回退到默认模型gpt-5.1-codex
- #3423重启电脑后 Codex 插件全部失效,需要重新安装
- #3447Windows开启路由后模型始终无法生效
- #3895Codex Desktop history temporarily disappears after provider/proxy switch
- #4012bug: stale Codex MCP servers resurrected from provider config and takeover backup
- #4254[Codex] Proxy takeover overwrites entire config.toml, silently destroying all user settings (UI preferences, MCP servers, memories, etc.)
- #4368codex重启会被cc-switch覆盖config.foml文件
- #4371功能请求:用 Codex 官方 profile(增量叠加)机制重构供应商切换,替代易出错的 config.toml 覆盖式改写
- #4423[Bug] Windows v3.16.3 — Codex (no proxy): updating provider model name does not take effect in config.toml
- #4424[Bug] Windows v3.16.3 — Codex (no proxy): updating provider model name does not take effect in config.toml
- #4969[Bug] openai_chat + routing: model catalog generated but Codex desktop doesn't display models
- #4978Mobile Codex Session bypasses CC Switch local proxy (requests not reaching router)
- #5266[回归] v3.16.5 的 NativeResponses 模型目录模板导致推理档位和图片能力退化
- #5276Bug: Save logic strips /v1 from base_url for openai_responses providers, breaking Bailian native Responses
- #5425自动 failover 到 GLM 后产生高度重复输出(gpt-5.6-luna)
- #5743[Bug] Every active Codex provider displays the same fixed API key
- #5886Codex common_config_codex and route backup can be replaced by a partial config while proxy routing is active
- #5974[Bug] 开启 Codex 本地路由后 unifyCodexSessionHistory 对 OpenAI Official 失效:官方路由硬编码 cc-switch-official 桶导致官方/第三方会话历史分裂
- #6017[Bug] 代理接管(异常退出恢复路径)重写 config.toml 时不合并「应用通用配置」,导致 sandbox_mode/web_search 等设置丢失
- #6183Codex config.toml 在启动时被自动热切换覆盖,丢失 [windows] 和 [projects] 段
- #6256[Bug] macOS 上 Codex 直连 wss://api.openai.com 绕过本地路由:需显式设置 transport_kind = responses_http
- #6265[Bug] 开启 Codex 本地代理接管后,重启 CC Switch 会清空 MCP 配置
- #6377[BUG]删除 MCP 服务器后,代理接管备份 (proxy_live_backup) 在退出时将其写回 config.toml,导致删除无效、再次导入时复活
- #6558bug(codex): CLI provider switch rewrites live config.toml from provider blob and drops permission profiles + compaction/reasoning keys
- #6860Config writer strips non-managed [model_providers.*] sections on takeover/switch, breaking old Codex threads
- 关闭了 VPN 还是报错 Reconnecting... 2/5 (8s • esc to interrupt) 怎么办?
- 这通常是本地网络或代理规则残留导致的。尝试将配置中的 `127.0.0.1` 替换为 `localhost`,并确保系统代理已完全关闭且没有残留的代理规则拦截本地回环流量。
- 重启电脑后 Codex 插件全部失效,需要重新安装怎么办?
- 这是因为 CC Switch 在启动时覆盖了 `~/.codex/auth.json`,导致 OAuth 状态被破坏。请升级到最新版(v3.16.4+),并在设置中开启「保留 Codex 官方鉴权」选项。
- 原地编辑供应商的 model 字段后,config.toml 里的 model 没有更新怎么办?
- 这是 v3.16.3 的已知 Bug,原地更新供应商的代码路径漏掉了 `model` 字段的序列化。临时绕过方案是:新建一个供应商(或复制现有的),设置好新的 model 并启用它,新流程会写入完整的 provider block。
- 删除 MCP 服务器后,重启 CC Switch 发现它又回来了怎么办?
- 这是因为删除操作只清理了 `mcp_servers` 表和 live 配置文件,但 `proxy_live_backup` 表中的接管前整文件快照仍包含该服务器。退出 CC Switch 时快照被原样写回 config.toml,导致服务器复活。需要同时清理数据库中的快照记录。
- macOS 上开启本地路由后,Codex 直连 wss://api.openai.com 绕过代理怎么办?
- Codex 的 `transport_kind` 字段默认为 `responses_websocket`,WebSocket 连接会忽略 `base_url` 直连官方端点。需要在 CC Switch 生成的 `config.toml` 中显式设置 `transport_kind = "responses_http"`。
这是一个非官方社区 wiki,与 cc-switch 作者及项目本身无隶属关系。内容整理自项目公开的 GitHub issues。本站不分发任何软件。