Repository navigation
fix(provider): 5xx 视为容量拒绝——快速切换成员并冷却死通道 - #392
Merged
Merged
Conversation
…s fast
Root cause measured against token.zlshag.xyz (the relay in the report),
not inferred:
* Every payload shape (plain / +system / +tools / +tools+system+
stream_options) gets the SAME instant 503
{"error":{"message":"Service temporarily unavailable","type":"api_error"}}
in <1s, so the status is a channel verdict, not a request complaint.
* glm-5.3 answered 3/3 while deepseek-v4-pro and deepseek-v4.1-flash
answered 1/3 each on the same key — channels fail independently.
* Sequential 12/12 succeeded; parallel bursts returned 429/502/503
instantly, so the relay also admits ~1 concurrent per channel.
* A 448KB / 147k-token prompt returned 200 CLEAN, so neither body size
nor context length triggers it.
The app made that relay behaviour expensive: a 5xx maps to TransientError
(mapHttpErrorShared's TRANSIENT_HTTP_STATUSES), isRetryable was true but
isFallbackable was false, so the loop burned 5 same-provider retries
(1/2/4/8/16s ≈ 31s) and then failed the turn even when the group had a
healthy member, and the dead entry was never parked — the next turn
re-picked it. That is the "Transient error: [503] ... 老是断开" loop.
- LLMError gains `httpStatus` (one parser for the bracketed status the
mappers stamp into `detail`) and `isCapacityRejection`; `isFallbackable`
now routes TransientError 5xx and ProviderError 5xx/429 through them.
Watchdog stalls carry no status token and keep their resume semantics.
- Agent loop: a capacity 5xx with another group member gets the same
one-attempt budget 429 already had, so the turn switches instead of
hammering a dead channel for 31s.
- Agent loop: capacity 5xx parks the member (markRoutingCooldownFor,
30s default, Retry-After wins), so the next turn routes around it.
- ChatViewModel.HTTP_5XX_STATUS_RE removed — duplicate of the new parser.
- Tests pin status parsing, capacity classification, fallback, and the
"stall is not a capacity rejection" boundary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
根因(实测,非推断)
针对报告里的中转站
token.zlshag.xyz做了 4 组对照实验:结论:503 来自中转站自身的通道准入/上游冷却(
{"error":{"message":"Service temporarily unavailable","type":"api_error"}},0.4–1.2s 内返回,无上游尝试),不是 app 的请求或网络。glm 通道当时健康、deepseek 通道整段不可用。app 侧为什么会放大成「老是断开」
mapHttpErrorShared把 5xx 归为TransientError(TRANSIENT_HTTP_STATUSES),但isFallbackable只认ProviderError的[5xx]→ 503 永不触发组内回退。ChatViewModel.HTTP_5XX_STATUS_RE与LLMError各有一份状态码正则,判定逻辑三处各写一遍。修复
LLMError新增httpStatus(统一解析[NNN]令牌,TransientError / ProviderError / RateLimited 共用)与isCapacityRejection;isFallbackable改为经它判定,5xx 的TransientError也能回退。看门狗 stall 不带状态码,resume 语义([T-stall-resume])不受影响。markRoutingCooldownFor(默认 30s,有Retry-After则以其为准),下一轮路由绕开死通道。ChatViewModel.HTTP_5XX_STATUS_RE,只留单一解析入口。测试
LLMErrorClassificationTest新增:状态码解析(Transient/Provider/RateLimited/无码)、5xx→可回退、429 与看门狗 stall 的边界、ProviderError 5xx 行为保持。本地沙箱无 Android 工具链,编译与单测交由 CI。