From eae2063bef7f21d1cde2758bc5b160a9a2c1ad35 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 17 Sep 2026 18:22:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(llm):=20=E6=8E=A2=E6=B5=8B=E9=80=9A?= =?UTF-8?q?=E9=81=93=E5=88=A0=E6=8E=89=20proxy=5Fset=5Fbody=20=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=E4=BD=93=EF=BC=8C=E6=81=A2=E5=A4=8D=E3=80=8C=E6=8E=A2?= =?UTF-8?q?=E6=B5=8B=E4=BD=93=E5=8E=9F=E6=A0=B7=E8=BD=AC=E5=8F=91=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 面板「测试」报 minimax unknown model 'test' (2013) 的根因:1.0.43 为当时的 空 body 探测兜底,在 conf/nginx.conf 的 /_upstream_test/ 注入了 model=test 的 最小 dummy 体;而 nginx proxy_set_body 是无条件覆盖——把面板发来的「第一个 登记模型」探测体整个换掉,严格校验模型名的厂商一律误报「不通」(健康徽章因 4xx 算存活仍显示正常,二者口径不一致)。测试模板本就无此行,所以本机回归全绿 ——典型的 conf/模板漂移,本次连 gateway 模板里同款遗留一并清掉。 - conf/nginx.conf + tests/gateway/nginx.conf.in:删注入行,注释改写成「别加回来」的告诫 - tests/llm/e2e.sh【11】:动态闸(探测体原样到靶机)+ 静态闸(生产 conf 探测块禁 proxy_set_body) - CLAUDE.md 排障表补一行 llm 264 / gateway 108 全绿 --- CLAUDE.md | 1 + conf/nginx.conf | 12 ++++++------ tests/gateway/nginx.conf.in | 4 ++-- tests/llm/e2e.sh | 13 +++++++++++++ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 0c5dd24..8517117 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -295,6 +295,7 @@ location 与 80 端口 LLM server 是两份拷贝,改一处记得同步另一 | 404 但上游明明配了 | `enabled: false` 会被摘除;或手改了 json 没重启(热路径无回源兜底) | | 上游 404 且**响应体为空** | 上游 `base` 带 `/v1` 而客户端也带 `/v1` → 拼成 `/v1/v1/...`;查 `llm::join_target` 的去重分支 | | `/v1/models` 反而 404 | `is_models_probe` 的位置错了:**必须在解析 slot 之前**,否则被当成 `slot=v1` | +| 「测试」报 `unknown model 'test'`(如 minimax 2013),但健康徽章是正常 | 生产 conf 的 `/_upstream_test/` 曾注入 `proxy_set_body` 最小 dummy 体(1.0.43 空 body 兜底遗留),`proxy_set_body` 是**无条件覆盖**——面板发来的「第一个登记模型」探测体被整个换掉,严格校验模型名的厂商全部误报不通。已移除;e2e【11】静态闸钉住,**别把注入行加回任何一份 conf** | | 用量一直是 0 | 被拒的请求(401/403/404/429)**不计用量**;或 `stats::record` 被挪出了"鉴权全通过之后" | | 删了账号还在用量榜上 | 没调 `stats::forget`(清 `ust:` / `ums:` 前缀) | | **发版后用量/趋势全变 0** | 快照没落上:查 `data/llm-stats.json` 是否存在 / 可写(数据卷),看 error log 有无 `[stats]` 报错。⚠️ 注意**登录会话(`sess:`)与配额(`st:`)重启清零是设计如此**,别把这两样当成故障 | diff --git a/conf/nginx.conf b/conf/nginx.conf index f84698e..af40a09 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -440,12 +440,12 @@ http { proxy_set_header Authorization $llm_auth; proxy_set_header Content-Type $http_content_type; proxy_set_header Accept $http_accept; - # 探测通道是「空 body POST」,多数厂商在 model 字段缺失时 NPE - # (智谱 4.x SDK 典型表现:返 200 + body.error.code=500), - # 误报成「模型不存在」。注入一段 OpenAI/Anthropic 都能接受的最小 - # 探测体,让上游真做一次最小生成。msg 极短,max_tokens=1,费用 - # 与可观测性可控。 - proxy_set_body '{"model":"test","max_tokens":1,"messages":[{"role":"user","content":"hi"}]}'; + # ⚠️ 这里**不能**加 proxy_set_body:面板探测体本来就带「第一个登记 + # 模型 + max_tokens=1」(见 www/assets/upstreams.js 的 probe),而 + # nginx 的 proxy_set_body 是无条件覆盖。1.0.43 为当时的空 body 探测 + # 注入过最小 dummy 体(绕智谱 model=null NPE),结果把严格校验模型名 + # 的厂商(minimax:unknown model 'test' 2013)一律打成「不通」。 + # e2e【11】有静态闸钉住这条,别加回来。 proxy_ssl_server_name on; proxy_connect_timeout 5s; proxy_send_timeout 15s; diff --git a/tests/gateway/nginx.conf.in b/tests/gateway/nginx.conf.in index 2172726..3eaf2a6 100644 --- a/tests/gateway/nginx.conf.in +++ b/tests/gateway/nginx.conf.in @@ -112,8 +112,8 @@ http { proxy_set_header Authorization $llm_auth; proxy_set_header Content-Type $http_content_type; proxy_set_header Accept $http_accept; - # 与生产同款:注入最小 dummy 体避开「model=null → 智谱 NPE 返 500」误报 - proxy_set_body '{"model":"test","max_tokens":1,"messages":[{"role":"user","content":"hi"}]}'; + # 探测体由管理台原样发来(含登记模型),不注入任何覆盖体—— + # 见 conf/nginx.conf 同 location 的告诫注释与 llm e2e【11】静态闸。 proxy_connect_timeout 5s; proxy_send_timeout 15s; proxy_read_timeout 15s; diff --git a/tests/llm/e2e.sh b/tests/llm/e2e.sh index 8c87367..f968cfd 100755 --- a/tests/llm/e2e.sh +++ b/tests/llm/e2e.sh @@ -392,6 +392,8 @@ ck "★admin 测 openai → 透传上游 200" 200 \ "$(code -b "$JAR" -X POST "$API/api/admin/upstreams/test?slot=openai" -H 'Content-Type: application/json' -d "$PING")" ck " 靶机收到的 path 不含 slot 段" "/v1/chat/completions" "$(up_field path)" ck " 换上了 openai 上游的真 Key" "Bearer sk-UPSTREAM-REAL-SECRET" "$(up_field auth)" +ck " ★探测体原样到达靶机(model=ds-chat,未被网关注入体覆盖)" "yes" \ + "$(up_field body | grep -q 'ds-chat' && echo yes || echo no)" ck "★base 自带 /v1 的上游(deepseeklike)→ 去重后 200" 200 \ "$(code -b "$JAR" -X POST "$API/api/admin/upstreams/test?slot=deepseeklike" -H 'Content-Type: application/json' -d "$PING")" ck " 靶机 path 仍是 /v1/chat/completions(无 /v1/v1、无 slot 段)" "/v1/chat/completions" "$(up_field path)" @@ -402,6 +404,17 @@ ck "不存在的 slot → 404 信封" 404 \ "$(code -b "$JAR" -X POST "$API/api/admin/upstreams/test?slot=ghost" -d '{}')" ck "★内部 location 外部直连 → 404(不能绕过 admin 会话触达上游)" 404 \ "$(code -b "$JAR" -X POST "$API/_upstream_test/openai/v1/chat/completions" -d '{}')" +# —— 静态回归闸 —— +# 生产 conf 与测试模板是两份拷贝,历史事故(面板测 minimax 报 +# `unknown model 'test' (2013)`)正是二者漂移:1.0.43 为当时的「空 body 探测」 +# 兜底,在 conf/nginx.conf 的 /_upstream_test/ 注入了 proxy_set_body dummy 体, +# 而 nginx 的 proxy_set_body 是**无条件覆盖**——把面板发来的「第一个登记模型」 +# 探测体整个换掉,严格校验模型名的厂商全部误报「不通」,本夹具却因模板没这行 +# 而全绿。探测体必须原样转发,这道闸防注入行只在线上配置里复活。 +# 只看生效行:conf 注释里「别加 proxy_set_body」的告诫会字面命中 grep +UB_BLOCK=$(awk '/location \/_upstream_test\//{f=1} f{print} f&&/^ \}$/{exit}' "$HERE/../../conf/nginx.conf" | grep -v '^[[:space:]]*#') +ck "★生产 conf 探测块无 proxy_set_body(探测体原样转发)" "no" \ + "$(echo "$UB_BLOCK" | grep -q proxy_set_body && echo yes || echo no)" echo echo "【11.5】★ API 代理(/apix/ → 外部供应商)"