Skip to content

fix(middleware): 隐藏无可用渠道错误中的任务插件标识 - #7414

Merged
Calcium-Ion merged 2 commits into
QuantumNous:mainfrom
blackdm666:codex/hide-plugin-routing-errors
Sep 17, 2026
Merged

Calcium-Ion merged 2 commits into
QuantumNous:mainfrom
blackdm666:codex/hide-plugin-routing-errors

Conversation

@blackdm666

@blackdm666 blackdm666 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Agent

  • Tool: Codex。本 PR 的代码和说明由 AI 辅助编写。
  • Tool version: 当前会话未提供桌面应用版本号。
  • Model (full id): GPT-6;当前会话未提供更完整的模型标识。
  • Host (CLI / IDE / GitHub coding agent / other): Codex 桌面应用,Windows。
  • Date (UTC): 2026-09-16。

Links

  • Closes: 无对应 Issue;这是根据用户实际错误截图、官方源码和本地回归复现提交的聚焦修复。
  • Related: 官方基线 69a50029819a26c53e6babd276d49cfe2f8880ad。

User request

用户发现“无可用渠道”错误将任务插件标识返回给调用者,并指出:“那插件名字就不能写我的渠道名了,直接就暴露给用户了呀”。随后要求:“你把这个提交一个PR,用中文,按仓库格式提交。”用户已明确选择提交到官方仓库。

Out of scope — refuse

  • Matched: no。
  • If yes, what was told to the user (stop here; do not open a PR): 不适用。本改动修复官方渠道分发中间件自身的错误信息披露,可通过合成插件独立复现;不新增或修改第三方服务适配、不涉及 Coding Plan、逆向渠道、Codex 渠道或第三方站点定制。

Kind

  • Bug fix
  • New feature
  • Performance / refactor
  • Docs
  • Other:

Issue facts

  • Actual behavior: 模型已被任务插件认领、当前请求没有可用渠道时,HTTP 503 的 error.message 包含插件 meta.key、内部组名,以及在管理控制台停用或覆盖插件的操作建议。多个插件共享模型时,还会列出全部候选插件标识。
  • Impact: 普通 API 调用者可以从失败响应获知内部提供商标识和路由配置;插件标识包含供应商名称时,会直接暴露相关信息。
  • Frequency: 用户提供了一次实际错误截图,未提供线上统计;本地旧代码的 6 个回归场景(三种语言 × 单/多插件)均稳定复现。
  • Evidence that the problem is in new-api rather than the client or upstream: middleware/distributor.go 的 noAvailableChannelMessage() 将插件标识传入后端翻译模板,随后由 abortWithOpenAiMessage() 返回给调用者。测试直接执行 Distribute(),没有调用客户端或上游服务即可复现。
  • Applicable types and their fields (relay / billing / frontend / deployment; write "not applicable" otherwise): 适用 relay:渠道选择失败响应的 error.message。保留 HTTP 503、new_api_error、model_not_found 及请求 ID。billing、frontend、deployment 不适用,本 PR 不改动这些路径。

Change

任务插件没有可用渠道时,对外统一返回本地化的通用提示;简体中文为“当前模型暂无可用渠道,请稍后重试或联系客服。”,请求 ID 继续由原有错误响应流程附加。

插件标识、分组和模型转入服务端告警日志,记录 event=no_available_channel 与 reason=no_eligible_channel,并由现有日志器关联请求 ID。共享模型仍保留全部候选插件,管理员可以据此排查。日志字段使用 %q 引用,避免直接拼接未经引用的字段。

Research

Duplicate / prior art

  • Search queries (issues, PRs): 在 QuantumNous/new-api 检索 "no available channel" "plugin"、"distributor" "plugin"、"no_available_channel_task_plugin"、"plugin" "error"、"plugin" "expose"、"插件" "泄露"、"noAvailableChannelMessage"。
  • What already existed and why this is not a duplicate: 未找到针对该错误提示泄露插件标识的修复;搜索返回的 refactor: clean tests #7270 为测试整理。官方当前实现和已有测试仍明确要求公开插件标识,本 PR 将该断言改为响应保密、日志保留诊断信息。

Docs and code

  • https://docs.newapi.ai/ : 已打开官方文档首页及使用指南首页;其管理入口说明不能解决后端固定拼接插件标识的问题,最终行为依据官方源码及 HTTP 回归确认。
  • https://deepwiki.com/QuantumNous/new-api : 已阅读 渠道选择与负载均衡 和 错误处理与类型,核对分发层职责和既有错误封装;Wiki 索引不是当前提交,具体实现以本 PR 基线为准。
  • README / repo docs: 已阅读 README 项目定位、AGENTS.md、docs/plugin-api/v1.md 和本 PR 模板;改动位于宿主错误提示,不更改插件 API、元数据或协议。
  • Code paths and what they imply for this change: middleware/distributor.go 生成可用渠道错误;middleware/utils.go 保持错误码、状态码与请求 ID;logger/logger.go 提供带请求 ID 的服务端日志;三份后端语言文件包含原始泄露文案。

Alternatives considered

  • Option A: 要求部署者给插件改名,只能降低可识别程度,仍会公开内部标识和管理操作提示。
  • Option B: 只删除详细提示而不增加诊断日志,会丢失管理员排查共享插件和分组配置的线索。
  • Why this approach: 在现有错误生成位置分离公开提示与服务端诊断,改动范围小,保留错误响应协议和排查能力。

Files

Path Why
middleware/distributor.go 插件分发细节写入服务端日志,对外返回通用提示。
middleware/distributor_test.go 通过实际 Gin 分发链路覆盖三语言、单/多插件、请求 ID、日志及无插件回退行为。
i18n/locales/en.yaml 英文通用提示。
i18n/locales/zh-CN.yaml 简体中文通用提示。
i18n/locales/zh-TW.yaml 繁体中文通用提示。

Behavior

  • Before: 503 响应正文包含 private-provider-alpha、内部组名以及停用或覆盖插件的建议;共享模型还会暴露其他候选插件。
  • After: 503 响应正文只包含本地化通用提示与请求 ID;内部诊断保留在同一请求 ID 对应的服务端日志中。
  • Explicit non-goals / leftover work: 仅处理任务插件“无可用渠道”这一错误分支;不改插件认领、渠道选择、重试、普通非插件报错、插件校验错误、计费、鉴权或数据库,不部署生产环境。

Verification

  • Commands and results:
    • 先仅加入回归测试,执行 go test ./middleware -run '^TestDistributeHidesTaskPluginDetailsButLogsDiagnostics$' -count=1:旧代码 6 个场景失败,失败响应包含内部标识;应用修复后同一命令通过。
    • go test ./middleware ./i18n ./pkg/jsplugin ./relay/channel/task/jsplugin ./relay:通过;i18n 没有独立测试文件,三语言翻译由 middleware 回归实际加载并验证。
    • go vet ./middleware ./i18n:通过。
    • gofmt 与 git diff --check:通过。
  • Manual steps and observed result: 检查官方错误生成代码、请求 ID 注入和日志代码;HTTP 行为通过 httptest 驱动真实 RequestId()、Distribute() 和错误封装验证,未发付费上游请求。
  • UI: screenshot or recording (or why none): 无 UI 改动;使用合成插件复现,未上传含部署内部标识的用户截图。
  • Tests added or updated, or why none: 将原来要求公开插件名的测试替换为实际 HTTP 响应与日志回归;验证精确 JSON、HTTP 503、model_not_found、请求 ID、全部候选插件的服务端日志,以及不可继续进入 relay handler。保留无插件回退测试;共享插件重绑定测试不再断言对外公开插件名。
  • Databases / providers / platforms exercised: Windows amd64、Go 1.26.5;新回归使用内存渠道缓存和本地合成插件,不依赖数据库或外部提供商。上述已有包测试均实际运行。
  • Not verified: 未执行生产部署、真实上游生成、浏览器验收、全仓测试或数据库兼容性矩阵;本改动不涉及数据库或前端。

Risks

  • Failure modes: 若客户端依赖旧错误文案进行字符串匹配,需要改用保持不变的错误码;服务端会新增一条告警日志。
  • Billing / quota / auth impact: 无相关代码改动,仍在未能选出渠道时终止请求。
  • Follow-ups: 合并发布后,用无可用渠道请求复盘公开响应与对应请求 ID 的服务端日志,确认调用者不再看到插件标识。

Scope check

  • Single focused change: yes,任务插件无可用渠道错误的信息披露修复。
  • Secrets included: no。
  • Out of scope (Coding Plan / reverse-engineered channel / third-party wrapper / Codex): no。

Summary by CodeRabbit

  • Bug Fixes
    • Improved “no available channel” error messages across English and Chinese locales.
    • User-facing responses no longer expose task-plugin provider names or administrative disable/override instructions.
    • Error messages continue to identify the affected group and model and explain that no enabled channel is available.
    • Detailed provider information remains available in diagnostic logs for troubleshooting, including the request context and failure reason.

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 395cbc47-16e9-4747-9330-6449ffc68384

📥 Commits

Reviewing files that changed from the base of the PR and between 535b9e4 and d323fc0.

📒 Files selected for processing (5)
  • i18n/locales/en.yaml
  • i18n/locales/zh-CN.yaml
  • i18n/locales/zh-TW.yaml
  • middleware/distributor.go
  • middleware/distributor_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • i18n/locales/zh-CN.yaml
  • i18n/locales/en.yaml
  • i18n/locales/zh-TW.yaml

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

Task-plugin routing details are removed from public 503 messages. The distributor now records those details in server logs. English, Simplified Chinese, and Traditional Chinese messages and distributor tests were updated.

Changes

Task-plugin diagnostics

Layer / File(s) Summary
Hide routing details and retain diagnostics
middleware/distributor.go, middleware/distributor_test.go, i18n/locales/*.yaml
The distributor logs group, model, plugin keys, request ID, and the no-eligible-channel reason. Localized client messages no longer expose plugin keys or disable/override guidance. Tests verify redaction and diagnostic logging across locales and provider counts.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: calcium-ion

Merge Risk: ⚪ Minimal · up to d323f

Plugin routing keys are removed from public 503 responses while server diagnostics retain them for request-ID-based troubleshooting. No current merge-blocking risk is identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (3 skipped: 3… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: hide task-plugin identifiers from no-available-channel errors in the middleware. It is specific, concise, and aligned with the pull request objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (3 skipped: 3 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit reads each line,
The patch grows clear beneath the moon,
Small changes hop in place,
Tests guard the garden path,
Reviews bloom before the dawn.

Comment @coderabbitai help to get the list of available commands.

@Calcium-Ion
Calcium-Ion marked this pull request as ready for review September 17, 2026 09:31
@Calcium-Ion

Copy link
Copy Markdown
Member

这样诊断信息就太少了,连是不是插件都无法知道

@seefs001 seefs001 closed this Sep 17, 2026
@Calcium-Ion Calcium-Ion reopened this Sep 17, 2026
… plugin keys

The fully generic message from QuantumNous#7414 left callers and operators unable to
tell whether a task plugin was involved at all. Restore the group, model and
plugin-claimed wording in the 503 body, but keep the plugin keys and the
admin fix hint out of it; the candidate plugin keys stay in the warn log
under the request id so operators can correlate.
@Calcium-Ion
Calcium-Ion merged commit 7209b6d into QuantumNous:main Sep 17, 2026
1 check was pending
chunfeng789 added a commit to chunfeng789/new-api that referenced this pull request Sep 17, 2026
* fix(middleware): 隐藏无可用渠道错误中的任务插件标识

* fix(middleware): keep task-plugin context in no-channel error without plugin keys

The fully generic message from QuantumNous#7414 left callers and operators unable to
tell whether a task plugin was involved at all. Restore the group, model and
plugin-claimed wording in the 503 body, but keep the plugin keys and the
admin fix hint out of it; the candidate plugin keys stay in the warn log
under the request id so operators can correlate.

---------

Co-authored-by: 老黑 <67053678+blackdm666@users.noreply.github.com>
Co-authored-by: CaIon <i@caion.me>
Javabcd pushed a commit to Javabcd/new-api that referenced this pull request Sep 22, 2026
* fix(middleware): 隐藏无可用渠道错误中的任务插件标识

* fix(middleware): keep task-plugin context in no-channel error without plugin keys

The fully generic message from QuantumNous#7414 left callers and operators unable to
tell whether a task plugin was involved at all. Restore the group, model and
plugin-claimed wording in the 503 body, but keep the plugin keys and the
admin fix hint out of it; the candidate plugin keys stay in the warn log
under the request id so operators can correlate.

---------
Co-authored-by: CaIon <i@caion.me>
GuDong2003 pushed a commit to GuDong2003/new-api that referenced this pull request Sep 25, 2026
* fix(middleware): 隐藏无可用渠道错误中的任务插件标识

* fix(middleware): keep task-plugin context in no-channel error without plugin keys

The fully generic message from QuantumNous#7414 left callers and operators unable to
tell whether a task plugin was involved at all. Restore the group, model and
plugin-claimed wording in the 503 body, but keep the plugin keys and the
admin fix hint out of it; the candidate plugin keys stay in the warn log
under the request id so operators can correlate.

---------
Co-authored-by: CaIon <i@caion.me>
TomJKS pushed a commit to TomJKS/new-api that referenced this pull request Sep 28, 2026
* fix(middleware): 隐藏无可用渠道错误中的任务插件标识

* fix(middleware): keep task-plugin context in no-channel error without plugin keys

The fully generic message from QuantumNous#7414 left callers and operators unable to
tell whether a task plugin was involved at all. Restore the group, model and
plugin-claimed wording in the 503 body, but keep the plugin keys and the
admin fix hint out of it; the candidate plugin keys stay in the warn log
under the request id so operators can correlate.

---------
Co-authored-by: CaIon <i@caion.me>
timwenx pushed a commit to timwenx/new-api that referenced this pull request Nov 18, 2026
* fix(middleware): 隐藏无可用渠道错误中的任务插件标识

* fix(middleware): keep task-plugin context in no-channel error without plugin keys

The fully generic message from QuantumNous#7414 left callers and operators unable to
tell whether a task plugin was involved at all. Restore the group, model and
plugin-claimed wording in the 503 body, but keep the plugin keys and the
admin fix hint out of it; the candidate plugin keys stay in the warn log
under the request id so operators can correlate.

---------
Co-authored-by: CaIon <i@caion.me>
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.

3 participants