Commit Graph
1 Commits
Author SHA1 Message Date
yetone b749cffbb1 gateway: a reply asked past what the window leaves is asked again for what it leaves, not failed as too long (molvqingtai, da34, Jeremy.Zhou on Discord)
DeepSeek counts the reply asked for (max_tokens) in its 1M window with
the prompt: "maximum context length is 1000000 tokens. However, you
requested N tokens (P in the messages, C in the completion)". Since
62020b9c2 (#2355) a client's max_completion_tokens reaches DeepSeek as
max_tokens, so a turn asking the model's whole 384K on a ~620K+
conversation was refused there and read as "too long for its model"
(molvqingtai: auto-deepseek-v4.1-flash, round robin, the official
member failing where WorkBuddy and OpenCode Go answered). Codex turns
are asked the model's own 393216 on Anthropic's API (#1792), and since
1a3b92688 (v0.1.1290) Claude Code beside a [1m] DeepSeek is told 1M
and compacts only near it, so both met the same refusal before they
compacted (da34: Codex "ran out of room"; Jeremy.Zhou: Claude Code).

replyLeft (maxoutput.go) reads the window and the prompt from that
refusal, in DeepSeek's/vLLM's words or Anthropic's ("input length and
`max_tokens` exceed context limit: P + C > W"), and the same account and
model are asked once more for W-P (withReplyCap: the request's own field
lowered, or max_tokens / max_output_tokens set where it named none).
Room under 8192 is left alone: the agent is told it overflowed, to
compact. The try is "room" in the Routing page ("reply asked past the
window left", zh/zh-TW/ja/de). DeepSeek's documented window stays 1M
(api-docs pricing: deepseek-flash 1M, max output 384K), as models.dev
and the catalog say, so no number changes.

Run:
- TestDeepSeekReplyFitsTheWindowLeft: deepseek preset on a fake chat
  API that refuses in DeepSeek's words when prompt+max_tokens > 1M;
  max_completion_tokens 393216, max_tokens 393216 and a Responses
  client each arrive as 393216 then 293216 and answer 200; 32000 is
  asked once; room under 8192 reaches the agent as the 400, asked once.
- TestAnthropicReplyFitsTheWindowLeft: Anthropic's wording; Claude
  Code's max_tokens 64000 -> 30000, Codex naming none -> 393216 -> 30000.
- TestReplyLeft: both wordings, vLLM's newer one, and errors with no
  room or no parts give 0.
- Broken by hand: the retry's condition off -> both tests FAIL with the
  vendor's 400; the cap not applied on the retry -> FAIL the same.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... clean.
- go test -timeout 45m ./... at 33dbdcc52 + this change: 64 packages ok,
  0 FAIL (load average 130-160). An earlier run before the Anthropic
  wording was added timed out in internal/agent (TestPortMovesEveryAgent
  at the 45m mark, load ~110), which this change doesn't touch; the
  second run passed it.
- GUI: i18n-keys, routing-*, panel-routing* in both engines and every
  language. Red here and on origin/main ab7ec8c65 alike: routing-bodies
  (#2559), routing-model-rest (#2115), routing-request-metrics WebKit
  (#2571), routing-keys-fold WebKit ja/de once (#2658).
- Not tried against the real DeepSeek API: the refusal's wording is
  DeepSeek's documented OpenAI-compatible one, not captured from the
  reporters.
2026-10-19 19:05:30 +08:00