Skip to content

fix(openai): 保留账号测试中已配置的模型 / retain configured account test models - #8083

Open
LeeeeeeM wants to merge 1 commit into
Wei-Shaw:mainfrom
LeeeeeeM:codex/fix-account-test-model-list
Open

LeeeeeeM wants to merge 1 commit into
Wei-Shaw:mainfrom
LeeeeeeM:codex/fix-account-test-model-list

Conversation

@LeeeeeeM

Copy link
Copy Markdown
Contributor

Closes #8081
Related: #7017, #7689

中文

问题与原因

OpenAI 兼容账号保存了模型白名单或映射后,如果上游 /models 成功返回的目录没有包含配置目标,账号测试列表会丢失这些配置名称,甚至变成空列表。

projectAccountModelsBody 只保留目标精确存在于上游目录的条目;FetchOpenAIAccountModels 将投影后的空列表作为成功结果返回,因此管理接口的错误回退不会执行。带日期的上游 ID 与 CodingPlan 请求名称不同,是一种复现方式;该问题也影响使用此发现流程的其他 OpenAI 兼容供应商。

本次改动

  • 在 FetchOpenAIAccountModels 中,完成现有目录投影和 OAuth 图片选项补充后,追加尚未展示的显式配置请求名称(model_mapping 的左侧键,包括白名单的同名映射)。
  • 复用已有 ID 集合,避免重复显示,并保留已发现条目的元数据。
  • 补充名称使用请求 ID 作为显示名称,供管理员实际测试。模型出现在列表中不代表上游调用一定成功。
  • 保留现有 OAuth 图片别名处理和 passthrough 行为;遵循已有具体模型 ID 的筛选规则,不扩展通配符语义。

实现集中在测试模型列表服务及其测试,共两个文件。共享上游目录、缓存、公开 /v1/models 投影、管理 handler 和前端不变。

回归覆盖与验证

  • 11 个配置名称都没有出现在上游目录中。
  • 上游与配置部分重叠,多个别名指向同一目标。
  • 上游目录为空但存在显式配置,以及空名称。
  • 已发现条目的元数据保留,补充逻辑不修改共享目录或增加发现请求。
  • 更新已有 OAuth 别名断言,使未发现的显式配置目标也保留其请求名称;现有图片选项和 passthrough 测试仍通过。

以下定向单元测试已通过:

cd backend
go test -tags=unit ./internal/service -run 'Test(FetchOpenAIAccountModels|FetchOpenAIModelsList|ProjectAccountModels|AccountTestService_OpenAI|CodexDirectImages)' -count=1

未逐一验证真实供应商的模型推理调用;本 PR 修复测试列表的展示。


English

Problem and cause

An OpenAI-compatible account can have an explicit model whitelist or mapping, yet lose those choices in the account test picker when a successful upstream /models response omits the configured targets. The picker can become completely empty.

projectAccountModelsBody retains an entry only when its mapped target exactly exists in the upstream catalog. FetchOpenAIAccountModels returns the projected empty list as a successful result, so the admin handler's discovery-error fallback does not run. Dated upstream IDs differing from CodingPlan request names are one reproduction; other OpenAI-compatible providers using this discovery path are affected as well.

Changes

  • After existing catalog projection and OAuth image-choice supplementation, append missing explicitly configured request names in FetchOpenAIAccountModels: the left-hand keys of model_mapping, including identity mappings used by a whitelist.
  • Reuse the existing ID set to prevent duplicate choices and retain metadata on discovered entries.
  • Use the request ID as the display name for added choices so administrators can test them. Picker visibility does not guarantee that an upstream inference request will succeed.
  • Preserve existing OAuth image-alias handling and passthrough behavior. Follow the existing concrete-ID filtering convention without expanding wildcard semantics.

This is a focused alternative addressing the same root cause as #7689. Only the test-picker service and its tests change. The shared upstream catalog/cache, public /v1/models projection, admin handler, and frontend remain unchanged.

Regression coverage and validation

  • All 11 configured names absent from discovery.
  • Partial overlap and multiple aliases sharing a target.
  • An empty upstream catalog with explicit configuration, plus empty names.
  • Existing metadata preserved; picker additions neither mutate the shared catalog nor trigger extra discovery requests.
  • Updated the existing OAuth alias expectation to retain an explicitly configured request name when its target is unlisted. Existing image-choice and passthrough tests continue to pass.

The targeted unit-test command shown above passed.

Live inference was not individually verified for every provider model; this PR fixes account test-picker visibility.

@LeeeeeeM

Copy link
Copy Markdown
Contributor Author

@Wei-Shaw CC

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.

[Bug] 已配置模型在账号测试列表中消失 / Configured models missing from account test picker

1 participant