ccswitchmulti icon indicating copy to clipboard operation
ccswitchmulti copied to clipboard

[Bug][Codex V2] v3.19.2-10+ authPolicy 迁移遗漏:classify 不识别 v2 route 认证 → 官方 route 401 自锁(PROXY_MANAGED)

Open zhushihao opened this issue 3 months ago • 3 comments

症状

Codex 客户端经 CC Switch MultiRouter 使用第三方/自定义模型(如 gpt-5.6-luna)发消息时 401:

unexpected status 401 Unauthorized: CC Switch local proxy failed while handling Codex endpoint /responses.
Provider: OpenAI Official; model: gpt-5.6-luna;
cause: 认证失败: 已切换到 OpenAI 官方供应商,请重启 Codex 或新建会话以加载官方登录配置

与 #32 / #33 报告的报错一致(这两个 issue 是同一现象,本 issue 给出根因与修复)。

根因(母仓库 cd1e7c4b / v3.19.2-10 引入,迁移遗漏)

cd1e7c4b("resolve MultiRouter v2 from live providers",首发 v3.19.2-10)把 route 的认证声明从 v1 的 upstream.auth.source 迁移到顶层 authPolicy.source。同批迁移中:

  • ✅ codex_route_uses_official_agent_backend(codex.rs:117-139)同步加了 authPolicy/auth_policy 兜底 —— 正常
  • ❌ classify_codex_multirouter_auth_facade(codex.rs:58-90)漏改,仍只读 /upstream/auth/source

v2 schema 保存时根本不写 upstream(实测 DB:v2 route 只有顶层 authPolicy,upstream 为 null),因此 classify 对 v2 route 永远读不到 auth source:

  1. 门面判定漂移:NativeMixed → FullyManaged(判定为"完全托管")
  2. CCSM 重写 live config 时向 ~/.codex/config.toml 注入 experimental_bearer_token = "PROXY_MANAGED" 占位 token
  3. Codex 客户端此后每个请求带 Authorization: Bearer PROXY_MANAGED
  4. 官方 route(native_codex_auth)的校验(forwarder.rs)看到占位 token → 拒绝 → 401

一旦写成 FullyManaged 形态,之后每次重写都因"config 里已有 token"保持该形态 → 自锁,重启 Codex 也无法恢复。

影响面:全仓库 grep /upstream/auth/source,共 4 处运行时逻辑读取 route auth source,仅 codex_route_uses_official_agent_backend 1 处支持 authPolicy,其余 3 处(classify / route_uses_managed_oauth / codex_provider_uses_account_pool / infer_official_target)在 v2 schema 下全部失配。

触发条件

  • DB 里 route 已是 v2 形态(顶层 authPolicy),且
  • 升级到 v3.19.2-10+ 后首次触发 live config 重写(启动 CCSM / 热切换 / SSOT 恢复)

v3.19.2-9 及更早(v1 schema,route 存 upstream.auth)不受影响 —— 这也是为什么降级回 v9 后"正常"。

修复

见 PR #35(b458479b):

  • 新增 pub(crate) fn codex_route_auth_source(codex.rs),按 upstream.auth.source → auth.source → authPolicy.source → auth_policy.source 兜底提取
  • 替换全部 4 处读 route auth source 的运行时逻辑(classify / route_uses_managed_oauth / codex_provider_uses_account_pool / infer_official_target)
  • 补 v1/v2 各形态单元测试 + classify v2 回归测试(6 用例全绿)

临时规避(无需改代码)

手动把 ~/.codex/config.toml 中 codex_model_router_v2 的 experimental_bearer_token = "PROXY_MANAGED" 删除、改回 NativeMixed 形态(保留 requires_openai_auth = true + 真实 OAuth 登录),重启 Codex 可立即恢复;但 CCSM 下次重写 live config 时会再次写坏,根治需合入 PR #35。

zhushihao avatar Aug 23 '26 10:08 zhushihao

@zhushihao 那我就等更新呗 啥时候能合并啊

ufoozhenghao avatar Aug 24 '26 00:08 ufoozhenghao

此 issue 已超过 60 天没有活动,已被标记为 stale。 如果此问题仍然存在,请回复以保持 issue 打开状态,否则将在 14 天后自动关闭。

This issue has been automatically marked as stale because it has not had activity for 60 days. Please reply to keep it open, otherwise it will be automatically closed in 14 days.

github-actions[bot] avatar Oct 23 '26 03:10 github-actions[bot]

此 issue 因长时间无活动已被自动关闭。如果问题仍然存在,欢迎重新打开。

This issue has been automatically closed due to inactivity. If the problem persists, feel free to reopen it.

github-actions[bot] avatar Nov 06 '26 05:11 github-actions[bot]