diff --git a/rust/crates/plugin-llm/src/handlers.rs b/rust/crates/plugin-llm/src/handlers.rs index 63259a7..b47450b 100644 --- a/rust/crates/plugin-llm/src/handlers.rs +++ b/rust/crates/plugin-llm/src/handlers.rs @@ -247,10 +247,17 @@ impl HttpRequestHandler for LlmHealthHandler { // (best-effort 撞墙)→ 时间线不动; // * 2xx 且无耗尽信号 → clear_cool:冷却中的账号被探测/转发验证恢复, // 立即清键回队(健康账号无键,remove 返回 false、静默)。 + // + // is_probe(管理台「测试」按钮的内跳)**不写冷却/耗尽**—— + // 测试账号由 pick 随机选,上游回耗尽形态只说明「这个请求过不了」, + // 不能据此认定账号已耗尽。线上事故:13:50 三把好 key 被面板测试轮 + // 点进冷却,整池不可用,恢复要走完整退避。mark_health 与 + // bump_acct_load 照常(测试也是真转发,有统计意义); + // 2xx clear_cool 也保留——测试成功 = 该账号此刻健康(正向证据)。 let (status_list, _) = upstreams::read_upe(&slot); let status_exhausted = status_list.iter().any(|&s| s == code); let body_exhausted = usage_filter::take_exhausted(r); - if status_exhausted || body_exhausted { + if !is_probe && (status_exhausted || body_exhausted) { upstreams::mark_exhausted(&slot, idx, now); upstreams::bump_acct_exhaust(&slot, idx, now); } else if (200..300).contains(&code) { diff --git a/tests/llm/e2e.sh b/tests/llm/e2e.sh index f968cfd..6d8f3ba 100755 --- a/tests/llm/e2e.sh +++ b/tests/llm/e2e.sh @@ -852,6 +852,24 @@ ck "★probe 投影:#1 仍在冷却(退避持续)" true "$(acct_view "$UPS ck "probe #0 至少记 1 次耗尽" yes "$([ "$(acct_view "$UPS2" probe 0 load.exhausts)" -ge 1 ] && echo yes || echo no)" ck "probe #1 至少记 3 次耗尽(标记+两轮探测)" yes "$([ "$(acct_view "$UPS2" probe 1 load.exhausts)" -ge 3 ] && echo yes || echo no)" +# ---- 管理台「测试」按钮不得写路由状态(线上事故回归)---- +# 事故复现:面板测试走 /_upstream_test,账号由 pick 随机选;上游一旦回 401+marker, +# 旧逻辑会把"管理员手抖点了一下测试"当成"这个账号额度耗尽",冷却一张好钥匙, +# 恢复要走完一轮退避/探测。fixture `probetest`:单账号 Bearer probe-dead +# (上游靶机识别后永远回 401+`status_code:1004` 标记),exhaust_status=[401] 让 +# status 通道也命中——彻底钉死「测试按钮不写冷却」这条。 +TB=$(code -b "$JAR" -X POST "$API/api/admin/upstreams/test?slot=probetest" -H 'Content-Type: application/json' -d "$PING") +ck "probetest admin test → 上游真实 401 透传" 401 "$TB" +UPS_PT=$(curl -s -b "$JAR" $API/api/admin/upstreams) +ck "★admin test 后账号未进冷却(冷却不被测试按钮污染)" false "$(acct_view "$UPS_PT" probetest 0 cooled)" +ck "★admin test 不记录耗尽计数" 0 "$(acct_view "$UPS_PT" probetest 0 load.exhausts)" +# 真实流量同形态 → 标记通道必须照常工作(不能为避 bug 把真标记也关掉) +PT1=$(mh probetest probetest-model) +ck "probetest 真实流量 → 401(标记通道触发)" 401 "$(echo "$PT1" | awk '/^HTTP/{print $2}')" +UPS_PT2=$(curl -s -b "$JAR" $API/api/admin/upstreams) +ck "★真实流量 401+marker → 进冷却(标记通道保留)" true "$(acct_view "$UPS_PT2" probetest 0 cooled)" +ck "★真实流量耗尽计数 ≥1" yes "$([ "$(acct_view "$UPS_PT2" probetest 0 load.exhausts)" -ge 1 ] && echo yes || echo no)" + # ---- auth 规范化(normalize_auth)---- # fixture `normalize` 账号 auth 写成裸 key(`sk-NORM-NO-SCHEME`,无 `Bearer `), # 期望:转发时网关自动补 `Bearer `,靶机实收完整头值(不会因缺 scheme 触发 1004)。 diff --git a/tests/llm/fixtures/llm-upstreams.json b/tests/llm/fixtures/llm-upstreams.json index 45d8af7..f22e752 100644 --- a/tests/llm/fixtures/llm-upstreams.json +++ b/tests/llm/fixtures/llm-upstreams.json @@ -87,5 +87,17 @@ "enabled": true, "note": "双协议地址验证:OpenAI 路径 /api/coding/paas/v4 与 Anthropic /api/anthropic 完全不同,各走各的(智谱真实形态)", "created_at": 1757500000 + }, + "probetest": { + "base": "http://127.0.0.1:18999", + "models": ["probetest-model"], + "enabled": true, + "accounts": [ + {"auth": "Bearer probe-dead", "note": "永远耗尽(管理测试隔离剧本用)", "resets": []} + ], + "exhaust_status": [401], + "exhaust_markers": ["\"status_code\":1004"], + "note": "管理台「测试」按钮不得写冷却/耗尽状态(真实事故回归);同形态真实流量进来仍照常标记", + "created_at": 1757500000 } }