Skip to content

fix(model-catalog): keep versioned base URL when fetching model list (#1349)#1363

Open
LeoLin990405 wants to merge 1 commit into
BigPizzaV3:mainfrom
LeoLin990405:fix/model-list-versioned-base-url
Open

fix(model-catalog): keep versioned base URL when fetching model list (#1349)#1363
LeoLin990405 wants to merge 1 commit into
BigPizzaV3:mainfrom
LeoLin990405:fix/model-list-versioned-base-url

Conversation

@LeoLin990405

Copy link
Copy Markdown

问题 / Problem

配置火山引擎 ARK 供应商后,「诊断供应商」失败、「从上游获取模型」报 HTTP 404,但进入 Codex 聊天一切正常(issue #1349)。

根因在 model_catalog.rs::models_endpoint():它只把结尾是 /v1 的 base URL 特判为 <base>/models,其它一律拼 <base>/v1/models。ARK 的 base 形如 .../api/coding/v3(仓库自己的测试 tests/relay_config.rs 也用这个值),于是被拼成:

https://ark.cn-beijing.volces.com/api/coding/v3/v1/models   ← 404(多了一段 /v1)

有意思的是,protocol_proxy.rs 早就用 has_version_suffix() 正确处理了任意 /vN 版本段/v1/v1 还会被折叠),所以实际聊天请求走 proxy 正常——只有客户端这条「拉模型列表」的路径用了这个过时的、只认 /v1 的实现,两边逻辑分叉才导致 404。

models_endpoint() only special-cased base URLs ending in /v1, appending /v1/models to everything else. Providers with a different version segment (Volcano Engine ARK: .../api/coding/v3) got .../api/coding/v3/v1/models → 404 on "fetch models from upstream" and provider doctor, even though chat completions worked. protocol_proxy.rs already handles arbitrary /vN suffixes via has_version_suffix(); only this client-side path diverged.

改动 / Change

  • protocol_proxy::has_version_suffix 由私有提升为 pub(crate)
  • model_catalog::models_endpoint 复用它 —— base 已带版本段(/v1/v3/api/coding/v3 …)时直接追加 /models,否则维持追加 /v1/models/v1 与无版本 base 的现有行为完全不变,只修好了非 /v1 版本段被重复拼 /v1 的 bug。
  • 新增回归测试 model_catalog_appends_models_to_versioned_base_url:用 .../api/coding/v3 base,断言实际请求路径是 /api/coding/v3/models(而非 /api/coding/v3/v1/models)。测试骨架沿用现有 spawn_models_server mock。

Reuse the proxy's already-tested has_version_suffix() so the two code paths agree. /v1 and version-less bases are unchanged.

3 文件 +52/-2

测试 / Testing

⚠️ 透明说明:提交环境未安装 Rust 工具链,我无法在本地跑 cargo test。改动已逐行人工核对(&String&str deref 强转、inline format 捕获、无新 import),且复用的 has_server_suffix 已被 proxy 侧覆盖使用。烦请维护者在合并前跑一次 cargo test -p codex-plus-core --test model_catalog;如需我在有工具链的机器上补跑并回帖也可以。

⚠️ Could not run cargo test locally (no Rust toolchain in the submitting environment). The change is small and manually reviewed; please run cargo test -p codex-plus-core --test model_catalog before merging, or let me know and I'll run it on a machine with the toolchain and report back.

models_endpoint() only special-cased base URLs ending in /v1, so any
provider whose base URL carries a different version segment (e.g. Volcano
Engine ARK's .../api/coding/v3) got /v1/models appended, producing
.../api/coding/v3/v1/models and a 404 on 'fetch models from upstream' and
provider doctor, even though chat completions worked fine.

Reuse the protocol proxy's has_version_suffix() so the client-side model
list fetch matches the version handling the proxy already applies. /v1 and
version-less bases keep their current behavior.

Adds a regression test covering a versioned (.../api/coding/v3) base URL.

Fixes BigPizzaV3#1349
@LeoLin990405

Copy link
Copy Markdown
Author

✅ Update: Rust toolchain now available — verified locally.

cargo test -p codex-plus-core --test model_catalog
running 7 tests
test model_catalog_appends_models_to_versioned_base_url ... ok
...
test result: ok. 7 passed; 0 failed

The new regression test passes and the crate builds clean (only pre-existing dead-code warnings, none from this change). Ready for review. / 已在本机跑通 cargo test,7/7 通过,新回归测试覆盖 ARK .../api/coding/v3 版本段 base。

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.

1 participant