gateway: a vendor that says the content is too long without naming the context — the try rests the account and the group is never asked
What happens
A group member answers 400 "内容太长了,请精简输入或开启新对话" once a turn passes ~730K on a model it declares at 1048576. tooLongRe has two Chinese wordings and both name the thing that overflowed (上下文…超 / 超…上下文), so this one goes past them: the try is filed as an error that rests the account, and the group's other twelve members are never asked. A long conversation fails once and keeps failing.
Why it is worth a fix
The word list grows one vendor at a time, and missing one word does not produce a visible error — it makes fallback silently not work. The routing log only shows fail=other, which reads as "the vendor broke", not "our classifier missed".
The other half, easy to miss
paceWords needs the Chinese pace wordings in the same change. Without them, "内容太长,已达到速率限制" is read as the size alone and the momentary cap rests the account — the worse of the two mistakes.
Shape of the change (in internal/gateway/gateway.go)
tooLongRe: add the wording that says the content is too long without naming the contextpaceWords: add the Chinese pace wordings- one more row in
TestEveryVendorsOverflow
Verified on a local branch (described here rather than offered as a PR, since this repo doesn't take them): gofmt -l clean, go vet ./internal/gateway/ clean, go test ./internal/gateway -count=1 -run 'Overflow|TooLong|Fallback|Retry|Pace|Rate|Cap|Member|Group' → ok 113.9s, including TestEveryVendorsOverflow.
Say the word and I will paste the diff in this issue — it is a few lines in the regexes plus the test row.
Taking your decision — signal from the frame, word list as the fallback — here is what the frame actually carries and where the two existing paths miss it.
The frame. 400 {"error":{"message":"内容太长了,请精简输入或开启新对话"}} — no code, no names the thing that overflowed, no quota/rate word. Request was ~730K on a model this plugin declares at 1048576, so it is not near the window — the vendor's own ceiling is lower than its declared window.
Why neither path catches it today
tooLongRehas two Chinese wordings, both naming the overflowed thing (上下文…超/超…上下文); this one names nothing, sooverflowed()is false.tooLongUnsaidis the right shape — a 400 with no quota/refusal words, judged bytokens >= windowOf(p, model) * 1.2. Here 730K < 1048576 × 1.2, so the margin never trips. This vendor's real ceiling being ~0.7 of its declared window is the whole bug: the margin assumes the declared window is what the upstream enforces.
Proposal (two changes, both small)
A. Signal from the frame — narrow the unsaid judgment when the vendor's words are length words but silent on the subject. Something like:
// lengthWords: 太长 / 过长 / 精简 / 缩短 / 开启新对话 / too long / too large / reduce / shorten
// on a 400 with no quota, rate, credit, refusal, region or model word,
// and a request past half the window, treat it as too long.
lengthUnsaid := lengthWords.Match(body) && burstWords.Match(body) == false
if lengthUnsaid && float64(tokens) >= float64(window)*0.5 {
// same message tooLongUnsaid builds
}
The 0.5 floor is what this data says: the two live cases I have are 730K/1M and "内容太长了" on a 1M-declared model, both past half the window and both refused.
B. Word list as fallback — add 内容太长, 太长,请精简, 精简输入, 开启新对话 to tooLongRe, and the same to paceWords (or "内容太长,已达到速率限制" keeps reading as size alone, and a momentary cap rests the account — the worse of the two misses).
Evidence from this machine. Two of the three cases in the issue came from a group whose other 12 members were never asked: the try was filed fail=other and the account rested, while the group had members with a larger declared window. If you want the raw usage rows (provider, model, tokens, err) pasted here, say so.
I cannot send a PR (CreatePullRequest is refused for non-collaborators), so this is the patch in prose — take it, or tell me where to put it and I will write the diff against a file list you name.
Landed in a1f1810e9, released in v0.1.2956. This is fix A from your comment: a 400 or 422 whose words are about length and that names no part of the request now counts as an overflow once the request is past half the model's declared window. The words are 太长, 过长, 超长, 精简, 开启新对话, too long/large, shorten and the like; a request "names no part" when the message isn't about a picture, a file, the reply, a field or max_tokens, and has no pace, quota or refusal words. When that happens, the next group member with room is asked and nobody is rested. With no member left, the agent is told the prompt is too long, so it compacts. Fix B, the word list, had already landed in cfcd6648f.
Not tried: the real vendor's 400 at ~730K. The test (TestLengthWordsPastHalfTheWindowGoToTheNextMember) uses wordings that aren't in the list, so it covers the next vendor that says it differently.
Leaving this open until you see it work on your group.
Tried to reproduce it on 0.1.2971, and this machine's providers will not refuse a request that size — so I have no live sample to confirm fix A with.
What I did, against group/deepseek-v4.1-flash1017 (wps-lingxi, 1,000,000 declared):
| payload | prompt_tokens | result |
|---|---|---|
| 2.4 MB of Chinese | 400,030 | 200, finish_reason: length, 16 completion tokens |
| 3.6 MB of Chinese | 600,030 | 200, same |
Both went through. 600K is past lengthMargin (0.5 × 1M) and past unsaidMargin (1.2 × 1M would need 1.2M), but the path only fires when the vendor refuses — and this one serves it. The 730K refusal in the report was a different plugin on a different model whose own ceiling sat below its declared window.
So: code path confirmed by reading, runtime not exercised. saysLength + lengthMargin = 0.5 are exactly the shape I proposed (length words, partWords excluded, pace words excluded, 400/422 only), and overflow_cap_test.go covers the wordings that are not in tooLongRe — which is the case that matters, since the next vendor will say it differently again.
Not closing: I would rather leave it open until a real vendor refusal lands in this group's log, then post the row. If you would rather close it on the test alone, say so and I will.
Closing per your call — the code path is confirmed and the test covers wordings that are not in the list; the live sample did not appear because this machine's providers serve a 600K request instead of refusing it. If a real length refusal lands in the group's log later, I will open a new report with the row.