Skip to content

feat: 聚合供应商支持按模型路由 - #1780

Open
kokotao wants to merge 8 commits into
BigPizzaV3:mainfrom
kokotao:codex/aggregate-relay-model-routing
Open

feat: 聚合供应商支持按模型路由#1780
kokotao wants to merge 8 commits into
BigPizzaV3:mainfrom
kokotao:codex/aggregate-relay-model-routing

Conversation

@kokotao

@kokotao kokotao commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

概述

  • 新增聚合供应商按模型路由规则,支持通配符匹配与优先级排序
  • 路由命中时直接选择目标成员供应商,未命中才走原有聚合策略
  • 聚合模式下,代理转发前会将上游 model 改写为被选中成员供应商的默认模型
  • 聚合供应商写入 Codex 配置时设置 requires_openai_auth = false
  • 新增管理器 UI 辅助函数与测试,用于聚合路由规则的编辑与校验

详细说明

  • 支持 deepseek-*gpt-* 等通配符模式及精确模型名匹配。
  • 未命中路由时保留原有聚合策略行为。
  • 路由目标无效时跳过并记录 route matched / unmatched / skipped 诊断日志。
  • 选中成员供应商请求失败时,继续按聚合成员顺序 fallback。

修复:聚合供应商不再强制要求 OpenAI 登录

  • 问题:切换到聚合供应商时,Codex 配置此前会写入 requires_openai_auth = true,强制要求聚合中继并不需要的 OpenAI 登录态。
  • 修复:RelayMode::Aggregate 生成的供应商配置现在写入 requires_openai_auth = false,并且 relay_config_status_from_home 会将「base_url + bearer token」的聚合配置视为已配置,无需 OpenAI 登录。
  • 对应测试:relay_config_status_treats_aggregate_provider_as_configured_without_openai_auth

Closes #1744.

测试计划

  • npm test
  • npm run check
  • cargo test -p codex-plus-core --test relay_rotation
  • cargo test -p codex-plus-core --test protocol_proxy aggregate -- --nocapture
  • cargo test -p codex-plus-core --test relay_config
  • cargo test -p codex-plus-core --test relay_switch

…-model-routing

# Conflicts:
#	crates/codex-plus-core/src/relay_config.rs
@kokotao kokotao changed the title feat: route aggregate providers by model feat: 聚合供应商支持按模型路由 Aug 10, 2026
@BigPizzaV3

Copy link
Copy Markdown
Owner

审查结论:暂不建议合并。当前 Windows artifacts CI 失败,失败用例是 upstream_theme_assets 的字节校验:assets/inject/upstream/dream-skin/windows/renderer-inject.jsassets/inject/upstream/skin-packs/packs/caishen-lite/theme.json 的 SHA-256 均不匹配。请先同步/修正资源或对应基线后重新跑全平台 CI,再继续评审。

…-model-routing

# Conflicts:
#	apps/codex-plus-manager/src/App.tsx
#	crates/codex-plus-core/src/protocol_proxy.rs
#	crates/codex-plus-core/src/relay_config.rs
@kokotao

kokotao commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

已同步最新 main(fb3ebd9a)并解决冲突,CI 状态更新:

  • upstream_theme_assets 已通过:同步 main 后资源基线与 SHA-256 校验一致,之前审查指出的 Windows 资源校验问题已消除
  • ✅ 修复了合并引入的编译问题:AggregateRelayProfile 初始化补充 routes 字段(apps/codex-plus-manager/src-tauri/src/commands.rs
  • ❌ 当前 Windows artifacts 唯一失败是 codex-plus-launcherwatchdog_reuses_bridge_context_with_data_serviceapps/codex-plus-launcher/src/main.rs:1135),该失败在上游 main 自身也存在:上游最新提交 fb3ebd9a 的 PR build artifacts 运行(run 31996725033)在同一个测试、同一位置失败(test result: FAILED. 6 passed; 1 failed

即:本次 CI 失败不是本 PR 引入,而是上游 main 当前的问题,需要上游先修复该 launcher 测试(Windows 环境)。

…-model-routing

# Conflicts:
#	apps/codex-plus-manager/src-tauri/tauri.conf.json
#	apps/codex-plus-manager/src/App.tsx
@kokotao

kokotao commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

已再次同步最新 main(c26e511,v1.2.49)并解决冲突,全平台 CI 现已通过 ✅:

  • ✅ Windows artifacts:成功(fix-launcher-watchdog-route 已在上游 main 修复之前失败的 launcher 测试)
  • ✅ macOS DMG (x64):成功
  • ✅ macOS DMG (arm64):成功

PR 当前 mergeablemergeStateStatus = CLEAN,可以继续评审/合并。

@BigPizzaV3 BigPizzaV3 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当前实现仍有一个阻塞性的路由失效路径:

RelayRotationSelector::select_with_outcomes 在调用 match_route_for_aggregate 前先执行 validate_aggregate_members(settings, &self.aggregate)?。因此,只要聚合中的任一成员缺少 relay、base URL 或 API key,选择流程就会直接返回 SelectionError;后续宣称会跳过无效目标的 relay_is_available / RouteMatchInfo::SkippedInvalidRelay 根本没有机会执行。

这会导致一个与 PR 描述相反的行为:某条路由目标失效时,请求不是跳过该规则并继续匹配/回退,而是整个聚合请求失败。请把校验调整到与路由语义一致:路由匹配阶段允许跳过无效目标;最终选中的普通策略成员仍需严格校验。并增加“最高优先级路由目标缺 key,下一条有效路由命中”以及“无有效路由后回退聚合策略”的回归测试。

另外该分支已再次与最新 main 冲突,修复后请 rebase 并重跑三平台 CI。

…-model-routing

# Conflicts:
#	crates/codex-plus-core/src/settings.rs
#	crates/codex-plus-core/tests/relay_rotation.rs
@kokotao

kokotao commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

已按 review 意见修复完成,说明如下:

修复内容

  1. 路由失效路径修复crates/codex-plus-core/src/relay_rotation.rs):

    • from_settings 仅保留「空成员」检查,不再前置全量 validate_aggregate_members
    • select_with_outcomes 在路由匹配阶段跳过无效目标(缺 relay/base URL/API key),继续匹配下一条规则;只有最终通过策略(fallback/weighted)选中的普通策略成员才走 selected_member_relay 严格校验
    • peek / fallback_relays_after 同步调整,fallback 候选只保留有效成员
    • 现在行为与 PR 描述一致:某条路由目标失效时,请求跳过该规则继续匹配/回退,而不是整个聚合请求失败
  2. 回归测试crates/codex-plus-core/tests/relay_rotation.rs)新增 2 条:

    • route_skips_highest_priority_target_missing_key_and_hits_next_valid_route:最高优先级路由目标缺 key,下一条有效路由命中
    • route_all_targets_invalid_falls_back_to_aggregate_strategy:所有路由目标无效时回退聚合策略
    • 本地 relay_rotation 37 个用例全绿
  3. 同步说明:本次采用 merge origin/main(v1.2.50, 140247a)而非 rebase。原因是上游 main 在 AggregateRelayProfile / RelaySessionProvider 等相关文件有较大改动,rebase 产生 5 文件冲突且需逐文件手工重做;merge 已解决全部冲突并保持历史可追溯。

CI 结果

三平台 CI 全部通过(run 32471131089):

  • macOS DMG (arm64) ✅
  • macOS DMG (x64) ✅
  • Windows artifacts ✅

另:8/11 指出的 upstream 主题资源 SHA 问题已被上游 main 修复,当前分支不再涉及。

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.

[Feature]: 聚合供应商支持根据模型来源自动路由到不同供应商

2 participants