Commit Graph
6 Commits
Author SHA1 Message Date
yetoneandggbdpq 4ecf32c12c gateway: a LiteLLM "Budget has been exceeded" 429 is out of quota, so the key's quota-rest holds it (#5111)
A LiteLLM relay's spent key answers 429 "Budget has been exceeded!
Key=… Current cost: …, Max budget: …". usedUpWords knew only the
adjacent pair "budget exceeded", so the refusal fell through to a plain
rate limit: the key rested a minute, doubled up to half an hour, and was
asked again every half hour for a budget that doesn't come back, the
user's quota-rest never read. The pair is a window now,
budget.{0,32}(exceeded|exhausted). LiteLLM's own "Rate limit exceeded",
which names no budget, stays a rate limit.

Run (mote): go test -tags nogui -run 'TestOutOfBudgetIsntRetriedInPlace|
TestOwnQuotaRest' ./internal/gateway/ ok; the whole internal/gateway package ok (926s) on these changes over 4e7661adc, the targeted tests again at this head, rebased onto b712adb84;
vet and gofmt clean.
Broken by hand: the old pair put back, both new rows fail ("is a rate
failure", "is asked again in place").
Not tried: a real LiteLLM relay; the wording is LiteLLM's
BudgetExceededError text as the reporter quoted it.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-06 10:44:24 +08:00
yetoneandggbdpq 7d19be10ff gateway: "longer than the model context length" is an overflow, so Codex compacts (#4040)
easyrev's vendor refuses a turn past the model's window with a 400
whose message is "The message is longer than the model context length"
(code context_length_exceeded). tooLongRe knew Together's wording, with
"model's", only, so the refusal wasn't read as an overflow: Codex got
the 400 JSON whole, which it takes for an invalid request and shows raw,
instead of response.failed context_length_exceeded in its stream, which
it compacts on. The 's is optional now.

Not changed: a vendor whose only overflow signal is the code field, with
words tooLongRe doesn't know, still isn't read as one; the words passed
to tooLong are the vendor's message, not its code.

Run (mote): go test -tags nogui -run
'TestEveryVendorsOverflow|TestCodexByteCapBeforeStreamCompacts'
./internal/gateway/ ok; the whole internal/gateway package ok (926s) on these changes over 4e7661adc, the targeted tests again at this head, rebased onto b712adb84; go vet -tags nogui ./internal/gateway/ and
gofmt -l clean.
Broken by hand: gateway.go put back with the tests kept, both fail
("Codex wasn't told in its stream to compact: 400 application/json
…context_length_exceeded…" and "…isn't taken for a conversation too
long").
Not tried: a real Codex CLI against the reporter's vendor.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-06 10:44:24 +08:00
yetone cfcd6648fc gateway: Chinese that says the input is too long is an overflow, Chinese pace words a rate limit (#4420)
A group member answered 400 "内容太长了,请精简输入或开启新对话" once a
turn passed ~730K on a model it declares at 1M. tooLongRe's Chinese only
matched wordings that name 上下文, so the try was filed as a plain
failure that rested the member, and the group's other members were never
asked. Reported by MYCF711 (Discord, issue #4420).

tooLongRe gets a third line for Chinese that names what was sent (内容,
输入, 文本, 提示词/prompt, 问题, 对话, 消息) beside its length: "…太长/过长/
超长", "…超过/超出…长度/token/字数", "输入长度/token…超过", and
"字数太多/过多". Tied to: the reporter's vendor, z.ai's 1261 "Prompt 超长",
iFlytek Spark's 10907 "token数量超过上限。对话历史+问题的字数太多,需要精简
输入". Left out on purpose: bare "超出最大长度" (a field's length), bare
"token数量超过上限" (a day's allowance is said so too), "输出过长" (the
reply), and "请求体过大" (a 413 byte limit, already handled by status).

paceWords gets Chinese pace words (速率, 频繁, 频率, 限流, 并发, 每秒/
分钟/小时/天/日, 稍后再试/重试), so "内容太长,已达到速率限制" is a rate
limit, not a size. rateWords gains 过于频繁/速率 and quotaWords 频繁/速率,
so such a 400 is asked of the next account and such a 429 is failRate.

Tests:
- TestEveryVendorsOverflow: 8 Chinese rows (red on the old code, each).
- TestChineseNotTooLong (new): pace-with-size, a field's length, the
  reply's length, a day's token cap and plain errors aren't overflows; the
  pace 400 is retryable.
- TestChineseInputTooLongGoesToTheNextMember (new): two-member group, the
  reporter's literal words, raw and \u-escaped: member b answers, failOverflow,
  nobody rests (red on the old code: a 1, b 0, 400 to the agent).
- docs/subsystems/gateway-routing.md names the new wordings.

Run (mote, via mote-run, at this tree):
- go test ./internal/gateway -count=1 -timeout 45m: ok 500.9s
- go vet ./internal/gateway, GOOS=linux and GOOS=windows: clean; gofmt -l clean
- Broken by hand: old gateway.go/routing.go/fallback.go with the new
  tests: all three tests red (11 failures). paceWords alone reverted:
  TestChineseNotTooLong red on 4 pace messages and the retryable check.

Not tried: the reporter's real vendor (unknown which member it is), nor a
real z.ai or iFlytek account; the wordings come from their docs. Only
internal/gateway was run, not the whole repo; the change is inside that
package's classifiers.
2026-10-30 17:52:14 +08:00
SadWood b69d9089e6 fix(gateway):保留413跨成员回退并说明请求体限制 (#711)
将 request_too_large 与明确的上下文超限分别处理。成员返回普通或结构化 413 时尝试其他成员,跳过同成员的额外账号,不将该成员休眠。仅在最终向客户端返回 413 时加入减少图片、大型工具结果或带摘要开启新会话的建议。

保留 tooLongUnsaid 对文本估算超过已知窗口 1.2 倍的判断,以及已有的上下文溢出窗口过滤和压缩提示。

补充 Anthropic 与 Codex 两条协议路径、成功及耗尽回退、同成员账号跳过、高文本估算和迁移 Factory 插件的合成回归测试。
2026-10-04 10:01:47 +08:00
yetone 11a09d418c gateway: every vendor's "too long" reaches the agent as context_length_exceeded and fails over to nobody, and a spent budget isn't asked again in place (owner: 继续做第 4 项,错误分类接入 failover) — pi's two tables (packages/ai/src/utils/overflow.ts, retry.ts) against magpie's classifier: 15 of pi's 25 overflow texts weren't known, so the agent got the vendor's words and didn't compact, and four were worse: Kimi's "exceeded model token limit" rested the account as out of quota, and z.ai's model_context_window_exceeded, Ollama's "prompt too long; exceeded max context length" and "token limit exceeded" went to every other account in turn (quotaWords' "exceeded"). tooLongRe takes pi's patterns (request_too_large, Gemini, xAI, Groq, OpenRouter, Together, llama.cpp, LM Studio, Copilot, MiniMax, Kimi, DS4, z.ai, Ollama, DashScope), and overflowed (a 400/413/422 saying so) is neither retryable nor a quota or credit failure, so nobody rests and it is answered at once. "out of budget" / "budget exceeded|exhausted" are a used-up plan: a 429 was a rate limit asked three times in place, a 400 was answered without trying the next account. TestEveryVendorsOverflow and TestOutOfBudgetIsntRetriedInPlace fail on the old code (26 failures). Real accounts, sandbox magpie, a 2.2M-token request: Qoder's "invalid params, context window exceeds limit" came back from the old build as 413 api_error with no code (Claude Code and Codex wouldn't compact) and is now 400 context_length_exceeded / Anthropic "prompt is too long: …"; WorkBuddy, WorkBuddy AI, Kiro and Grok (SuperGrok) answer context_length_exceeded too, and ordinary requests through each still answer. go vet, GOOS=linux/windows builds and go test -tags nogui -count=1 ./... under a temp HOME pass. Silent overflow (usage past the window on a 200) isn't detected: the reply is already the agent's by then. 2026-10-03 14:55:37 +08:00
yetone 40812f1d2b gateway: a vendor saying the conversation is too long is said the client's way, so the agent compacts and retries — Volcengine's "Input exceeds the context limit (1048568 tokens)" reached Claude Code and Codex as a plain error they stop on; a 4xx that says the input is past the model's context (context_length_exceeded, maximum context length, prompt is too long, exceeds the context limit, 超过上下文…) now answers 400 with Anthropic's "prompt is too long: …" on /v1/messages and code context_length_exceeded on chat and Responses; one about max_tokens is left alone 2026-09-26 01:38:37 +08:00